diff options
-rw-r--r-- | src/window.c | 47 |
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); |