[Xfce4-commits] [xfce/thunar] 01/01: Add a confirmation dialog when closing a window with multiple open tabs.
noreply at xfce.org
noreply at xfce.org
Wed Aug 21 00:04:37 CEST 2019
This is an automated email from the git hooks/post-receive script.
a l e x p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository xfce/thunar.
commit 33f6570e3c828f5867244bed3a3f6d9403feaa9d
Author: Reuben Green <reubengreen73 at gmail.com>
Date: Mon Aug 19 14:44:13 2019 +0100
Add a confirmation dialog when closing a window with multiple open tabs.
Adds a confirmation dialog to ask for user confirmation when closing a window
with multiple open tabs. The user can choose to close the window, close the
current tab, or cancel. The user can deactivate this confirmation via a
checkbox in the dialog.
(Bug #15758)
---
thunar/thunar-preferences.c | 14 ++++++++
thunar/thunar-window.c | 83 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+)
diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c
index 916ee34..ba1efd4 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,
@@ -763,6 +764,19 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
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:
*
* Whether to display emblems for file icons (if defined) in the
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index 7755725..c27798d 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,83 @@ thunar_window_finalize (GObject *object)
+static gboolean thunar_window_delete( GtkWidget *widget,
+ GdkEvent *event,
+ gpointer data )
+{
+ GtkWidget *dialog, *grid, *label, *icon, *checkbutton;
+ GtkNotebook *notebook;
+ const gchar *title;
+ gchar *message, *markup;
+ gboolean confirm_close_multiple_tabs;
+ gint response, n_tabs;
+
+ _thunar_return_val_if_fail (THUNAR_IS_WINDOW (widget),FALSE);
+
+ /* if we don't have muliple tabs then just exit */
+ notebook = GTK_NOTEBOOK (THUNAR_WINDOW (widget)->notebook);
+ n_tabs = gtk_notebook_get_n_pages (GTK_NOTEBOOK (THUNAR_WINDOW (widget)->notebook));
+ if (n_tabs < 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;
+
+ /* ask the user for confirmation */
+ dialog = gtk_dialog_new_with_buttons (_("Warning"),
+ GTK_WINDOW (dialog),
+ GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("Close T_ab"), GTK_RESPONSE_CLOSE,
+ _("Close _Window"), GTK_RESPONSE_YES,
+ NULL);
+ grid = gtk_grid_new ();
+ gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
+ gtk_widget_set_margin_start (grid, 12);
+ gtk_widget_set_margin_end (grid, 12);
+ gtk_widget_set_margin_top (grid, 12);
+ gtk_widget_set_margin_bottom (grid, 12);
+ gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), grid);
+
+ icon = gtk_image_new_from_icon_name ("dialog-warning", GTK_ICON_SIZE_DIALOG);
+ gtk_grid_attach (GTK_GRID (grid), icon, 0, 0, 1, 2);
+
+ title = _("Close all tabs?");
+ message = g_strdup_printf (_("This window has %d tabs open. Closing this window\n"
+ "will also close all its tabs."), n_tabs);
+ markup = g_markup_printf_escaped ("<span weight='bold' size='larger'>%s</span>\n%s\n", title, message);
+ g_free (message);
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label), markup);
+ g_free (markup);
+ gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
+
+ checkbutton = gtk_check_button_new_with_mnemonic (_("Do _not ask me again"));
+ gtk_grid_attach (GTK_GRID (grid), checkbutton, 1, 1, 1, 1);
+
+ gtk_widget_show_all (dialog);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ /* if the user requested not to be asked again, store this preference */
+ if (response != GTK_RESPONSE_CANCEL && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton)))
+ g_object_set (G_OBJECT (THUNAR_WINDOW (widget)->preferences),
+ "misc-confirm-close-multiple-tabs", FALSE, NULL);
+
+ gtk_widget_destroy (dialog);
+
+ if(response == GTK_RESPONSE_YES)
+ return FALSE;
+ if(response == GTK_RESPONSE_CLOSE)
+ gtk_notebook_remove_page (notebook, gtk_notebook_get_current_page(notebook));
+ return TRUE;
+}
+
+
+
static void
thunar_window_get_property (GObject *object,
guint prop_id,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list