[gnome-builder] libide/tweaks: handle title updates upon navigation.back



commit 33a9bf801a9ba3ef86aad6caac9af89a29d51b76
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 3 16:45:29 2022 -0700

    libide/tweaks: handle title updates upon navigation.back

 src/libide/tweaks/ide-tweaks-window.c  | 35 ++++++++++++++++++++++++----------
 src/libide/tweaks/ide-tweaks-window.ui |  1 +
 2 files changed, 26 insertions(+), 10 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index 7f6242e2d..ae5bb7fff 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -110,8 +110,6 @@ ide_tweaks_window_page_activated_cb (IdeTweaksWindow    *self,
                                      IdeTweaksPage      *page,
                                      IdeTweaksPanelList *list)
 {
-  IdeTweaksPage *ancestor;
-  const char *title;
   const char *name;
   GtkWidget *panel;
   gboolean has_subpages;
@@ -126,13 +124,6 @@ ide_tweaks_window_page_activated_cb (IdeTweaksWindow    *self,
   name = ide_tweaks_item_get_id (IDE_TWEAKS_ITEM (page));
   has_subpages = ide_tweaks_page_get_has_subpage (page);
 
-  if ((ancestor = ide_tweaks_item_get_ancestor (IDE_TWEAKS_ITEM (page), IDE_TYPE_TWEAKS_PAGE)))
-    title = ide_tweaks_page_get_title (ancestor);
-  else
-    title = gtk_window_get_title (GTK_WINDOW (self));
-
-  adw_window_title_set_title (self->sidebar_title, title);
-
   /* Re-use a panel if it is already in the stack. This can happen if
    * we haven't yet reached a notify::transition-running that caused the
    * old page to be discarded.
@@ -281,6 +272,29 @@ panel_list_stack_notify_transition_running_cb (IdeTweaksWindow *self,
     }
 }
 
+static void
+panel_list_stack_notify_visible_child_cb (IdeTweaksWindow *self,
+                                          GParamSpec      *pspec,
+                                          GtkStack        *stack)
+{
+  IdeTweaksPanelList *list;
+  IdeTweaksItem *item;
+  const char *title;
+
+  g_assert (IDE_IS_TWEAKS_WINDOW (self));
+  g_assert (GTK_IS_STACK (stack));
+
+  if (!(list = IDE_TWEAKS_PANEL_LIST (gtk_stack_get_visible_child (stack))))
+    return;
+
+  if ((item = ide_tweaks_panel_list_get_item (list)) && IDE_IS_TWEAKS_PAGE (item))
+    title = ide_tweaks_page_get_title (IDE_TWEAKS_PAGE (item));
+  else
+    title = gtk_window_get_title (GTK_WINDOW (self));
+
+  adw_window_title_set_title (self->sidebar_title, title);
+}
+
 static void
 ide_tweaks_window_navigate_back_action (GtkWidget  *widget,
                                         const char *action_name,
@@ -375,6 +389,7 @@ ide_tweaks_window_class_init (IdeTweaksWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, sidebar_search_bar);
   gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, sidebar_search_entry);
   gtk_widget_class_bind_template_callback (widget_class, panel_list_stack_notify_transition_running_cb);
+  gtk_widget_class_bind_template_callback (widget_class, panel_list_stack_notify_visible_child_cb);
   gtk_widget_class_bind_template_callback (widget_class, panel_stack_notify_transition_running_cb);
 
   gtk_widget_class_install_action (widget_class, "navigation.back", NULL, 
ide_tweaks_window_navigate_back_action);
@@ -521,7 +536,7 @@ ide_tweaks_window_navigate_back (IdeTweaksWindow *self)
         }
     }
 
-  g_warning ("Failed to lcoate parent panel list");
+  g_warning ("Failed to locate parent panel list");
 }
 
 gboolean
diff --git a/src/libide/tweaks/ide-tweaks-window.ui b/src/libide/tweaks/ide-tweaks-window.ui
index 62a7bec49..0c1d1d73b 100644
--- a/src/libide/tweaks/ide-tweaks-window.ui
+++ b/src/libide/tweaks/ide-tweaks-window.ui
@@ -81,6 +81,7 @@
                 <property name="vexpand">true</property>
                 <property name="vhomogeneous">false</property>
                 <property name="width-request">200</property>
+                <signal name="notify::visible-child" handler="panel_list_stack_notify_visible_child_cb" 
swapped="true" object="IdeTweaksWindow"/>
                 <signal name="notify::transition-running" 
handler="panel_list_stack_notify_transition_running_cb" swapped="true" object="IdeTweaksWindow"/>
               </object>
             </child>


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