[tepl] Tab: create close confirm dialog on ::close-request



commit 0360875f89b598701101b7fd38e0c9d6fd4842c9
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Nov 25 06:17:37 2017 +0100

    Tab: create close confirm dialog on ::close-request
    
    Currently the method handler does nothing, but it will soon do a little
    more than that.

 docs/reference/api-breaks.xml |    6 ++++++
 tepl/tepl-tab.c               |   28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/api-breaks.xml b/docs/reference/api-breaks.xml
index 685ed32..2f0d73a 100644
--- a/docs/reference/api-breaks.xml
+++ b/docs/reference/api-breaks.xml
@@ -112,6 +112,12 @@
           is still GTK+&nbsp;3.
         </para>
       </listitem>
+      <listitem>
+        <para>
+          The <link linkend="TeplTab-close-request">TeplTab::close-request</link>
+          signal has now a default object method handler.
+        </para>
+      </listitem>
     </itemizedlist>
   </chapter>
 </part>
diff --git a/tepl/tepl-tab.c b/tepl/tepl-tab.c
index 4607840..9120ebc 100644
--- a/tepl/tepl-tab.c
+++ b/tepl/tepl-tab.c
@@ -21,6 +21,7 @@
 #include "tepl-tab.h"
 #include <glib/gi18n-lib.h>
 #include "tepl-buffer.h"
+#include "tepl-close-confirm-dialog-single.h"
 #include "tepl-file-loader.h"
 #include "tepl-file-metadata.h"
 #include "tepl-file-saver.h"
@@ -173,6 +174,25 @@ tepl_tab_pack_info_bar_default (TeplTab    *tab,
 }
 
 static void
+close_confirm_dialog_single_cb (GObject      *source_object,
+                               GAsyncResult *result,
+                               gpointer      user_data)
+{
+       TeplTab *tab = TEPL_TAB (source_object);
+
+       if (_tepl_close_confirm_dialog_single_finish (tab, result))
+       {
+               gtk_widget_destroy (GTK_WIDGET (tab));
+       }
+}
+
+static void
+tepl_tab_close_request_default (TeplTab *tab)
+{
+       _tepl_close_confirm_dialog_single_async (tab, close_confirm_dialog_single_cb, NULL);
+}
+
+static void
 buffer_notify_cb (GtkTextView *view,
                  GParamSpec  *pspec,
                  TeplTab     *tab)
@@ -286,6 +306,7 @@ tepl_tab_class_init (TeplTabClass *klass)
 
        klass->pack_view = tepl_tab_pack_view_default;
        klass->pack_info_bar = tepl_tab_pack_info_bar_default;
+       klass->close_request = tepl_tab_close_request_default;
 
        /**
         * TeplTab:view:
@@ -316,6 +337,13 @@ tepl_tab_class_init (TeplTabClass *klass)
         * The ::close-request signal is emitted when there is a request to
         * close the #TeplTab, for example if the user clicks on a close button.
         *
+        * The default object method handler does the following:
+        * - Nothing.
+        *
+        * To override the default object method handler, either override the
+        * virtual function in a #TeplTab subclass or connect to the signal and
+        * call g_signal_stop_emission_by_name().
+        *
         * Since: 3.0
         */
        signals[SIGNAL_CLOSE_REQUEST] =


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]