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>
This commit is contained in:
Shawn Rutledge 2014-08-05 12:58:47 +02:00
parent 276036179a
commit 2ad9e69a9f

View File

@ -308,8 +308,14 @@ QUrl QGtk2FileDialogHelper::directory() const
void QGtk2FileDialogHelper::selectFile(const QUrl &filename)
{
GtkDialog *gtkDialog = d->gtkDialog();
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
{