[gnome-builder] libide/tweaks: implement fold navigation



commit 70c891db76fb864e11767933e16d1c595b577380
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 4 09:53:15 2022 -0700

    libide/tweaks: implement fold navigation

 src/libide/tweaks/ide-tweaks-panel.ui  |  3 +-
 src/libide/tweaks/ide-tweaks-window.c  | 82 ++++++++++++++++++++++++----------
 src/libide/tweaks/ide-tweaks-window.ui |  4 +-
 3 files changed, 62 insertions(+), 27 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-panel.ui b/src/libide/tweaks/ide-tweaks-panel.ui
index 993c2aba2..0cb50a036 100644
--- a/src/libide/tweaks/ide-tweaks-panel.ui
+++ b/src/libide/tweaks/ide-tweaks-panel.ui
@@ -17,8 +17,7 @@
                   <object class="GtkButton">
                     <property name="visible" bind-source="IdeTweaksPanel" bind-property="folded" 
bind-flags="sync-create"/>
                     <property name="icon-name">go-previous-symbolic</property>
-                    <property name="action-name">window.navigate</property>
-                    <property name="action-target">0</property>
+                    <property name="action-name">navigation.back</property>
                   </object>
                 </child>
                 <property name="title-widget">
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index 749753c63..c6879451b 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -34,8 +34,11 @@ struct _IdeTweaksWindow
 
   IdeTweaks      *tweaks;
 
+  AdwLeaflet     *leaflet;
+  GtkBox         *panel_box;
   GtkStack       *panel_stack;
   GtkStack       *panel_list_stack;
+  GtkBox         *panel_list_box;
   AdwWindowTitle *sidebar_title;
   GtkSearchBar   *sidebar_search_bar;
   GtkSearchEntry *sidebar_search_entry;
@@ -70,15 +73,23 @@ ide_tweaks_window_get_current_page (IdeTweaksWindow *self)
   return NULL;
 }
 
+static IdeTweaksPanelList *
+ide_tweaks_window_get_current_list (IdeTweaksWindow *self)
+{
+  g_assert (IDE_IS_TWEAKS_WINDOW (self));
+
+  return IDE_TWEAKS_PANEL_LIST (gtk_stack_get_visible_child (self->panel_list_stack));
+}
+
 static IdeTweaksItem *
 ide_tweaks_window_get_current_list_item (IdeTweaksWindow *self)
 {
-  GtkWidget *visible_child;
+  IdeTweaksPanelList *list;
 
   g_assert (IDE_IS_TWEAKS_WINDOW (self));
 
-  if ((visible_child = gtk_stack_get_visible_child (self->panel_list_stack)))
-    return ide_tweaks_panel_list_get_item (IDE_TWEAKS_PANEL_LIST (visible_child));
+  if ((list = ide_tweaks_window_get_current_list (self)))
+    return ide_tweaks_panel_list_get_item (list);
 
   return NULL;
 }
@@ -86,16 +97,22 @@ ide_tweaks_window_get_current_list_item (IdeTweaksWindow *self)
 static void
 ide_tweaks_window_update_actions (IdeTweaksWindow *self)
 {
+  IdeTweaksPanelList *list;
   GtkWidget *visible_child;
   gboolean can_navigate_back = FALSE;
 
   g_assert (IDE_IS_TWEAKS_WINDOW (self));
 
-  if ((visible_child = gtk_stack_get_visible_child (self->panel_list_stack)))
+  visible_child = adw_leaflet_get_visible_child (self->leaflet);
+  list = ide_tweaks_window_get_current_list (self);
+
+  if (visible_child == GTK_WIDGET (self->panel_box) && self->folded)
+    {
+      can_navigate_back = TRUE;
+    }
+  else if (list != NULL)
     {
-      IdeTweaksPanelList *list = IDE_TWEAKS_PANEL_LIST (visible_child);
       IdeTweaksItem *item = ide_tweaks_panel_list_get_item (list);
-
       can_navigate_back = !IDE_IS_TWEAKS (item);
     }
 
@@ -138,10 +155,12 @@ ide_tweaks_window_page_activated_cb (IdeTweaksWindow    *self,
       if (!(panel = gtk_stack_get_child_by_name (self->panel_stack, name)))
         {
           panel = ide_tweaks_panel_new (page);
+          ide_tweaks_panel_set_folded (IDE_TWEAKS_PANEL (panel), self->folded);
           gtk_stack_add_named (self->panel_stack, panel, name);
         }
 
       gtk_stack_set_visible_child (self->panel_stack, panel);
+      adw_leaflet_navigate (self->leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
     }
   else
     {
@@ -160,10 +179,12 @@ ide_tweaks_window_page_activated_cb (IdeTweaksWindow    *self,
                            ide_tweaks_item_get_id (IDE_TWEAKS_ITEM (page)));
       gtk_stack_set_visible_child (self->panel_list_stack, sublist);
       ide_tweaks_panel_list_set_search_mode (IDE_TWEAKS_PANEL_LIST (sublist), TRUE);
-      ide_tweaks_panel_list_select_first (IDE_TWEAKS_PANEL_LIST (sublist));
 
-      ide_tweaks_window_update_actions (self);
+      if (!self->folded)
+        ide_tweaks_panel_list_select_first (IDE_TWEAKS_PANEL_LIST (sublist));
     }
+
+  ide_tweaks_window_update_actions (self);
 }
 
 static void
@@ -179,6 +200,8 @@ ide_tweaks_window_clear (IdeTweaksWindow *self)
 
   while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->panel_stack))))
     gtk_stack_remove (self->panel_stack, child);
