Skip to main content
Version: v2.8.1

Dialog

This part of the runtime provides access to native dialogs, such as File Selectors and Message boxes.

JavaScript

Dialog is currently unsupported in the JS runtime.

OpenDirectoryDialogโ€‹

Opens a dialog that prompts the user to select a directory. Can be customised using OpenDialogOptions.

Go: OpenDirectoryDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error)

Returns: Selected directory (blank if the user cancelled) or an error

OpenFileDialogโ€‹

Opens a dialog that prompts the user to select a file. Can be customised using OpenDialogOptions.

Go: OpenFileDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error)

Returns: Selected file (blank if the user cancelled) or an error

OpenMultipleFilesDialogโ€‹

Opens a dialog that prompts the user to select multiple files. Can be customised using OpenDialogOptions.

Go: OpenMultipleFilesDialog(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error)

Returns: Selected files (nil if the user cancelled) or an error

SaveFileDialogโ€‹

Opens a dialog that prompts the user to select a filename for the purposes of saving. Can be customised using SaveDialogOptions.

Go: SaveFileDialog(ctx context.Context, dialogOptions SaveDialogOptions) (string, error)

Returns: The selected file (blank if the user cancelled) or an error

MessageDialogโ€‹

Displays a message using a message dialog. Can be customised using MessageDialogOptions.

Go: MessageDialog(ctx context.Context, dialogOptions MessageDialogOptions) (string, error)

Returns: The text of the selected button or an error

Optionsโ€‹

OpenDialogOptionsโ€‹

type OpenDialogOptions struct {
DefaultDirectory string
DefaultFilename string
Title string
Filters []FileFilter
ShowHiddenFiles bool
CanCreateDirectories bool
ResolvesAliases bool
TreatPackagesAsDirectories bool
}
FieldDescriptionWinMacLin
DefaultDirectoryThe directory the dialog will show when openedโœ…โœ…โœ…
DefaultFilenameThe default filenameโœ…โœ…โœ…
TitleTitle for the dialogโœ…โœ…โœ…
FiltersA list of file filtersโœ…โœ…โœ…
ShowHiddenFilesShow files hidden by the systemโœ…โœ…
CanCreateDirectoriesAllow user to create directoriesโœ…
ResolvesAliasesIf true, returns the file not the aliasโœ…
TreatPackagesAsDirectoriesAllow navigating into packagesโœ…

SaveDialogOptionsโ€‹

type SaveDialogOptions struct {
DefaultDirectory string
DefaultFilename string
Title string
Filters []FileFilter
ShowHiddenFiles bool
CanCreateDirectories bool
TreatPackagesAsDirectories bool
}
FieldDescriptionWinMacLin
DefaultDirectoryThe directory the dialog will show when openedโœ…โœ…โœ…
DefaultFilenameThe default filenameโœ…โœ…โœ…
TitleTitle for the dialogโœ…โœ…โœ…
FiltersA list of file filtersโœ…โœ…โœ…
ShowHiddenFilesShow files hidden by the systemโœ…โœ…
CanCreateDirectoriesAllow user to create directoriesโœ…
TreatPackagesAsDirectoriesAllow navigating into packagesโœ…

MessageDialogOptionsโ€‹

type MessageDialogOptions struct {
Type DialogType
Title string
Message string
Buttons []string
DefaultButton string
CancelButton string
}
FieldDescriptionWinMacLin
TypeThe type of message dialog, eg question, info...โœ…โœ…โœ…
TitleTitle for the dialogโœ…โœ…โœ…
MessageThe message to show the userโœ…โœ…โœ…
ButtonsA list of button titlesโœ…
DefaultButtonThe button with this text should be treated as default. Bound to return.โœ…*โœ…
CancelButtonThe button with this text should be treated as cancel. Bound to escapeโœ…

Windowsโ€‹

Windows has standard dialog types in which the buttons are not customisable. The value returned will be one of: "Ok", "Cancel", "Abort", "Retry", "Ignore", "Yes", "No", "Try Again" or "Continue".

For Question dialogs, the default button is "Yes" and the cancel button is "No". This can be changed by setting the DefaultButton value to "No".

Example:

    result, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: "Question",
Message: "Do you want to continue?",
DefaultButton: "No",
})

Linuxโ€‹

Linux has standard dialog types in which the buttons are not customisable. The value returned will be one of: "Ok", "Cancel", "Yes", "No"

Macโ€‹

A message dialog on Mac may specify up to 4 buttons. If no DefaultButton or CancelButton is given, the first button is considered default and is bound to the return key.

For the following code:

selection, err := runtime.MessageDialog(b.ctx, runtime.MessageDialogOptions{
Title: "It's your turn!",
Message: "Select a number",
Buttons: []string{"one", "two", "three", "four"},
})

the first button is shown as default:


And if we specify DefaultButton to be "two":

selection, err := runtime.MessageDialog(b.ctx, runtime.MessageDialogOptions{
Title: "It's your turn!",
Message: "Select a number",
Buttons: []string{"one", "two", "three", "four"},
DefaultButton: "two",
})

the second button is shown as default. When return is pressed, the value "two" is returned.


If we now specify CancelButton to be "three":

selection, err := runtime.MessageDialog(b.ctx, runtime.MessageDialogOptions{
Title: "It's your turn!",
Message: "Select a number",
Buttons: []string{"one", "two", "three", "four"},
DefaultButton: "two",
CancelButton: "three",
})

the button with "three" is shown at the bottom of the dialog. When escape is pressed, the value "three" is returned:




DialogTypeโ€‹

const (
InfoDialog DialogType = "info"
WarningDialog DialogType = "warning"
ErrorDialog DialogType = "error"
QuestionDialog DialogType = "question"
)

FileFilterโ€‹

type FileFilter struct {
DisplayName string // Filter information EG: "Image Files (*.jpg, *.png)"
Pattern string // semi-colon separated list of extensions, EG: "*.jpg;*.png"
}

Windowsโ€‹

Windows allows you to use multiple file filters in dialog boxes. Each FileFilter will show up as a separate entry in the dialog:




Linuxโ€‹

Linux allows you to use multiple file filters in dialog boxes. Each FileFilter will show up as a separate entry in the dialog:




Macโ€‹

Mac dialogs only have the concept of a single set of patterns to filter files. If multiple FileFilters are provided, Wails will use all the Patterns defined.

Example:

    selection, err := runtime.OpenFileDialog(b.ctx, runtime.OpenDialogOptions{
Title: "Select File",
Filters: []runtime.FileFilter{
{
DisplayName: "Images (*.png;*.jpg)",
Pattern: "*.png;*.jpg",
}, {
DisplayName: "Videos (*.mov;*.mp4)",
Pattern: "*.mov;*.mp4",
},
},
})

This will result in the Open File dialog using *.png,*.jpg,*.mov,*.mp4 as a filter.