1
0

dialogs.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package main
  2. import (
  3. "github.com/wailsapp/wails/v3/pkg/application"
  4. )
  5. // dialogs implements app.Dialogs with Wails' native file dialogs.
  6. type dialogs struct {
  7. a *application.App
  8. }
  9. // cancelled maps a dialog the user closed to "", nil. On Windows Wails
  10. // returns an error with this text instead of an empty path.
  11. func cancelled(path string, err error) (string, error) {
  12. if err != nil && err.Error() == "cancelled by user" {
  13. return "", nil
  14. }
  15. return path, err
  16. }
  17. func (d *dialogs) OpenWAV() (string, error) {
  18. return cancelled(d.a.Dialog.OpenFile().
  19. SetTitle("Choose a WAV file").
  20. CanChooseFiles(true).
  21. AddFilter("WAV files", "*.wav").
  22. PromptForSingleSelection())
  23. }
  24. func (d *dialogs) ChooseFolder() (string, error) {
  25. return cancelled(d.a.Dialog.OpenFile().
  26. SetTitle("Export to folder").
  27. CanChooseFiles(false).
  28. CanChooseDirectories(true).
  29. CanCreateDirectories(true).
  30. PromptForSingleSelection())
  31. }
  32. func (d *dialogs) SaveZip(defaultName string) (string, error) {
  33. return cancelled(d.a.Dialog.SaveFile().
  34. SetFilename(defaultName).
  35. AddFilter("Zip files", "*.zip").
  36. PromptForSingleSelection())
  37. }