[gnome-builder] libide/tweaks: update sidebar title based on current page



commit 86055785999f7797ae5fb46fc9452b86efe50894
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 3 16:28:29 2022 -0700

    libide/tweaks: update sidebar title based on current page

 src/libide/tweaks/ide-tweaks-window.c  | 11 +++++++++++
 src/libide/tweaks/ide-tweaks-window.ui |  5 ++---
 2 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index 411a48962..7f6242e2d 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -36,6 +36,7 @@ struct _IdeTweaksWindow
 
   GtkStack       *panel_stack;
   GtkStack       *panel_list_stack;
+  AdwWindowTitle *sidebar_title;
   GtkSearchBar   *sidebar_search_bar;
   GtkSearchEntry *sidebar_search_entry;
 
@@ -109,6 +110,8 @@ 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;
@@ -123,6 +126,13 @@ 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.
@@ -361,6 +371,7 @@ ide_tweaks_window_class_init (IdeTweaksWindowClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/libide-tweaks/ide-tweaks-window.ui");
   gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_stack);
   gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_list_stack);
+  gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, sidebar_title);
   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);
diff --git a/src/libide/tweaks/ide-tweaks-window.ui b/src/libide/tweaks/ide-tweaks-window.ui
index 12500ba74..62a7bec49 100644
--- a/src/libide/tweaks/ide-tweaks-window.ui
+++ b/src/libide/tweaks/ide-tweaks-window.ui
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <template class="IdeTweaksWindow" parent="AdwWindow">
+    <property name="title" translatable="yes">Preferences</property>
     <property name="default-width">1080</property>
     <property name="default-height">720</property>
     <child>
@@ -20,9 +21,7 @@
                 <property name="show-start-title-buttons">true</property>
                 <property name="show-end-title-buttons" bind-source="leaflet" bind-property="folded" 
bind-flags="sync-create"/>
                 <property name="title-widget">
-                  <object class="AdwWindowTitle" id="sidebar_title">
-                    <property name="title" translatable="yes">Preferences</property>
-                  </object>
+                  <object class="AdwWindowTitle" id="sidebar_title"/>
                 </property>
                 <child>
                   <object class="GtkButton" id="sidebar_previous_button">


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