From 0fc468afd83e966318d7b78761a88186392c3291 Mon Sep 17 00:00:00 2001 From: Reuben Green Date: Fri, 9 Aug 2019 14:33:29 +0100 Subject: [PATCH] Add a optional confirmation dialog when closing a window with multiple open tabs. Adds the option to ask for user confirmation when closing a window with multiple open tabs. This option may be toggled on and off via the preferences dialog, and the user's choice is stored between sessions in the "misc-confirm-close-multiple-tabs" preference. (Bug #15758) --- thunar/thunar-preferences-dialog.c | 25 ++++++++++++++ thunar/thunar-preferences.c | 14 ++++++++ thunar/thunar-window.c | 53 ++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c index dc12bec7..d7253969 100644 --- a/thunar/thunar-preferences-dialog.c +++ b/thunar/thunar-preferences-dialog.c @@ -665,6 +665,31 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog) gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1); gtk_widget_show (button); + frame = g_object_new (GTK_TYPE_FRAME, "border-width", 0, "shadow-type", GTK_SHADOW_NONE, NULL); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0); + gtk_widget_show (frame); + + label = gtk_label_new (_("Multiple Tabs")); + gtk_label_set_attributes (GTK_LABEL (label), thunar_pango_attr_list_bold ()); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_widget_show (label); + + grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 12); + gtk_grid_set_row_spacing (GTK_GRID (grid), 6); + gtk_widget_set_margin_top (GTK_WIDGET (grid), 6); + gtk_widget_set_margin_start (GTK_WIDGET (grid), 12); + gtk_container_add (GTK_CONTAINER (frame), grid); + gtk_widget_show (grid); + + button = gtk_check_button_new_with_mnemonic (_("Confirm before closing _multiple tabs")); + exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-confirm-close-multiple-tabs", G_OBJECT (button), "active"); + gtk_widget_set_tooltip_text (button, + _("Select this option to ask for confirmation before closing a window containing multiple tabs")); + gtk_widget_set_hexpand (button, TRUE); + gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1); + gtk_widget_show (button); + if (thunar_g_vfs_is_uri_scheme_supported ("trash")) { frame = g_object_new (GTK_TYPE_FRAME, "border-width", 0, "shadow-type", GTK_SHADOW_NONE, NULL); diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 916ee345..ba1efd45 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -96,6 +96,7 @@ enum PROP_MISC_THUMBNAIL_MODE, PROP_MISC_THUMBNAIL_DRAW_FRAMES, PROP_MISC_FILE_SIZE_BINARY, + PROP_MISC_CONFIRM_CLOSE_MULTIPLE_TABS, PROP_SHORTCUTS_ICON_EMBLEMS, PROP_SHORTCUTS_ICON_SIZE, PROP_TREE_ICON_EMBLEMS, @@ -762,6 +763,19 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) TRUE, EXO_PARAM_READWRITE); + /** + * ThunarPreferences:misc-confirm-close-multiple-tabs: + * + * Ask the user for confirmation before closing a window with + * multiple tabs. + **/ + preferences_props[PROP_MISC_CONFIRM_CLOSE_MULTIPLE_TABS] = + g_param_spec_boolean ("misc-confirm-close-multiple-tabs", + "ConfirmCloseMultipleTabs", + NULL, + TRUE, + EXO_PARAM_READWRITE); + /** * ThunarPreferences:shortcuts-icon-emblems: * diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index 7755725b..57ab152b 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -94,6 +94,9 @@ enum static void thunar_window_dispose (GObject *object); static void thunar_window_finalize (GObject *object); +static gboolean thunar_window_delete (GtkWidget *widget, + GdkEvent *event, + gpointer data); static void thunar_window_get_property (GObject *object, guint prop_id, GValue *value, @@ -744,6 +747,9 @@ thunar_window_init (ThunarWindow *window) "misc-small-toolbar-icons", &small_icons, NULL); + /* set up a handler to confirm exit when there are multiple tabs open */ + g_signal_connect (window, "delete-event", G_CALLBACK (thunar_window_delete), NULL); + /* connect to the volume monitor */ window->device_monitor = thunar_device_monitor_get (); g_signal_connect (window->device_monitor, "device-pre-unmount", G_CALLBACK (thunar_window_device_pre_unmount), window); @@ -1085,6 +1091,53 @@ thunar_window_finalize (GObject *object) +static gboolean thunar_window_delete( GtkWidget *widget, + GdkEvent *event, + gpointer data ) +{ + GtkWidget *dialog, *label, *vbox; + gboolean confirm_close_multiple_tabs; + gint response; + + _thunar_return_val_if_fail (THUNAR_IS_WINDOW (widget),FALSE); + + /* if we don't have muliple tabs then just exit */ + if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (THUNAR_WINDOW (widget)->notebook)) < 2) + return FALSE; + + /* check if the user has disabled confirmation of closing multiple tabs, and just exit if so */ + g_object_get (G_OBJECT (THUNAR_WINDOW (widget)->preferences), + "misc-confirm-close-multiple-tabs", &confirm_close_multiple_tabs, + NULL); + if(!confirm_close_multiple_tabs) + return FALSE; + + dialog = gtk_dialog_new_with_buttons (_("Close Multiple Tabs"),GTK_WINDOW (widget), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + _("C_lose Window"),GTK_RESPONSE_ACCEPT, + _("_Cancel"),GTK_RESPONSE_REJECT, + NULL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT); + gtk_window_set_default_size (GTK_WINDOW (dialog), 290, -1); + + vbox = g_object_new (GTK_TYPE_BOX, "orientation", GTK_ORIENTATION_VERTICAL, "border-width", 6, "spacing", 10, NULL); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), vbox, TRUE, TRUE, 0); + gtk_widget_show (vbox); + + label = gtk_label_new_with_mnemonic (_("You have multiple tabs open. Are you sure you want to close the window?")); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy (dialog); + if(response == GTK_RESPONSE_ACCEPT) + return FALSE; + else + return TRUE; +} + + + static void thunar_window_get_property (GObject *object, guint prop_id, -- 2.20.1