dialog.go 664 B

1234567891011121314151617181920212223242526272829303132333435
  1. package handlers
  2. import (
  3. "context"
  4. "github.com/wailsapp/wails/v2/pkg/runtime"
  5. )
  6. type DialogHandler struct {
  7. ctx context.Context
  8. }
  9. func NewDialogHandler(ctx context.Context) *DialogHandler {
  10. return &DialogHandler{ctx: ctx}
  11. }
  12. // SelectDirectory 目录选择方法
  13. func (dh *DialogHandler) SelectDirectory() (string, error) {
  14. options := runtime.OpenDialogOptions{
  15. Title: "选择目录",
  16. Filters: []runtime.FileFilter{},
  17. DefaultDirectory: "",
  18. DefaultFilename: "",
  19. }
  20. result, err := runtime.OpenDirectoryDialog(dh.ctx, options)
  21. if err != nil {
  22. return "", err
  23. }
  24. if result == "" {
  25. return "", nil
  26. }
  27. return result, nil
  28. }