[recipes] Warn if the window is closed with unsaved changes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Warn if the window is closed with unsaved changes
- Date: Sat, 11 Mar 2017 04:57:33 +0000 (UTC)
commit 52e11bdb88c560c9e8041a0fd22f3c82412e5ddc
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Mar 10 23:56:02 2017 -0500
Warn if the window is closed with unsaved changes
Now that we track the unsaved status of the edit page,
this is very easy to do.
https://bugzilla.gnome.org/show_bug.cgi?id=778201
https://bugzilla.gnome.org/show_bug.cgi?id=779602
src/gr-window.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/gr-window.ui | 1 +
2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-window.c b/src/gr-window.c
index af72294..102833b 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -456,6 +456,55 @@ window_mapped_handler (GtkWidget *widget)
}
static void
+response_cb (GtkDialog *dialog,
+ int response,
+ gpointer data)
+{
+ GrWindow *window = data;
+
+ if (response == GTK_RESPONSE_YES)
+ gtk_widget_destroy (GTK_WIDGET (window));
+ else
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static gboolean
+window_delete_handler (GtkWidget *widget)
+{
+ GrWindow *window = GR_WINDOW (widget);
+ const char *visible;
+ gboolean unsaved;
+
+ visible = gtk_stack_get_visible_child_name (GTK_STACK (window->main_stack));
+ g_object_get (window->edit_page, "unsaved", &unsaved, NULL);
+
+ if (strcmp (visible, "edit") == 0 && unsaved) {
+ GtkWidget *dialog;
+ GrRecipe *recipe;
+ g_autofree char *text = NULL;
+
+ recipe = gr_edit_page_get_recipe (GR_EDIT_PAGE (window->edit_page));
+ if (recipe)
+ text = g_strdup_printf (_("The ā%sā recipe has unsaved changes.\nClose the window
anyway?"),
+ gr_recipe_get_name (recipe));
+ else
+ text = g_strdup (_("The new recipe has not been saved.\nClose the window anyway?"));
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ "%s", text);
+ g_signal_connect (dialog, "response", G_CALLBACK (response_cb), window);
+ gtk_widget_show (dialog);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
hide_or_show_header_end_stack (GObject *object,
GParamSpec *pspec,
GrWindow *window)
@@ -760,6 +809,7 @@ gr_window_class_init (GrWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, window_keypress_handler_before);
gtk_widget_class_bind_template_callback (widget_class, window_buttonpress_handler);
gtk_widget_class_bind_template_callback (widget_class, window_mapped_handler);
+ gtk_widget_class_bind_template_callback (widget_class, window_delete_handler);
gtk_widget_class_bind_template_callback (widget_class, do_undo);
gtk_widget_class_bind_template_callback (widget_class, close_undo);
gtk_widget_class_bind_template_callback (widget_class, do_remind);
diff --git a/src/gr-window.ui b/src/gr-window.ui
index a8021e3..ea7de13 100644
--- a/src/gr-window.ui
+++ b/src/gr-window.ui
@@ -6,6 +6,7 @@
<signal name="key-press-event" handler="window_keypress_handler_before"/>
<signal name="key-press-event" handler="window_keypress_handler" after="yes"/>
<signal name="button-press-event" handler="window_buttonpress_handler" after="yes"/>
+ <signal name="delete-event" handler="window_delete_handler"/>
<signal name="map" handler="window_mapped_handler" after="yes"/>
<child type="titlebar">
<object class="GtkHeaderBar" id="header">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]