| 1234567891011121314151617181920212223242526272829303132333435 |
- package handlers
- import (
- "context"
- "github.com/wailsapp/wails/v2/pkg/runtime"
- )
- type DialogHandler struct {
- ctx context.Context
- }
- func NewDialogHandler(ctx context.Context) *DialogHandler {
- return &DialogHandler{ctx: ctx}
- }
- // SelectDirectory 目录选择方法
- func (dh *DialogHandler) SelectDirectory() (string, error) {
- options := runtime.OpenDialogOptions{
- Title: "选择目录",
- Filters: []runtime.FileFilter{},
- DefaultDirectory: "",
- DefaultFilename: "",
- }
- result, err := runtime.OpenDirectoryDialog(dh.ctx, options)
- if err != nil {
- return "", err
- }
- if result == "" {
- return "", nil
- }
- return result, nil
- }
|