[gnome-builder/wip/gtk4-port: 713/736] plugins/symbol-tree: setup factory for list item rows




commit 60ff0d0f9ca7f6ce19cc3df81950019c95623f41
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 21 16:34:19 2022 -0700

    plugins/symbol-tree: setup factory for list item rows
    
    We want these to be a tree, and this uses the alternate GtkBuilder file
    for the row contents while only relying on bindings.
    
    We still need an adapter for IdeSymbolNode to GListModel though.

 src/plugins/symbol-tree/gbp-symbol-popover-row.ui | 37 +++++++++++++++++++++++
 src/plugins/symbol-tree/gbp-symbol-popover.c      | 34 +++++++++++++++++++++
 src/plugins/symbol-tree/gbp-symbol-popover.ui     |  8 +++++
 src/plugins/symbol-tree/symbol-tree.gresource.xml |  1 +
 4 files changed, 80 insertions(+)
---
diff --git a/src/plugins/symbol-tree/gbp-symbol-popover-row.ui 
b/src/plugins/symbol-tree/gbp-symbol-popover-row.ui
new file mode 100644
index 000000000..71628f6c7
--- /dev/null
+++ b/src/plugins/symbol-tree/gbp-symbol-popover-row.ui
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtkListItem">
+    <property name="child">
+      <object class="GtkTreeExpander" id="expander">
+        <binding name="list-row">
+          <lookup name="item">GtkListItem</lookup>
+        </binding>
+        <property name="child">
+          <object class="GtkBox">
+            <property name="spacing">6</property>
+            <child>
+              <object class="GtkImage">
+                <binding name="icon-name">
+                  <lookup name="icon-name" type="IdeSymbolNode">
+                    <lookup name="item">expander</lookup>
+                  </lookup>
+                </binding>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="halign">start</property>
+                <binding name="label">
+                  <lookup name="name" type="IdeSymbolNode">
+                    <lookup name="item">expander</lookup>
+                  </lookup>
+                </binding>
+              </object>
+            </child>
+          </object>
+        </property>
+      </object>
+    </property>
+  </template>
+</interface>
+
diff --git a/src/plugins/symbol-tree/gbp-symbol-popover.c b/src/plugins/symbol-tree/gbp-symbol-popover.c
index dfa544886..803bbc199 100644
--- a/src/plugins/symbol-tree/gbp-symbol-popover.c
+++ b/src/plugins/symbol-tree/gbp-symbol-popover.c
@@ -31,6 +31,7 @@ struct _GbpSymbolPopover
   IdeSymbolResolver *symbol_resolver;
 
   GtkSearchEntry    *search_entry;
+  GtkListView       *list_view;
 };
 
 enum {
@@ -43,6 +44,37 @@ G_DEFINE_FINAL_TYPE (GbpSymbolPopover, gbp_symbol_popover, GTK_TYPE_POPOVER)
 
 static GParamSpec *properties [N_PROPS];
 
+static void
+gbp_symbol_popover_activate_cb (GbpSymbolPopover *self,
+                                guint             position,
+                                GtkListView      *list_view)
+{
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_SYMBOL_POPOVER (self));
+  g_assert (GTK_IS_LIST_VIEW (list_view));
+
+  g_debug ("Activating symbol row at position %u", position);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_symbol_popover_reload (GbpSymbolPopover *self)
+{
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_SYMBOL_POPOVER (self));
+
+  if (self->symbol_resolver == NULL)
+    {
+      gtk_list_view_set_model (self->list_view, NULL);
+      IDE_EXIT;
+    }
+
+  IDE_EXIT;
+}
+
 static void
 gbp_symbol_popover_dispose (GObject *object)
 {
@@ -112,6 +144,7 @@ gbp_symbol_popover_class_init (GbpSymbolPopoverClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class, "/plugins/symbol-tree/gbp-symbol-popover.ui");
   gtk_widget_class_bind_template_child (widget_class, GbpSymbolPopover, search_entry);
+  gtk_widget_class_bind_template_callback (widget_class, gbp_symbol_popover_activate_cb);
 }
 
 static void
@@ -145,6 +178,7 @@ gbp_symbol_popover_set_symbol_resolver (GbpSymbolPopover  *self,
 
   if (g_set_object (&self->symbol_resolver, symbol_resolver))
     {
+      gbp_symbol_popover_reload (self);
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SYMBOL_RESOLVER]);
     }
 }
diff --git a/src/plugins/symbol-tree/gbp-symbol-popover.ui b/src/plugins/symbol-tree/gbp-symbol-popover.ui
index abfa2fc15..85963c616 100644
--- a/src/plugins/symbol-tree/gbp-symbol-popover.ui
+++ b/src/plugins/symbol-tree/gbp-symbol-popover.ui
@@ -22,6 +22,14 @@
                 <property name="max-content-width">400</property>
                 <child>
                   <object class="GtkListView" id="list_view">
+                    <signal name="activate" handler="gbp_symbol_popover_activate_cb" swapped="true" 
object="GbpSymbolPopover"/>
+                    <property name="orientation">vertical</property>
+                    <property name="single-click-activate">True</property>
+                    <property name="factory">
+                      <object class="GtkBuilderListItemFactory">
+                        <property name="resource">/plugins/symbol-tree/gbp-symbol-popover-row.ui</property>
+                      </object>
+                    </property>
                   </object>
                 </child>
               </object>
diff --git a/src/plugins/symbol-tree/symbol-tree.gresource.xml 
b/src/plugins/symbol-tree/symbol-tree.gresource.xml
index b633dec05..f13c770b1 100644
--- a/src/plugins/symbol-tree/symbol-tree.gresource.xml
+++ b/src/plugins/symbol-tree/symbol-tree.gresource.xml
@@ -3,5 +3,6 @@
   <gresource prefix="/plugins/symbol-tree">
     <file>symbol-tree.plugin</file>
     <file preprocess="xml-stripblanks">gbp-symbol-popover.ui</file>
+    <file preprocess="xml-stripblanks">gbp-symbol-popover-row.ui</file>
   </gresource>
 </gresources>


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