[gnome-builder/wip/gtk4-port: 711/736] plugins/symbol-tree: stub popover for symbol tree




commit aee41e2dce4d329a8b72f8771fddecac804f8220
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 21 15:48:03 2022 -0700

    plugins/symbol-tree: stub popover for symbol tree
    
    This will need an adapter still for converting IdeSymbolTree+IdeSymbolNode
    into a GListModel (of GListModel) for use with GtkListView.

 src/plugins/symbol-tree/gbp-symbol-popover.c       | 150 +++++++++++++++++++++
 src/plugins/symbol-tree/gbp-symbol-popover.h       |  38 ++++++
 src/plugins/symbol-tree/gbp-symbol-popover.ui      |  34 +++++
 .../symbol-tree/gbp-symbol-workspace-addin.c       |   3 +
 src/plugins/symbol-tree/meson.build                |   1 +
 src/plugins/symbol-tree/symbol-tree.gresource.xml  |   1 +
 6 files changed, 227 insertions(+)
---
diff --git a/src/plugins/symbol-tree/gbp-symbol-popover.c b/src/plugins/symbol-tree/gbp-symbol-popover.c
new file mode 100644
index 000000000..dfa544886
--- /dev/null
+++ b/src/plugins/symbol-tree/gbp-symbol-popover.c
@@ -0,0 +1,150 @@
+/* gbp-symbol-popover.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-symbol-popover"
+
+#include "config.h"
+
+#include "gbp-symbol-popover.h"
+
+struct _GbpSymbolPopover
+{
+  GtkPopover         parent_instance;
+
+  IdeSymbolResolver *symbol_resolver;
+
+  GtkSearchEntry    *search_entry;
+};
+
+enum {
+  PROP_0,
+  PROP_SYMBOL_RESOLVER,
+  N_PROPS
+};
+
+G_DEFINE_FINAL_TYPE (GbpSymbolPopover, gbp_symbol_popover, GTK_TYPE_POPOVER)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+gbp_symbol_popover_dispose (GObject *object)
+{
+  GbpSymbolPopover *self = (GbpSymbolPopover *)object;
+
+  g_clear_object (&self->symbol_resolver);
+
+  G_OBJECT_CLASS (gbp_symbol_popover_parent_class)->dispose (object);
+}
+
+static void
+gbp_symbol_popover_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  GbpSymbolPopover *self = GBP_SYMBOL_POPOVER (object);
+
+  switch (prop_id)
+    {
+    case PROP_SYMBOL_RESOLVER:
+      g_value_set_object (value, gbp_symbol_popover_get_symbol_resolver (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_symbol_popover_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  GbpSymbolPopover *self = GBP_SYMBOL_POPOVER (object);
+
+  switch (prop_id)
+    {
+    case PROP_SYMBOL_RESOLVER:
+      gbp_symbol_popover_set_symbol_resolver (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_symbol_popover_class_init (GbpSymbolPopoverClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = gbp_symbol_popover_dispose;
+  object_class->get_property = gbp_symbol_popover_get_property;
+  object_class->set_property = gbp_symbol_popover_set_property;
+
+  properties [PROP_SYMBOL_RESOLVER] =
+    g_param_spec_object ("symbol-resolver",
+                         "Symbol Resolver",
+                         "The symbol resolver to build a tree from",
+                         IDE_TYPE_SYMBOL_RESOLVER,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  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);
+}
+
+static void
+gbp_symbol_popover_init (GbpSymbolPopover *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GtkWidget *
+gbp_symbol_popover_new (void)
+{
+  return g_object_new (GBP_TYPE_SYMBOL_POPOVER, NULL);
+}
+
+IdeSymbolResolver *
+gbp_symbol_popover_get_symbol_resolver (GbpSymbolPopover *self)
+{
+  g_return_val_if_fail (GBP_IS_SYMBOL_POPOVER (self), NULL);
+  g_return_val_if_fail (!self->symbol_resolver ||
+                        IDE_IS_SYMBOL_RESOLVER (self->symbol_resolver), NULL);
+
+  return self->symbol_resolver;
+}
+
+void
+gbp_symbol_popover_set_symbol_resolver (GbpSymbolPopover  *self,
+                                        IdeSymbolResolver *symbol_resolver)
+{
+  g_return_if_fail (GBP_IS_SYMBOL_POPOVER (self));
+  g_return_if_fail (!symbol_resolver || IDE_IS_SYMBOL_RESOLVER (symbol_resolver));
+
+  if (g_set_object (&self->symbol_resolver, symbol_resolver))
+    {
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SYMBOL_RESOLVER]);
+    }
+}
diff --git a/src/plugins/symbol-tree/gbp-symbol-popover.h b/src/plugins/symbol-tree/gbp-symbol-popover.h
new file mode 100644
index 000000000..0a3f3f4dc
--- /dev/null
+++ b/src/plugins/symbol-tree/gbp-symbol-popover.h
@@ -0,0 +1,38 @@
+/* gbp-symbol-popover.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include <libide-code.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_SYMBOL_POPOVER (gbp_symbol_popover_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpSymbolPopover, gbp_symbol_popover, GBP, SYMBOL_POPOVER, GtkPopover)
+
+GtkWidget         *gbp_symbol_popover_new                 (void);
+IdeSymbolResolver *gbp_symbol_popover_get_symbol_resolver (GbpSymbolPopover  *self);
+void               gbp_symbol_popover_set_symbol_resolver (GbpSymbolPopover  *self,
+                                                           IdeSymbolResolver *symbol_resolver);
+
+G_END_DECLS
diff --git a/src/plugins/symbol-tree/gbp-symbol-popover.ui b/src/plugins/symbol-tree/gbp-symbol-popover.ui
new file mode 100644
index 000000000..abfa2fc15
--- /dev/null
+++ b/src/plugins/symbol-tree/gbp-symbol-popover.ui
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GbpSymbolPopover" parent="GtkPopover">
+    <property name="width-request">300</property>
+    <child>
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkSearchEntry" id="search_entry">
+          </object>
+        </child>
+        <child>
+          <object class="GtkFrame">
+            <child>
+              <object class="GtkScrolledWindow" id="scroller">
+                <property name="propagate-natural-height">true</property>
+                <property name="propagate-natural-width">true</property>
+                <property name="min-content-height">100</property>
+                <property name="max-content-height">600</property>
+                <property name="min-content-width">300</property>
+                <property name="max-content-width">400</property>
+                <child>
+                  <object class="GtkListView" id="list_view">
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/plugins/symbol-tree/gbp-symbol-workspace-addin.c 
b/src/plugins/symbol-tree/gbp-symbol-workspace-addin.c
index dca47d2f8..d8a1b001c 100644
--- a/src/plugins/symbol-tree/gbp-symbol-workspace-addin.c
+++ b/src/plugins/symbol-tree/gbp-symbol-workspace-addin.c
@@ -28,6 +28,7 @@
 #include <libide-editor.h>
 #include <libide-gui.h>
 
+#include "gbp-symbol-popover.h"
 #include "gbp-symbol-workspace-addin.h"
 #include "gbp-symbol-util.h"
 
@@ -233,6 +234,8 @@ gbp_symbol_workspace_addin_load (IdeWorkspaceAddin *addin,
   gtk_box_append (box, GTK_WIDGET (self->menu_label));
   self->menu_button = g_object_new (GTK_TYPE_MENU_BUTTON,
                                     "child", box,
+                                    "direction", GTK_ARROW_UP,
+                                    "popover", gbp_symbol_popover_new (),
                                     "visible", FALSE,
                                     NULL);
 
diff --git a/src/plugins/symbol-tree/meson.build b/src/plugins/symbol-tree/meson.build
index 9e6d6819d..54fed0533 100644
--- a/src/plugins/symbol-tree/meson.build
+++ b/src/plugins/symbol-tree/meson.build
@@ -1,5 +1,6 @@
 plugins_sources += files([
   'gbp-symbol-hover-provider.c',
+  'gbp-symbol-popover.c',
   'gbp-symbol-util.c',
   'gbp-symbol-workspace-addin.c',
   'symbol-tree-plugin.c',
diff --git a/src/plugins/symbol-tree/symbol-tree.gresource.xml 
b/src/plugins/symbol-tree/symbol-tree.gresource.xml
index f2c33673c..b633dec05 100644
--- a/src/plugins/symbol-tree/symbol-tree.gresource.xml
+++ b/src/plugins/symbol-tree/symbol-tree.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/plugins/symbol-tree">
     <file>symbol-tree.plugin</file>
+    <file preprocess="xml-stripblanks">gbp-symbol-popover.ui</file>
   </gresource>
 </gresources>


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