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
This commit is contained in:
Nelson Benítez León
2020-04-13 15:53:26 -04:00
parent c8d058137a
commit e6ff990145

View File

@ -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);