Set the mode for the GTK3 file chooser also in selectFile

If the mode is not GTK_FILE_CHOOSER_ACTION_SAVE or
GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER , a GTK warning will
be generated which makes Qt WebEngine's Glib error handler
assert. Doing so only when showing the dialog is too late.

This patch moves the actual file selection to a private method
that can be called from both selectFile and applyOptions in
order to prevent overwriting the file chooser action potentially
multiple times.

Task-number: QTBUG-59692
Change-Id: Ied939248cdc3a0b4c9e8239ab61ba617a46b8496
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
This commit is contained in:
Michael Brüning 2017-03-28 17:12:44 +02:00
parent ff259bffe6
commit 78f761318a
2 changed files with 18 additions and 3 deletions

View File

@ -315,6 +315,12 @@ QUrl QGtk3FileDialogHelper::directory() const
}
void QGtk3FileDialogHelper::selectFile(const QUrl &filename)
{
setFileChooserAction();
selectFileInternal(filename);
}
void QGtk3FileDialogHelper::selectFileInternal(const QUrl &filename)
{
GtkDialog *gtkDialog = d->gtkDialog();
if (options()->acceptMode() == QFileDialogOptions::AcceptSave) {
@ -409,6 +415,14 @@ static GtkFileChooserAction gtkFileChooserAction(const QSharedPointer<QFileDialo
}
}
void QGtk3FileDialogHelper::setFileChooserAction()
{
GtkDialog *gtkDialog = d->gtkDialog();
const GtkFileChooserAction action = gtkFileChooserAction(options());
gtk_file_chooser_set_action(GTK_FILE_CHOOSER(gtkDialog), action);
}
void QGtk3FileDialogHelper::applyOptions()
{
GtkDialog *gtkDialog = d->gtkDialog();
@ -417,8 +431,7 @@ void QGtk3FileDialogHelper::applyOptions()
gtk_window_set_title(GTK_WINDOW(gtkDialog), opts->windowTitle().toUtf8());
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(gtkDialog), true);
const GtkFileChooserAction action = gtkFileChooserAction(opts);
gtk_file_chooser_set_action(GTK_FILE_CHOOSER(gtkDialog), action);
setFileChooserAction();
const bool selectMultiple = opts->fileMode() == QFileDialogOptions::ExistingFiles;
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(gtkDialog), selectMultiple);
@ -437,7 +450,7 @@ void QGtk3FileDialogHelper::applyOptions()
setDirectory(opts->initialDirectory());
foreach (const QUrl &filename, opts->initiallySelectedFiles())
selectFile(filename);
selectFileInternal(filename);
const QString initialNameFilter = opts->initiallySelectedNameFilter();
if (!initialNameFilter.isEmpty())

View File

@ -110,6 +110,8 @@ private:
static void onFilterChanged(QGtk3FileDialogHelper *helper);
void applyOptions();
void setNameFilters(const QStringList &filters);
void selectFileInternal(const QUrl &filename);
void setFileChooserAction();
QUrl _dir;
QList<QUrl> _selection;