Use last selected directory when using default file name in dialog.showSaveDialog()
Prior to this change, attempting to use `dialog.showSaveDialog({ defaultPath: 'foo.png' })` would open the save dialog to the current directory with the default file name set to `foo.png`. We now use the last selected directory instead of the current directory. Absolute paths are not affected by this change.
This commit is contained in:
parent
fea165bef8
commit
19555bbab2
4 changed files with 16 additions and 6 deletions
|
@ -72,8 +72,12 @@ class FileChooserDialog {
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog_),
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog_),
|
||||||
settings.default_path.value().c_str());
|
settings.default_path.value().c_str());
|
||||||
} else {
|
} else {
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog_),
|
if (settings.default_path.IsAbsolute()) {
|
||||||
|
gtk_file_chooser_set_current_folder(
|
||||||
|
GTK_FILE_CHOOSER(dialog_),
|
||||||
settings.default_path.DirName().value().c_str());
|
settings.default_path.DirName().value().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog_),
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog_),
|
||||||
settings.default_path.BaseName().value().c_str());
|
settings.default_path.BaseName().value().c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,11 @@ void SetupDialog(NSSavePanel* dialog,
|
||||||
if (base::DirectoryExists(settings.default_path)) {
|
if (base::DirectoryExists(settings.default_path)) {
|
||||||
default_dir = base::SysUTF8ToNSString(settings.default_path.value());
|
default_dir = base::SysUTF8ToNSString(settings.default_path.value());
|
||||||
} else {
|
} else {
|
||||||
|
if (settings.default_path.IsAbsolute()) {
|
||||||
default_dir =
|
default_dir =
|
||||||
base::SysUTF8ToNSString(settings.default_path.DirName().value());
|
base::SysUTF8ToNSString(settings.default_path.DirName().value());
|
||||||
|
}
|
||||||
|
|
||||||
default_filename =
|
default_filename =
|
||||||
base::SysUTF8ToNSString(settings.default_path.BaseName().value());
|
base::SysUTF8ToNSString(settings.default_path.BaseName().value());
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,10 @@ class FileDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.default_path.IsAbsolute()) {
|
||||||
SetDefaultFolder(settings.default_path);
|
SetDefaultFolder(settings.default_path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Show(atom::NativeWindow* parent_window) {
|
bool Show(atom::NativeWindow* parent_window) {
|
||||||
atom::UnresponsiveSuppressor suppressor;
|
atom::UnresponsiveSuppressor suppressor;
|
||||||
|
|
|
@ -87,7 +87,8 @@ shown.
|
||||||
* `browserWindow` BrowserWindow (optional)
|
* `browserWindow` BrowserWindow (optional)
|
||||||
* `options` Object
|
* `options` Object
|
||||||
* `title` String (optional)
|
* `title` String (optional)
|
||||||
* `defaultPath` String (optional)
|
* `defaultPath` String (optional) - Absolute directory path, absolute file
|
||||||
|
path, or file name to use by default.
|
||||||
* `buttonLabel` String (optional) - Custom label for the confirmation button, when
|
* `buttonLabel` String (optional) - Custom label for the confirmation button, when
|
||||||
left empty the default label will be used.
|
left empty the default label will be used.
|
||||||
* `filters` [FileFilter[]](structures/file-filter.md) (optional)
|
* `filters` [FileFilter[]](structures/file-filter.md) (optional)
|
||||||
|
|
Loading…
Reference in a new issue