Skip to content

Dialogs

Wails provides a comprehensive dialog system for displaying native system dialogs. These include informational messages, questions, file selection, and more.

Dialog Types

Information Dialog

Display simple informational messages to users:

dialog := application.InfoDialog()
dialog.SetTitle("Welcome")
dialog.SetMessage("Welcome to our application!")
dialog.Show()

Question Dialog

Present users with questions and customisable buttons:

dialog := application.QuestionDialog()
dialog.SetTitle("Save Changes")
dialog.SetMessage("Do you want to save your changes?")
dialog.AddButton("Save").OnClick(func() {
// Handle save
})
saveButton := dialog.AddButton("Don't Save")
dialog.SetDefaultButton(saveButton)
dialog.Show()

Error Dialog

Display error messages:

dialog := application.ErrorDialog()
dialog.SetTitle("Error")
dialog.SetMessage("Failed to save file")
dialog.Show()

File Dialogs

Open File Dialog

Allow users to select files to open:

dialog := application.OpenFileDialog()
dialog.SetTitle("Select Image")
dialog.SetFilters([]*application.FileFilter{
{
DisplayName: "Images (*.png;*.jpg)",
Pattern: "*.png;*.jpg",
},
})
// Single file selection
if path, err := dialog.PromptForSingleSelection(); err == nil {
// Use selected file path
}
// Multiple file selection
if paths, err := dialog.PromptForMultipleSelection(); err == nil {
// Use selected file paths
}

Save File Dialog

Allow users to choose where to save files:

dialog := application.SaveFileDialog()
dialog.SetTitle("Save Document")
dialog.SetDefaultFilename("document.txt")
dialog.SetFilters([]*application.FileFilter{
{
DisplayName: "Text Files (*.txt)",
Pattern: "*.txt",
},
})
if path, err := dialog.PromptForSingleSelection(); err == nil {
// Save file to selected path
}

Dialog Customisation

Setting Icons

Dialogs can use custom icons from the built-in icon set:

dialog := application.InfoDialog()
dialog.SetIcon(icons.ApplicationDarkMode256)

Window Attachment

Dialogs can be attached to specific windows:

dialog := application.QuestionDialog()
dialog.AttachToWindow(app.CurrentWindow())
dialog.Show()

Button Customisation

Create buttons with custom labels and actions:

dialog := application.QuestionDialog()
dialog.SetMessage("Choose an action")
// Add buttons with custom handlers
dialog.AddButton("Save").OnClick(func() {
// Handle save
})
dialog.AddButton("Don't Save").OnClick(func() {
// Handle don't save
})
cancelButton := dialog.AddButton("Cancel")
dialog.SetDefaultButton(cancelButton) // Set default button

Platform Considerations

On macOS, dialogs follow system conventions:

  • Use system-standard dialog appearances
  • Support keyboard navigation (Tab, Space, Return)
  • Support standard keyboard shortcuts (⌘+.)
  • Automatically handle dark/light mode
  • Support system accessibility features
  • Position relative to parent window

Directory Selection

Allow users to select directories:

dialog := application.DirectoryDialog()
dialog.SetTitle("Select Project Directory")
if path, err := dialog.PromptForSingleSelection(); err == nil {
// Use selected directory path
}

About Dialog

Display application information:

app.ShowAboutDialog()

Best Practices

  1. Use appropriate dialog types for different scenarios:

    • InfoDialog for general messages
    • QuestionDialog for user decisions
    • ErrorDialog for error messages
    • FileDialog for file operations
  2. Provide clear and concise messages:

    • Use descriptive titles
    • Keep messages brief but informative
    • Clearly state any required user action
  3. Handle dialog responses appropriately:

    • Check for errors in file dialogs
    • Provide feedback for user actions
    • Handle cancellation gracefully
  4. Consider platform conventions:

    • Follow platform-specific dialog patterns
    • Use appropriate button ordering
    • Respect system settings