+
+  ide_tweaks_window_update_actions (self);
 }
 
 static void
@@ -198,7 +221,9 @@ ide_tweaks_window_rebuild (IdeTweaksWindow *self)
   gtk_stack_add_named (self->panel_list_stack,
                        list,
                        ide_tweaks_item_get_id (IDE_TWEAKS_ITEM (self->tweaks)));
-  ide_tweaks_panel_list_select_first (IDE_TWEAKS_PANEL_LIST (list));
+
+  if (!self->folded)
+    ide_tweaks_panel_list_select_first (IDE_TWEAKS_PANEL_LIST (list));
 
   ide_tweaks_window_update_actions (self);
 }
@@ -295,6 +320,8 @@ panel_list_stack_notify_visible_child_cb (IdeTweaksWindow *self,
     title = gtk_window_get_title (GTK_WINDOW (self));
 
   adw_window_title_set_title (self->sidebar_title, title);
+
+  ide_tweaks_window_update_actions (self);
 }
 
 static void
@@ -328,6 +355,8 @@ ide_tweaks_window_set_folded (IdeTweaksWindow *self,
       if ((child = gtk_stack_get_visible_child (self->panel_list_stack)))
         ide_tweaks_panel_list_set_selection_mode (IDE_TWEAKS_PANEL_LIST (child), selection_mode);
 
+      ide_tweaks_window_update_actions (self);
+
       g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FOLDED]);
     }
 }
@@ -424,11 +453,14 @@ ide_tweaks_window_class_init (IdeTweaksWindowClass *klass)
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
   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, leaflet);
+  gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_box);
+  gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_list_box);
   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, panel_stack);
   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_child (widget_class, IdeTweaksWindow, sidebar_title);
   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);
@@ -556,28 +588,32 @@ void
 ide_tweaks_window_navigate_back (IdeTweaksWindow *self)
 {
   IdeTweaksPanelList *list;
-  IdeTweaksItem *item;
   GtkWidget *visible_child;
 
   g_return_if_fail (IDE_IS_TWEAKS_WINDOW (self));
 
-  if (!(visible_child = gtk_stack_get_visible_child (self->panel_list_stack)))
-    g_return_if_reached ();
+  visible_child = adw_leaflet_get_visible_child (self->leaflet);
+  list = ide_tweaks_window_get_current_list (self);
 
-  list = IDE_TWEAKS_PANEL_LIST (visible_child);
-  item = ide_tweaks_panel_list_get_item (list);
-
-  while ((item = ide_tweaks_item_get_parent (item)))
+  if (visible_child == GTK_WIDGET (self->panel_box) && self->folded)
+    {
+      adw_leaflet_navigate (self->leaflet, ADW_NAVIGATION_DIRECTION_BACK);
+    }
+  else if (list != NULL)
     {
-      if ((list = ide_tweaks_window_find_list_for_item (self, item)))
+      IdeTweaksItem *item = ide_tweaks_panel_list_get_item (list);
+
+      while ((item = ide_tweaks_item_get_parent (item)))
         {
-          gtk_stack_set_visible_child (self->panel_list_stack, GTK_WIDGET (list));
-          ide_tweaks_window_update_actions (self);
-          return;
+          if ((list = ide_tweaks_window_find_list_for_item (self, item)))
+            {
+              gtk_stack_set_visible_child (self->panel_list_stack, GTK_WIDGET (list));
+              break;
+            }
         }
     }
 
-  g_warning ("Failed to locate parent panel list");
+  ide_tweaks_window_update_actions (self);
 }
 
 gboolean
diff --git a/src/libide/tweaks/ide-tweaks-window.ui b/src/libide/tweaks/ide-tweaks-window.ui
index 4bea7235e..da727fe64 100644
--- a/src/libide/tweaks/ide-tweaks-window.ui
+++ b/src/libide/tweaks/ide-tweaks-window.ui
@@ -14,7 +14,7 @@
         <property name="mode-transition-duration">250</property>
         <property name="transition-type">over</property>
         <child>
-          <object class="GtkBox" id="sidebar_box">
+          <object class="GtkBox" id="panel_list_box">
             <property name="orientation">vertical</property>
             <property name="hexpand">false</property>
             <child>
@@ -102,7 +102,7 @@
           </object>
         </child>
         <child>
-          <object class="GtkBox" id="page_box">
+          <object class="GtkBox" id="panel_box">
             <property name="orientation">vertical</property>
             <property name="hexpand">true</property>
             <property name="vexpand">true</property>


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