summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-07 17:53:30 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-07 17:59:59 (EDT)
commit7c722da00394561ddede4c85ae5ec3c37d698ec5 (patch)
tree8ee6e88ad205033c05afa7002ae5010f8b1a59f2
parentc61a6ed6dfa53053a6ee21ca83bea3ec9d5c28c6 (diff)
downloadmarquee-7c722da00394561ddede4c85ae5ec3c37d698ec5.zip
marquee-7c722da00394561ddede4c85ae5ec3c37d698ec5.tar.gz
marquee-7c722da00394561ddede4c85ae5ec3c37d698ec5.tar.bz2
MqWindow: Confirm close of multiple tabs
-rw-r--r--src/window.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/window.c b/src/window.c
index f530b31..ad5b9a5 100644
--- a/src/window.c
+++ b/src/window.c
@@ -46,6 +46,51 @@ configure_event_cb(GtkWindow G_GNUC_UNUSED *window, GdkEventConfigure *event,
}
static void
+close_confirm_response_cb(GtkWidget *dialog, gint response_id, MqWindow *window)
+{
+ gtk_widget_destroy(dialog);
+ if (response_id == GTK_RESPONSE_OK) {
+ gtk_widget_destroy(window->window);
+ }
+}
+
+static gboolean
+delete_event_cb(GtkWindow *widget, GdkEvent G_GNUC_UNUSED *event,
+ MqWindow *window)
+{
+ guint num_tabs;
+ GtkWidget *dialog;
+ GtkWidget *box;
+ gchar *msg;
+
+ num_tabs = mq_tab_get_tree_size(window->root_tab) - 1;
+
+ if (num_tabs == 1) {
+ return FALSE;
+ }
+
+ if (!mq_config_get_boolean(window->config, "tabs.warn-on-close")) {
+ return FALSE;
+ }
+
+ dialog = gtk_dialog_new_with_buttons("Confirm Close", widget,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ "_Cancel", GTK_RESPONSE_CANCEL,
+ "Cl_ose Tabs", GTK_RESPONSE_OK,
+ NULL);
+ box = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ msg = g_strdup_printf("You are about to close %d tabs. "
+ "Are you sure you want to continue?", num_tabs);
+ gtk_container_add(GTK_CONTAINER(box), gtk_label_new(msg));
+ g_free(msg);
+ g_signal_connect(dialog, "response",
+ G_CALLBACK(close_confirm_response_cb), window);
+ gtk_widget_show_all(dialog);
+
+ return TRUE;
+}
+
+static void
destroy_cb(GtkWidget G_GNUC_UNUSED *widget, MqWindow *window)
{
mq_application_delete_window(window->application, window);
@@ -107,6 +152,8 @@ mq_window_new(MqApplication *application, const gchar **uris)
G_CALLBACK(is_maximized_cb), window->config);
g_signal_connect(window->window, "configure-event",
G_CALLBACK(configure_event_cb), window->config);
+ g_signal_connect(window->window, "delete-event",
+ G_CALLBACK(delete_event_cb), window);
g_signal_connect(window->window, "destroy",
G_CALLBACK(destroy_cb), window);