summaryrefslogtreecommitdiffstats
path: root/src/plugins/platformthemes/gtk2
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2014-08-05 12:58:47 +0200
committerShawn Rutledge <shawn.rutledge@digia.com>2014-08-06 17:10:07 +0200
commit2ad9e69a9f9231b5f65a53036ae60bb0abc93609 (patch)
tree3b0834b8c95f71c745c73dd4dcd5d7560cdd30af /src/plugins/platformthemes/gtk2
parent276036179a112abf45bb433ef3b918ed68b807ff (diff)
GTK file dialog: pre-fill the filename if given to a Save dialog
The docs for gtk_file_chooser_set_filename explain that if a file is new, we should call gtk_file_chooser_set_current_name instead. (But in that case it is necessary to set the directory separately.) Qt doesn't make a distinction between a save dialog for saving a new file vs. a dialog for re-saving an existing file, so it seems this is the better way to do it all the time, since a save dialog would most often be used for saving a new file. Task-number: QTBUG-40573 Change-Id: I285e898fafc54ae39f09d564ca431a279a8f8919 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/plugins/platformthemes/gtk2')
-rw-r--r--src/plugins/platformthemes/gtk2/qgtk2dialoghelpers.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/plugins/platformthemes/gtk2/qgtk2dialoghelpers.cpp b/src/plugins/platformthemes/gtk2/qgtk2dialoghelpers.cpp
index f85fe0839f..506c29c9cf 100644
--- a/src/plugins/platformthemes/gtk2/qgtk2dialoghelpers.cpp
+++ b/src/plugins/platformthemes/gtk2/qgtk2dialoghelpers.cpp
@@ -308,7 +308,13 @@ QUrl QGtk2FileDialogHelper::directory() const
void QGtk2FileDialogHelper::selectFile(const QUrl &filename)
{
GtkDialog *gtkDialog = d->gtkDialog();
- gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(gtkDialog), filename.toLocalFile().toUtf8());
+ if (options()->acceptMode() == QFileDialogOptions::AcceptSave) {
+ QFileInfo fi(filename.toLocalFile());
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(gtkDialog), fi.path().toUtf8());
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(gtkDialog), fi.fileName().toUtf8());
+ } else {
+ gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(gtkDialog), filename.toLocalFile().toUtf8());
+ }
}
QList<QUrl> QGtk2FileDialogHelper::selectedFiles() const