mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 14:42:03 +08:00
Support default directory, Fixed label, removed TreatPackagesAsDirectories
This commit is contained in:
parent
a7e516a43d
commit
c58252386f
@ -54,7 +54,6 @@ func (f *Frontend) SaveFileDialog(dialogOptions frontend.SaveDialogOptions) (str
|
|||||||
Filters: dialogOptions.Filters,
|
Filters: dialogOptions.Filters,
|
||||||
ShowHiddenFiles: dialogOptions.ShowHiddenFiles,
|
ShowHiddenFiles: dialogOptions.ShowHiddenFiles,
|
||||||
CanCreateDirectories: dialogOptions.CanCreateDirectories,
|
CanCreateDirectories: dialogOptions.CanCreateDirectories,
|
||||||
TreatPackagesAsDirectories: dialogOptions.TreatPackagesAsDirectories,
|
|
||||||
}
|
}
|
||||||
f.mainWindow.OpenFileDialog(options, 0, GTK_FILE_CHOOSER_ACTION_SAVE)
|
f.mainWindow.OpenFileDialog(options, 0, GTK_FILE_CHOOSER_ACTION_SAVE)
|
||||||
results := <-openFileResults
|
results := <-openFileResults
|
||||||
|
@ -206,6 +206,7 @@ typedef struct OpenFileDialogOptions {
|
|||||||
void* webview;
|
void* webview;
|
||||||
char* title;
|
char* title;
|
||||||
char* defaultFilename;
|
char* defaultFilename;
|
||||||
|
char* defaultDirectory;
|
||||||
int createDirectories;
|
int createDirectories;
|
||||||
int multipleFiles;
|
int multipleFiles;
|
||||||
int showHiddenFiles;
|
int showHiddenFiles;
|
||||||
@ -223,9 +224,13 @@ void freeFileFilterArray(GtkFileFilter** filters) {
|
|||||||
|
|
||||||
int opendialog(gpointer data) {
|
int opendialog(gpointer data) {
|
||||||
struct OpenFileDialogOptions *options = data;
|
struct OpenFileDialogOptions *options = data;
|
||||||
|
char *label = "_Open";
|
||||||
|
if (options->action == GTK_FILE_CHOOSER_ACTION_SAVE) {
|
||||||
|
label = "_Save";
|
||||||
|
}
|
||||||
GtkWidget *dlgWidget = gtk_file_chooser_dialog_new(options->title, options->webview, options->action,
|
GtkWidget *dlgWidget = gtk_file_chooser_dialog_new(options->title, options->webview, options->action,
|
||||||
"_Cancel", GTK_RESPONSE_CANCEL,
|
"_Cancel", GTK_RESPONSE_CANCEL,
|
||||||
"_Open", GTK_RESPONSE_ACCEPT,
|
label, GTK_RESPONSE_ACCEPT,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
GtkFileChooser *fc = GTK_FILE_CHOOSER(dlgWidget);
|
GtkFileChooser *fc = GTK_FILE_CHOOSER(dlgWidget);
|
||||||
@ -253,6 +258,11 @@ int opendialog(gpointer data) {
|
|||||||
gtk_file_chooser_set_show_hidden(fc, TRUE);
|
gtk_file_chooser_set_show_hidden(fc, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options->defaultDirectory != NULL) {
|
||||||
|
gtk_file_chooser_set_current_folder (fc, options->defaultDirectory);
|
||||||
|
free(options->defaultDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
if (options->action == GTK_FILE_CHOOSER_ACTION_SAVE) {
|
if (options->action == GTK_FILE_CHOOSER_ACTION_SAVE) {
|
||||||
if (options->defaultFilename != NULL) {
|
if (options->defaultFilename != NULL) {
|
||||||
gtk_file_chooser_set_current_name(fc, options->defaultFilename);
|
gtk_file_chooser_set_current_name(fc, options->defaultFilename);
|
||||||
@ -572,7 +582,7 @@ func (w *Window) OpenFileDialog(dialogOptions frontend.OpenDialogOptions, multip
|
|||||||
filters[index] = thisFilter
|
filters[index] = thisFilter
|
||||||
}
|
}
|
||||||
mem.Free()
|
mem.Free()
|
||||||
filters[arraySize-1] = (*C.struct__GtkFileFilter)(unsafe.Pointer(uintptr(0)))
|
filters[arraySize-1] = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if dialogOptions.CanCreateDirectories {
|
if dialogOptions.CanCreateDirectories {
|
||||||
@ -586,5 +596,10 @@ func (w *Window) OpenFileDialog(dialogOptions frontend.OpenDialogOptions, multip
|
|||||||
if dialogOptions.DefaultFilename != "" {
|
if dialogOptions.DefaultFilename != "" {
|
||||||
data.defaultFilename = C.CString(dialogOptions.DefaultFilename)
|
data.defaultFilename = C.CString(dialogOptions.DefaultFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dialogOptions.DefaultDirectory != "" {
|
||||||
|
data.defaultDirectory = C.CString(dialogOptions.DefaultDirectory)
|
||||||
|
}
|
||||||
|
|
||||||
C.ExecuteOnMainThread(C.opendialog, C.gpointer(&data))
|
C.ExecuteOnMainThread(C.opendialog, C.gpointer(&data))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user