mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Fix for bad default directories in dialog options. Fixes #1052
This commit is contained in:
parent
0f09e8d433
commit
c16bb9715f
1 changed files with 22 additions and 0 deletions
|
|
@ -2,7 +2,9 @@ package runtime
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/wailsapp/wails/v2/internal/frontend"
|
||||
"github.com/wailsapp/wails/v2/internal/fs"
|
||||
)
|
||||
|
||||
// FileFilter defines a filter for dialog boxes
|
||||
|
|
@ -29,24 +31,44 @@ type MessageDialogOptions = frontend.MessageDialogOptions
|
|||
// OpenDirectoryDialog prompts the user to select a directory
|
||||
func OpenDirectoryDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
||||
appFrontend := getFrontend(ctx)
|
||||
if dialogOptions.DefaultDirectory != "" {
|
||||
if !fs.DirExists(dialogOptions.DefaultDirectory) {
|
||||
return "", fmt.Errorf("default directory '%s' does not exist", dialogOptions.DefaultDirectory)
|
||||
}
|
||||
}
|
||||
return appFrontend.OpenDirectoryDialog(dialogOptions)
|
||||
}
|
||||
|
||||
// OpenFileDialog prompts the user to select a file
|
||||
func OpenFileDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
||||
appFrontend := getFrontend(ctx)
|
||||
if dialogOptions.DefaultDirectory != "" {
|
||||
if !fs.DirExists(dialogOptions.DefaultDirectory) {
|
||||
return "", fmt.Errorf("default directory '%s' does not exist", dialogOptions.DefaultDirectory)
|
||||
}
|
||||
}
|
||||
return appFrontend.OpenFileDialog(dialogOptions)
|
||||
}
|
||||
|
||||
// OpenMultipleFilesDialog prompts the user to select a file
|
||||
func OpenMultipleFilesDialog(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error) {
|
||||
appFrontend := getFrontend(ctx)
|
||||
if dialogOptions.DefaultDirectory != "" {
|
||||
if !fs.DirExists(dialogOptions.DefaultDirectory) {
|
||||
return nil, fmt.Errorf("default directory '%s' does not exist", dialogOptions.DefaultDirectory)
|
||||
}
|
||||
}
|
||||
return appFrontend.OpenMultipleFilesDialog(dialogOptions)
|
||||
}
|
||||
|
||||
// SaveFileDialog prompts the user to select a file
|
||||
func SaveFileDialog(ctx context.Context, dialogOptions SaveDialogOptions) (string, error) {
|
||||
appFrontend := getFrontend(ctx)
|
||||
if dialogOptions.DefaultDirectory != "" {
|
||||
if !fs.DirExists(dialogOptions.DefaultDirectory) {
|
||||
return "", fmt.Errorf("default directory '%s' does not exist", dialogOptions.DefaultDirectory)
|
||||
}
|
||||
}
|
||||
return appFrontend.SaveFileDialog(dialogOptions)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue