[gnome-builder] libide/tweaks: add search entry for subpages



commit 5c1b40c46271dc0a39c6f4c0780b3cedc2976402
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 3 14:04:06 2022 -0700

    libide/tweaks: add search entry for subpages
    
    Also ensure we only show that search entry at the right times. Hide the
    sidebar_search_bar when in a subpage.

 src/libide/tweaks/ide-tweaks-panel-list-private.h |  9 +++--
 src/libide/tweaks/ide-tweaks-panel-list-row.ui    |  4 +-
 src/libide/tweaks/ide-tweaks-panel-list.c         | 45 +++++++++++++++++++++--
 src/libide/tweaks/ide-tweaks-panel-list.ui        | 29 +++++++++++----
 src/libide/tweaks/ide-tweaks-window.c             | 21 +++++++----
 5 files changed, 85 insertions(+), 23 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-panel-list-private.h 
b/src/libide/tweaks/ide-tweaks-panel-list-private.h
index 5a4767621..798e5a512 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list-private.h
+++ b/src/libide/tweaks/ide-tweaks-panel-list-private.h
@@ -30,8 +30,11 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeTweaksPanelList, ide_tweaks_panel_list, IDE, TWEAKS_PANEL_LIST, AdwBin)
 
-GtkWidget     *ide_tweaks_panel_list_new          (IdeTweaksItem      *item);
-IdeTweaksItem *ide_tweaks_panel_list_get_item     (IdeTweaksPanelList *self);
-void           ide_tweaks_panel_list_select_first (IdeTweaksPanelList *self);
+GtkWidget     *ide_tweaks_panel_list_new             (IdeTweaksItem      *item);
+IdeTweaksItem *ide_tweaks_panel_list_get_item        (IdeTweaksPanelList *self);
+void           ide_tweaks_panel_list_select_first    (IdeTweaksPanelList *self);
+gboolean       ide_tweaks_panel_list_get_search_mode (IdeTweaksPanelList *self);
+void           ide_tweaks_panel_list_set_search_mode (IdeTweaksPanelList *self,
+                                                      gboolean            search_mode);
 
 G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-panel-list-row.ui b/src/libide/tweaks/ide-tweaks-panel-list-row.ui
index c27fd7705..6bc59e988 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list-row.ui
+++ b/src/libide/tweaks/ide-tweaks-panel-list-row.ui
@@ -4,8 +4,8 @@
     <child>
       <object class="GtkBox">
         <property name="spacing">12</property>
-        <property name="margin-start">12</property>
-        <property name="margin-end">12</property>
+        <property name="margin-start">6</property>
+        <property name="margin-end">6</property>
         <property name="margin-top">12</property>
         <property name="margin-bottom">12</property>
         <child>
diff --git a/src/libide/tweaks/ide-tweaks-panel-list.c b/src/libide/tweaks/ide-tweaks-panel-list.c
index e3f1d7b1a..4d1788ee7 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list.c
+++ b/src/libide/tweaks/ide-tweaks-panel-list.c
@@ -31,16 +31,18 @@
 
 struct _IdeTweaksPanelList
 {
-  AdwBin         parent_instance;
+  AdwBin          parent_instance;
 
-  IdeTweaksItem *item;
+  IdeTweaksItem  *item;
 
-  GtkListBox    *list_box;
+  GtkListBox     *list_box;
+  GtkSearchEntry *search_entry;
 };
 
 enum {
   PROP_0,
   PROP_ITEM,
+  PROP_SEARCH_MODE,
   N_PROPS
 };
 
@@ -180,6 +182,10 @@ ide_tweaks_panel_list_get_property (GObject    *object,
       g_value_set_object (value, ide_tweaks_panel_list_get_item (self));
       break;
 
+    case PROP_SEARCH_MODE:
+      g_value_set_boolean (value, ide_tweaks_panel_list_get_search_mode (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -199,6 +205,10 @@ ide_tweaks_panel_list_set_property (GObject      *object,
       ide_tweaks_panel_list_set_item (self, g_value_get_object (value));
       break;
 
+    case PROP_SEARCH_MODE:
+      ide_tweaks_panel_list_set_search_mode (self, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -219,10 +229,16 @@ ide_tweaks_panel_list_class_init (IdeTweaksPanelListClass *klass)
                          IDE_TYPE_TWEAKS_ITEM,
                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_SEARCH_MODE] =
+    g_param_spec_boolean ("search-mode", NULL, NULL,
+                          FALSE,
+                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
   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-panel-list.ui");
   gtk_widget_class_bind_template_child (widget_class, IdeTweaksPanelList, list_box);
+  gtk_widget_class_bind_template_child (widget_class, IdeTweaksPanelList, search_entry);
   gtk_widget_class_bind_template_callback (widget_class, ide_tweaks_panel_list_row_activated_cb);
 
   signals [PAGE_ACTIVATED] =
@@ -287,3 +303,26 @@ ide_tweaks_panel_list_select_first (IdeTweaksPanelList *self)
         }
     }
 }
+
+gboolean
+ide_tweaks_panel_list_get_search_mode (IdeTweaksPanelList *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_PANEL_LIST (self), FALSE);
+
+  return gtk_widget_get_visible (GTK_WIDGET (self->search_entry));
+}
+
+void
+ide_tweaks_panel_list_set_search_mode (IdeTweaksPanelList *self,
+                                       gboolean            search_mode)
+{
+  g_return_if_fail (IDE_IS_TWEAKS_PANEL_LIST (self));
+
+  search_mode = !!search_mode;
+
+  if (ide_tweaks_panel_list_get_search_mode (self) != search_mode)
+    {
+      gtk_widget_set_visible (GTK_WIDGET (self->search_entry), search_mode);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SEARCH_MODE]);
+    }
+}
diff --git a/src/libide/tweaks/ide-tweaks-panel-list.ui b/src/libide/tweaks/ide-tweaks-panel-list.ui
index ddf1e5837..29098bd64 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list.ui
+++ b/src/libide/tweaks/ide-tweaks-panel-list.ui
@@ -2,14 +2,29 @@
 <interface>
   <template class="IdeTweaksPanelList" parent="AdwBin">
     <child>
-      <object class="GtkScrolledWindow">
-        <property name="hscrollbar-policy">never</property>
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
         <child>
-          <object class="GtkListBox" id="list_box">
-            <signal name="row-activated" handler="ide_tweaks_panel_list_row_activated_cb" swapped="true" 
object="IdeTweaksPanelList"/>
-            <style>
-              <class name="navigation-sidebar"/>
-            </style>
+          <object class="GtkSearchEntry" id="search_entry">
+            <property name="margin-start">12</property>
+            <property name="margin-end">12</property>
+            <property name="margin-top">12</property>
+            <property name="margin-bottom">6</property>
+            <property name="visible">false</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow">
+            <property name="hscrollbar-policy">never</property>
+            <property name="vexpand">true</property>
+            <child>
+              <object class="GtkListBox" id="list_box">
+                <signal name="row-activated" handler="ide_tweaks_panel_list_row_activated_cb" swapped="true" 
object="IdeTweaksPanelList"/>
+                <style>
+                  <class name="navigation-sidebar"/>
+                </style>
+              </object>
+            </child>
           </object>
         </child>
       </object>
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index bdcdab395..411a48962 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -30,14 +30,16 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GtkStackPage, g_object_unref)
 
 struct _IdeTweaksWindow
 {
-  AdwWindow  parent_instance;
+  AdwWindow       parent_instance;
 
-  IdeTweaks *tweaks;
+  IdeTweaks      *tweaks;
 
-  GtkStack  *panel_stack;
-  GtkStack  *panel_list_stack;
+  GtkStack       *panel_stack;
+  GtkStack       *panel_list_stack;
+  GtkSearchBar   *sidebar_search_bar;
+  GtkSearchEntry *sidebar_search_entry;
 
-  guint      can_navigate_back : 1;
+  guint           can_navigate_back : 1;
 };
 
 enum {
@@ -138,12 +140,12 @@ ide_tweaks_window_page_activated_cb (IdeTweaksWindow    *self,
 
       gtk_stack_set_visible_child (self->panel_stack, panel);
     }
-
-  /* If the page has subpages, then should show that list too */
-  if (has_subpages)
+  else
     {
       GtkWidget *sublist;
 
+      gtk_search_bar_set_search_mode (self->sidebar_search_bar, FALSE);
+
       sublist = ide_tweaks_panel_list_new (IDE_TWEAKS_ITEM (page));
       g_signal_connect_object (sublist,
                                "page-activated",
@@ -154,6 +156,7 @@ ide_tweaks_window_page_activated_cb (IdeTweaksWindow    *self,
                            sublist,
                            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);
@@ -358,6 +361,8 @@ 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_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_stack_notify_transition_running_cb);
 


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