diff options
author | Nelson Benítez León <nbenitezl@gmail.com> | 2020-04-13 15:53:26 -0400 |
---|---|---|
committer | Nelson Benítez León <nbenitezl@gmail.com> | 2020-04-13 16:33:10 -0400 |
commit | e6ff990145a5512b322ed188669749ca3958b5f8 (patch) | |
tree | 9909f188505cbc21ab77d7c16dab7e624bd47922 | |
parent | c8d058137a112f417c1d42abccd63231fbec8caa (diff) | |
download | gtk+-e6ff990145a5512b322ed188669749ca3958b5f8.tar.gz |
GtkFilechooserWidget: prevent oblivious selection of file
which could happen after confirming the "file overwrite"
dialog and may result in a different file being overwritten
causing data loss.
The oblivious file selection can be done by a mouse
click or keyboard press sent inadvertently just after
confirming the "file overwrite" dialog.
Fixed by adding a flag to ignore any button/key press
events sent to the file list. We set this flag just
after the user accepts the "file overwrite" dialog,
which means the enclosing GtkfilechooserDialog is about
to get closed. And we restablish the flag when the dialog
is shown again (in its map() handler).
Fixes data loss issue #2288
-rw-r--r-- | gtk/gtkfilechooserwidget.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 369b8995a2..0a64c34095 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -376,6 +376,7 @@ struct _GtkFileChooserWidgetPrivate { guint show_type_column : 1; guint create_folders : 1; guint auto_selecting_first_row : 1; + guint browse_files_interaction_frozen : 1; }; #define MAX_LOADING_TIME 500 @@ -1348,6 +1349,9 @@ browse_files_key_press_event_cb (GtkWidget *widget, GtkFileChooserWidget *impl = (GtkFileChooserWidget *) data; GtkFileChooserWidgetPrivate *priv = impl->priv; + if (priv->browse_files_interaction_frozen) + return GDK_EVENT_STOP; + if (should_trigger_location_entry (impl, event) && (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN || priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)) @@ -2437,6 +2441,9 @@ list_button_press_event_cb (GtkWidget *widget, GtkFileChooserWidgetPrivate *priv = impl->priv; static gboolean in_press = FALSE; + if (priv->browse_files_interaction_frozen) + return GDK_EVENT_STOP; + if (in_press) return FALSE; @@ -4080,6 +4087,8 @@ gtk_file_chooser_widget_map (GtkWidget *widget) profile_start ("start", NULL); + priv->browse_files_interaction_frozen = FALSE; + GTK_WIDGET_CLASS (gtk_file_chooser_widget_parent_class)->map (widget); settings_load (impl); @@ -6565,6 +6574,11 @@ G_GNUC_END_IGNORE_DEPRECATIONS response = gtk_dialog_run (GTK_DIALOG (dialog)); + if (response == GTK_RESPONSE_ACCEPT) + /* Dialog is now going to be closed, so prevent any button/key presses to + * file list (will be restablished on next map()). Fixes data loss bug #2288 */ + impl->priv->browse_files_interaction_frozen = TRUE; + gtk_widget_destroy (dialog); return (response == GTK_RESPONSE_ACCEPT); |