SaveAsDialog

From Xojo Documentation

Class (inherits from FolderItemDialog)

Used to create customized Save As dialogs. Non-customizable Save As dialogs are created by the GetSaveFolderItem function.

Properties
ActionButtonCaption Left Title
CancelButtonCaption PromptText Top
Filter Result fa-lock-32.png
InitialFolder SuggestedFileName


Methods
ShowModal ShowModalWithin

Notes

Using the properties of the FolderItemDialog class, you can customize the following aspects of a save-file dialog box:

  • Position (Left and Top properties)
  • Default directory (Initial Directory property)
  • Valid file types to show (Filter property).
  • If you specify more than one file type (separate the file type names with semicolons), SaveAsDialog will add a Format pop-up menu to the dialog, allowing the user to specify the desired file type to use. Examine the extension of the file name returned to see which format was chosen.
  • Default filename (SuggestedFileName property)
  • Text of the Validate and Cancel buttons (ActionButtonCaption and CancelButtonCaption properties)
  • Text that appears in the Title bar of the dialog (Title property)
  • Text that appears in the body of the dialog (PromptText property)

On macOS, a Hide Filename Extension checkbox appears in the save-file dialog. The FolderItem returned has its ExtensionVisible property set according to the user's use of this checkbox.

Sample Code

The following code opens a customized save-file dialog box and displays the contents of the "Documents" directory in the browser area. It refers to the 'text/plain' common file type defined in the FileTypes1 file type set.

Var dlg As New SaveAsDialog
Var f As FolderItem
dlg.InitialDirectory = SpecialFolder.Documents
dlg.PromptText = "Prompt Text"
dlg.SuggestedFileName = "Suggested Filename"
dlg.Title = "Title Property"
dlg.Filter = FileTypes1.Text // defined as a file type in FileTypes1 file type set
f = dlg.ShowModal
If f <> Nil Then
// file saved
Else
// user canceled
End If

The following code creates a pop-up menu in the Save As dialog that gives the user the option of choosing among four file types.

Var dlg As New SaveAsDialog
Var f As FolderItem

Var txtType As New FileType
txtType.Name = "Text File (*.txt)"
txtType.Extensions = "txt"

Var htmlType As New FileType
htmlType.Name = "HTML File (*.htm, *.html)"
htmlType.Extensions = "htm"

Var csvType As New FileType
csvType.Name = "CSV File (*.csv)"
csvType.Extensions = "csv"

Var xlsType As New FileType
xlsType.Name = "Excel File (*.xls)"
xlsType.Extensions = "xls"

dlg.InitialDirectory = SpecialFolder.Desktop
dlg.promptText = "Prompt Text"
dlg.SuggestedFileName = "Suggested Filename"
dlg.Title = "Title Property"
dlg.Filter = txtType + htmlType + csvType + xlsType
f = dlg.ShowModal
If f <> Nil Then
If Right(f.Name, 3) = "txt" Then
MessageBox("1")
ElseIf Right(f.Name, 3) = "htm" Then
MessageBox("2")
ElseIf Right(f.Name, 3) = "csv" Then
MessageBox("3")
ElseIf Right(f.Name, 3) = "xls" Then
MessageBox("4")
End If
Else
// user canceled
End If

See Also

FileType, FolderItem, FolderItemDialog, OpenDialog, SelectFolderDialog classes