[console] tab: avoid double removal



commit b2ce4632de0abf3a9f1c78836b6931fe71191a94
Author: Zander Brown <zbrown gnome org>
Date:   Thu Aug 25 13:34:53 2022 +0100

    tab: avoid double removal
    
    Some scenarios caused the page to be removed twice, putting us in
    undefined terrotory
    
    Rearrange things a little so that pages are always managed by …pages…
    rather than a tab trying to remove itself
    
    Use a vfunc rather than connecting to our own signal

 src/kgx-pages.c |  2 +-
 src/kgx-tab.c   | 66 ++++++++++++++++++++++++++++-----------------------------
 src/kgx-tab.h   |  5 +++++
 3 files changed, 39 insertions(+), 34 deletions(-)
---
diff --git a/src/kgx-pages.c b/src/kgx-pages.c
index c97823b..4fcc075 100644
--- a/src/kgx-pages.c
+++ b/src/kgx-pages.c
@@ -342,7 +342,7 @@ died (KgxTab         *page,
 
   g_object_get (page, "close-on-quit", &close_on_quit, NULL);
 
-  if (!close_on_quit) {
+  if (!(close_on_quit && success)) {
     return;
   }
 
diff --git a/src/kgx-tab.c b/src/kgx-tab.c
index cffb6fe..0ddfc70 100644
--- a/src/kgx-tab.c
+++ b/src/kgx-tab.c
@@ -32,6 +32,7 @@
 #include "kgx-terminal.h"
 #include "kgx-util.h"
 #include "kgx-application.h"
+#include "kgx-marshals.h"
 
 
 typedef struct _KgxTabPrivate KgxTabPrivate;
@@ -509,6 +510,30 @@ kgx_tab_real_start_finish (KgxTab        *tab,
 }
 
 
+static void
+kgx_tab_real_died (KgxTab         *self,
+                   GtkMessageType  type,
+                   const char     *message,
+                   gboolean        success)
+{
+  KgxTabPrivate *priv;
+
+  g_return_if_fail (KGX_IS_TAB (self));
+
+  priv = kgx_tab_get_instance_private (self);
+
+  gtk_label_set_markup (GTK_LABEL (priv->label), message);
+
+  if (type == GTK_MESSAGE_ERROR) {
+    gtk_widget_add_css_class (priv->revealer, "error");
+  } else {
+    gtk_widget_remove_css_class (priv->revealer, "error");
+  }
+
+  gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), TRUE);
+}
+
+
 static void
 kgx_tab_class_init (KgxTabClass *klass)
 {
@@ -524,6 +549,7 @@ kgx_tab_class_init (KgxTabClass *klass)
 
   tab_class->start = kgx_tab_real_start;
   tab_class->start_finish = kgx_tab_real_start_finish;
+  tab_class->died = kgx_tab_real_died;
 
   /**
    * KgxTab:application:
@@ -652,7 +678,8 @@ kgx_tab_class_init (KgxTabClass *klass)
   signals[SIZE_CHANGED] = g_signal_new ("size-changed",
                                         G_TYPE_FROM_CLASS (klass),
                                         G_SIGNAL_RUN_LAST,
-                                        0, NULL, NULL, NULL,
+                                        0, NULL, NULL,
+                                        kgx_marshals_VOID__UINT_UINT,
                                         G_TYPE_NONE,
                                         2,
                                         G_TYPE_UINT,
@@ -661,7 +688,8 @@ kgx_tab_class_init (KgxTabClass *klass)
   signals[ZOOM] = g_signal_new ("zoom",
                                 G_TYPE_FROM_CLASS (klass),
                                 G_SIGNAL_RUN_LAST,
-                                0, NULL, NULL, NULL,
+                                0, NULL, NULL,
+                                kgx_marshals_VOID__ENUM,
                                 G_TYPE_NONE,
                                 1,
                                 KGX_TYPE_ZOOM);
@@ -669,7 +697,9 @@ kgx_tab_class_init (KgxTabClass *klass)
   signals[DIED] = g_signal_new ("died",
                                 G_TYPE_FROM_CLASS (klass),
                                 G_SIGNAL_RUN_LAST,
-                                0, NULL, NULL, NULL,
+                                G_STRUCT_OFFSET (KgxTabClass, died),
+                                NULL, NULL,
+                                kgx_marshals_VOID__ENUM_STRING_BOOLEAN,
                                 G_TYPE_NONE,
                                 3,
                                 GTK_TYPE_MESSAGE_TYPE,
@@ -725,34 +755,6 @@ kgx_tab_buildable_iface_init (GtkBuildableIface *iface)
 }
 
 
-static void
-died (KgxTab         *self,
-      GtkMessageType  type,
-      const char     *message,
-      gboolean        success)
-{
-  KgxTabPrivate *priv;
-
-  g_return_if_fail (KGX_IS_TAB (self));
-
-  priv = kgx_tab_get_instance_private (self);
-
-  gtk_label_set_markup (GTK_LABEL (priv->label), message);
-
-  if (type == GTK_MESSAGE_ERROR) {
-    gtk_widget_add_css_class (priv->revealer, "error");
-  } else {
-    gtk_widget_remove_css_class (priv->revealer, "error");
-  }
-
-  gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), TRUE);
-
-  if (priv->close_on_quit && success) {
-    kgx_pages_remove_page (kgx_tab_get_pages (self), self);
-  }
-}
-
-
 static void
 kgx_tab_init (KgxTab *self)
 {
@@ -773,8 +775,6 @@ kgx_tab_init (KgxTab *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  g_signal_connect (self, "died", G_CALLBACK (died), NULL);
-
   gtk_search_bar_connect_entry (GTK_SEARCH_BAR (priv->search_bar),
                                 GTK_EDITABLE (priv->search_entry));
 
diff --git a/src/kgx-tab.h b/src/kgx-tab.h
index de9a7c3..213442f 100644
--- a/src/kgx-tab.h
+++ b/src/kgx-tab.h
@@ -88,6 +88,11 @@ struct _KgxTabClass
   GPid (*start_finish) (KgxTab               *tab,
                         GAsyncResult         *res,
                         GError              **error);
+
+  void (*died)         (KgxTab               *self,
+                        GtkMessageType        type,
+                        const char           *message,
+                        gboolean              success);
 };
 
 


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