[gnome-builder] symbol-tree: start porting symbol tree to new design



commit 6b949340962df042fafe1799a92c30846354bda0
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 30 02:54:47 2017 -0700

    symbol-tree: start porting symbol tree to new design
    
    This moves the symbol tree into the stack header and simplifies that
    code a bit. We still have more to do such as:
    
     - Track the cursor position and update the header label
     - Track changes to the buffer and reload the symbol tree
     - Possibly add a quick search/filter to the tree

 data/themes/shared/shared-layout.css               |    9 -
 .../symbol-tree/gbp-symbol-layout-stack-addin.c    |  173 ++++++++
 ...ree-panel.h => gbp-symbol-layout-stack-addin.h} |   15 +-
 plugins/symbol-tree/gbp-symbol-menu-button.c       |  175 ++++++++
 .../{symbol-tree.h => gbp-symbol-menu-button.h}    |   18 +-
 plugins/symbol-tree/gbp-symbol-menu-button.ui      |   30 ++
 plugins/symbol-tree/gbp-symbol-tree-builder.c      |  164 ++++++++
 .../{symbol-tree.h => gbp-symbol-tree-builder.h}   |   12 +-
 plugins/symbol-tree/meson.build                    |   21 +-
 plugins/symbol-tree/symbol-tree-builder.h          |    5 +-
 plugins/symbol-tree/symbol-tree-panel.c            |  439 --------------------
 plugins/symbol-tree/symbol-tree-panel.ui           |   56 ---
 .../{symbol-tree.h => symbol-tree-plugin.c}        |   25 +-
 plugins/symbol-tree/symbol-tree.c                  |  196 ---------
 plugins/symbol-tree/symbol-tree.gresource.xml      |    4 +-
 plugins/symbol-tree/symbol-tree.plugin             |    2 +-
 plugins/symbol-tree/themes/shared.css              |   14 +-
 17 files changed, 596 insertions(+), 762 deletions(-)
---
diff --git a/data/themes/shared/shared-layout.css b/data/themes/shared/shared-layout.css
index 9359f7c..b08dba6 100644
--- a/data/themes/shared/shared-layout.css
+++ b/data/themes/shared/shared-layout.css
@@ -50,15 +50,6 @@ idelayoutgrid.handle {
   border: 1px solid @borders;
 }
 
-popover.symbols-button {
-  padding: 12px;
-}
-
-popover.symbols-button treeview {
-  background: transparent;
-  color: @theme_text_color;
-}
-
 popover.title-popover scrolledwindow {
   min-width: 300px;
 }
diff --git a/plugins/symbol-tree/gbp-symbol-layout-stack-addin.c 
b/plugins/symbol-tree/gbp-symbol-layout-stack-addin.c
new file mode 100644
index 0000000..9e022af
--- /dev/null
+++ b/plugins/symbol-tree/gbp-symbol-layout-stack-addin.c
@@ -0,0 +1,173 @@
+/* gbp-symbol-layout-stack-addin.c
+ *
+ * Copyright (C) 2017 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-symbol-layout-stack-addin"
+
+#include "gbp-symbol-layout-stack-addin.h"
+#include "gbp-symbol-menu-button.h"
+
+struct _GbpSymbolLayoutStackAddin {
+  GObject              parent_instance;
+  GbpSymbolMenuButton *button;
+  GCancellable        *cancellable;
+};
+
+static void
+gbp_symbol_layout_stack_addin_load (IdeLayoutStackAddin *addin,
+                                    IdeLayoutStack      *stack)
+{
+  GbpSymbolLayoutStackAddin *self = (GbpSymbolLayoutStackAddin *)addin;
+  GtkWidget *header;
+
+  g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
+  g_assert (IDE_IS_LAYOUT_STACK (stack));
+
+  header = ide_layout_stack_get_titlebar (stack);
+  self->button = g_object_new (GBP_TYPE_SYMBOL_MENU_BUTTON, NULL);
+  g_signal_connect (self->button,
+                    "destroy",
+                    G_CALLBACK (gtk_widget_destroyed),
+                    &self->button);
+  ide_layout_stack_header_add_custom_title (IDE_LAYOUT_STACK_HEADER (header),
+                                            GTK_WIDGET (self->button),
+                                            100);
+}
+
+static void
+gbp_symbol_layout_stack_addin_unload (IdeLayoutStackAddin *addin,
+                                      IdeLayoutStack      *stack)
+{
+  GbpSymbolLayoutStackAddin *self = (GbpSymbolLayoutStackAddin *)addin;
+
+  g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
+  g_assert (IDE_IS_LAYOUT_STACK (stack));
+
+  g_cancellable_cancel (self->cancellable);
+  g_clear_object (&self->cancellable);
+
+  if (self->button != NULL)
+    gtk_widget_destroy (GTK_WIDGET (self->button));
+}
+
+static void
+gbp_symbol_layout_stack_addin_get_symbol_tree_cb (GObject      *object,
+                                                  GAsyncResult *result,
+                                                  gpointer      user_data)
+{
+  IdeSymbolResolver *symbol_resolver = (IdeSymbolResolver *)object;
+  g_autoptr(GbpSymbolLayoutStackAddin) self = user_data;
+  g_autoptr(IdeSymbolTree) tree = NULL;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (G_IS_ASYNC_RESULT (result));
+
+  tree = ide_symbol_resolver_get_symbol_tree_finish (symbol_resolver, result, &error);
+
+  if (error != NULL &&
+      !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
+      !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
+    g_warning ("%s", error->message);
+
+  /* If we were destroyed, short-circuit */
+  if (self->button == NULL)
+    return;
+
+  if (tree == NULL)
+    {
+      gtk_widget_hide (GTK_WIDGET (self->button));
+      return;
+    }
+
+  gbp_symbol_menu_button_set_symbol_tree (self->button, tree);
+}
+
+static void
+gbp_symbol_layout_stack_addin_set_view (IdeLayoutStackAddin *addin,
+                                        IdeLayoutView       *view)
+{
+  GbpSymbolLayoutStackAddin *self = (GbpSymbolLayoutStackAddin *)addin;
+  IdeSymbolResolver *symbol_resolver;
+  IdeBuffer *buffer;
+  IdeFile *file;
+
+  g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
+  g_assert (!view || IDE_IS_LAYOUT_VIEW (view));
+
+  g_cancellable_cancel (self->cancellable);
+  g_clear_object (&self->cancellable);
+
+  gbp_symbol_menu_button_set_symbol_tree (self->button, NULL);
+
+  if (!IDE_IS_EDITOR_VIEW (view))
+    {
+      gtk_widget_hide (GTK_WIDGET (self->button));
+      return;
+    }
+
+  buffer = ide_editor_view_get_buffer (IDE_EDITOR_VIEW (view));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  symbol_resolver = ide_buffer_get_symbol_resolver (buffer);
+  g_assert (!symbol_resolver || IDE_IS_SYMBOL_RESOLVER (symbol_resolver));
+
+  if (symbol_resolver == NULL)
+    {
+      gtk_widget_hide (GTK_WIDGET (self->button));
+      return;
+    }
+
+  file = ide_buffer_get_file (buffer);
+  g_assert (IDE_IS_FILE (file));
+
+  self->cancellable = g_cancellable_new ();
+
+  ide_symbol_resolver_get_symbol_tree_async (symbol_resolver,
+                                             ide_file_get_file (file),
+                                             buffer,
+                                             self->cancellable,
+                                             gbp_symbol_layout_stack_addin_get_symbol_tree_cb,
+                                             g_object_ref (self));
+
+  gtk_widget_show (GTK_WIDGET (self->button));
+}
+
+static void
+layout_stack_addin_iface_init (IdeLayoutStackAddinInterface *iface)
+{
+  iface->load = gbp_symbol_layout_stack_addin_load;
+  iface->unload = gbp_symbol_layout_stack_addin_unload;
+  iface->set_view = gbp_symbol_layout_stack_addin_set_view;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpSymbolLayoutStackAddin,
+                         gbp_symbol_layout_stack_addin,
+                         G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_LAYOUT_STACK_ADDIN,
+                                                layout_stack_addin_iface_init))
+
+static void
+gbp_symbol_layout_stack_addin_class_init (GbpSymbolLayoutStackAddinClass *klass)
+{
+}
+
+static void
+gbp_symbol_layout_stack_addin_init (GbpSymbolLayoutStackAddin *self)
+{
+}
diff --git a/plugins/symbol-tree/symbol-tree-panel.h b/plugins/symbol-tree/gbp-symbol-layout-stack-addin.h
similarity index 64%
rename from plugins/symbol-tree/symbol-tree-panel.h
rename to plugins/symbol-tree/gbp-symbol-layout-stack-addin.h
index a883f60..3d68bd7 100644
--- a/plugins/symbol-tree/symbol-tree-panel.h
+++ b/plugins/symbol-tree/gbp-symbol-layout-stack-addin.h
@@ -1,6 +1,6 @@
-/* symbol-tree-panel.h
+/* gbp-symbol-layout-stack-addin.h
  *
- * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ * Copyright (C) 2017 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
@@ -16,19 +16,14 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SYMBOL_TREE_PANEL_H
-#define SYMBOL_TREE_PANEL_H
+#pragma once
 
 #include <ide.h>
 
 G_BEGIN_DECLS
 
-#define SYMBOL_TYPE_TREE_PANEL (symbol_tree_panel_get_type())
+#define GBP_TYPE_SYMBOL_LAYOUT_STACK_ADDIN (gbp_symbol_layout_stack_addin_get_type())
 
-G_DECLARE_FINAL_TYPE (SymbolTreePanel, symbol_tree_panel, SYMBOL, TREE_PANEL, DzlDockWidget)
-
-void symbol_tree_panel_reset (SymbolTreePanel *self);
+G_DECLARE_FINAL_TYPE (GbpSymbolLayoutStackAddin, gbp_symbol_layout_stack_addin, GBP, 
SYMBOL_LAYOUT_STACK_ADDIN, GObject)
 
 G_END_DECLS
-
-#endif /* SYMBOL_TREE_PANEL_H */
diff --git a/plugins/symbol-tree/gbp-symbol-menu-button.c b/plugins/symbol-tree/gbp-symbol-menu-button.c
new file mode 100644
index 0000000..6879a21
--- /dev/null
+++ b/plugins/symbol-tree/gbp-symbol-menu-button.c
@@ -0,0 +1,175 @@
+/* gbp-symbol-menu-button.c
+ *
+ * Copyright (C) 2017 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-symbol-menu-button.h"
+
+#include "gbp-symbol-menu-button.h"
+#include "gbp-symbol-tree-builder.h"
+
+struct _GbpSymbolMenuButton
+{
+  GtkMenuButton  parent_instance;
+
+  /* Owned references */
+  IdeSymbolTree  *symbol_tree;
+
+  /* Template references */
+  DzlTree        *tree;
+  DzlTreeBuilder *tree_builder;
+  GtkWidget      *popover;
+};
+
+enum {
+  PROP_0,
+  PROP_SYMBOL_TREE,
+  N_PROPS
+};
+
+G_DEFINE_TYPE (GbpSymbolMenuButton, gbp_symbol_menu_button, GTK_TYPE_MENU_BUTTON)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+gbp_symbol_menu_button_destroy (GtkWidget *widget)
+{
+  GbpSymbolMenuButton *self = (GbpSymbolMenuButton *)widget;
+
+  if (self->tree != NULL)
+    dzl_tree_set_root (self->tree, NULL);
+
+  g_clear_object (&self->symbol_tree);
+
+  GTK_WIDGET_CLASS (gbp_symbol_menu_button_parent_class)->destroy (widget);
+}
+
+static void
+gbp_symbol_menu_button_get_property (GObject    *object,
+                                     guint       prop_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec)
+{
+  GbpSymbolMenuButton *self = GBP_SYMBOL_MENU_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_SYMBOL_TREE:
+      g_value_set_object (value, gbp_symbol_menu_button_get_symbol_tree (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_symbol_menu_button_set_property (GObject      *object,
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
+{
+  GbpSymbolMenuButton *self = GBP_SYMBOL_MENU_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_SYMBOL_TREE:
+      gbp_symbol_menu_button_set_symbol_tree (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_symbol_menu_button_class_init (GbpSymbolMenuButtonClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->get_property = gbp_symbol_menu_button_get_property;
+  object_class->set_property = gbp_symbol_menu_button_set_property;
+
+  widget_class->destroy = gbp_symbol_menu_button_destroy;
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/plugins/symbol-tree-plugin/gbp-symbol-menu-button.ui");
+  gtk_widget_class_bind_template_child (widget_class, GbpSymbolMenuButton, popover);
+  gtk_widget_class_bind_template_child (widget_class, GbpSymbolMenuButton, tree);
+  gtk_widget_class_bind_template_child (widget_class, GbpSymbolMenuButton, tree_builder);
+
+  properties [PROP_SYMBOL_TREE] =
+    g_param_spec_object ("symbol-tree",
+                         "Symbol Tree",
+                         "The symbol tree to be visualized",
+                         IDE_TYPE_SYMBOL_TREE,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  g_type_ensure (GBP_TYPE_SYMBOL_TREE_BUILDER);
+}
+
+static void
+gbp_symbol_menu_button_init (GbpSymbolMenuButton *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+/**
+ * gbp_symbol_menu_button_get_symbol_tree:
+ * @self: a #GbpSymbolMenuButton
+ *
+ * Gets the #IdeSymbolTree displayed by the popover.
+ *
+ * Returns: (transfer none) (nullable): An #IdeSymbolTree or %NULL
+ *
+ * Since: 3.26
+ */
+IdeSymbolTree *
+gbp_symbol_menu_button_get_symbol_tree (GbpSymbolMenuButton *self)
+{
+  g_return_val_if_fail (GBP_IS_SYMBOL_MENU_BUTTON (self), NULL);
+
+  return self->symbol_tree;
+}
+
+/**
+ * gbp_symbol_menu_button_set_symbol_tree:
+ * @self: a #GbpSymbolMenuButton
+ *
+ * Sets the symbol tree to be displayed by the popover.
+ *
+ * Since: 3.26
+ */
+void
+gbp_symbol_menu_button_set_symbol_tree (GbpSymbolMenuButton *self,
+                                        IdeSymbolTree       *symbol_tree)
+{
+  g_return_if_fail (GBP_IS_SYMBOL_MENU_BUTTON (self));
+  g_return_if_fail (!symbol_tree || IDE_IS_SYMBOL_TREE (symbol_tree));
+
+  if (g_set_object (&self->symbol_tree, symbol_tree))
+    {
+      DzlTreeNode *root = dzl_tree_node_new ();
+
+      if (symbol_tree != NULL)
+        dzl_tree_node_set_item (root, G_OBJECT (symbol_tree));
+      dzl_tree_set_root (self->tree, root);
+
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SYMBOL_TREE]);
+    }
+}
diff --git a/plugins/symbol-tree/symbol-tree.h b/plugins/symbol-tree/gbp-symbol-menu-button.h
similarity index 56%
copy from plugins/symbol-tree/symbol-tree.h
copy to plugins/symbol-tree/gbp-symbol-menu-button.h
index 1e3b720..9a11c2b 100644
--- a/plugins/symbol-tree/symbol-tree.h
+++ b/plugins/symbol-tree/gbp-symbol-menu-button.h
@@ -1,6 +1,6 @@
-/* symbol-tree.h
+/* gbp-symbol-menu-button.h
  *
- * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ * Copyright (C) 2017 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
@@ -16,18 +16,18 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SYMBOL_TREE_H
-#define SYMBOL_TREE_H
+#pragma once
 
-#include <glib-object.h>
 #include <ide.h>
 
 G_BEGIN_DECLS
 
-#define SYMBOL_TYPE_TREE (symbol_tree_get_type())
+#define GBP_TYPE_SYMBOL_MENU_BUTTON (gbp_symbol_menu_button_get_type())
 
-G_DECLARE_FINAL_TYPE (SymbolTree, symbol_tree, SYMBOL, TREE, IdeObject)
+G_DECLARE_FINAL_TYPE (GbpSymbolMenuButton, gbp_symbol_menu_button, GBP, SYMBOL_MENU_BUTTON, GtkMenuButton)
 
-G_END_DECLS
+IdeSymbolTree *gbp_symbol_menu_button_get_symbol_tree (GbpSymbolMenuButton *self);
+void           gbp_symbol_menu_button_set_symbol_tree (GbpSymbolMenuButton *self,
+                                                       IdeSymbolTree       *symbol_tree);
 
-#endif /* SYMBOL_TREE_H */
+G_END_DECLS
diff --git a/plugins/symbol-tree/gbp-symbol-menu-button.ui b/plugins/symbol-tree/gbp-symbol-menu-button.ui
new file mode 100644
index 0000000..2d71fda
--- /dev/null
+++ b/plugins/symbol-tree/gbp-symbol-menu-button.ui
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkPopover" id="popover">
+    <style>
+      <class name="symbols-button"/>
+    </style>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="propagate-natural-width">true</property>
+        <property name="propagate-natural-height">true</property>
+        <property name="max-content-height">600</property>
+        <property name="visible">true</property>
+        <child>
+          <object class="DzlTree" id="tree">
+            <property name="headers-visible">false</property>
+            <property name="activate-on-single-click">true</property>
+            <property name="visible">true</property>
+            <child type="builder">
+              <object class="GbpSymbolTreeBuilder" id="tree_builder"/>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+  <template class="GbpSymbolMenuButton" parent="GtkMenuButton">
+    <property name="label">Symbols</property>
+    <property name="popover">popover</property>
+  </template>
+</interface>
diff --git a/plugins/symbol-tree/gbp-symbol-tree-builder.c b/plugins/symbol-tree/gbp-symbol-tree-builder.c
new file mode 100644
index 0000000..924c8f4
--- /dev/null
+++ b/plugins/symbol-tree/gbp-symbol-tree-builder.c
@@ -0,0 +1,164 @@
+/* gbp-symbol-tree-builder.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-symbol-tree-builder"
+
+#include <glib/gi18n.h>
+#include <ide.h>
+
+#include "gbp-symbol-tree-builder.h"
+
+struct _GbpSymbolTreeBuilder
+{
+  DzlTreeBuilder parent_instance;
+};
+
+G_DEFINE_TYPE (GbpSymbolTreeBuilder, gbp_symbol_tree_builder, DZL_TYPE_TREE_BUILDER)
+
+static void
+gbp_symbol_tree_builder_build_node (DzlTreeBuilder *builder,
+                                    DzlTreeNode    *node)
+{
+  IdeSymbolNode *parent = NULL;
+  IdeSymbolTree *symbol_tree;
+  DzlTree *tree;
+  DzlTreeNode *root;
+  GObject *item;
+  guint n_children;
+  guint i;
+
+  g_assert (DZL_IS_TREE_BUILDER (builder));
+  g_assert (DZL_IS_TREE_NODE (node));
+
+  if (!(tree = dzl_tree_builder_get_tree (builder)) ||
+      !(root = dzl_tree_get_root (tree)) ||
+      !(symbol_tree = IDE_SYMBOL_TREE (dzl_tree_node_get_item (root))))
+    return;
+
+  item = dzl_tree_node_get_item (node);
+
+  if (IDE_IS_SYMBOL_NODE (item))
+    parent = IDE_SYMBOL_NODE (item);
+
+  n_children = ide_symbol_tree_get_n_children (symbol_tree, parent);
+
+  for (i = 0; i < n_children; i++)
+    {
+      g_autoptr(IdeSymbolNode) symbol = NULL;
+      const gchar *name;
+      const gchar *icon_name;
+      DzlTreeNode *child;
+      IdeSymbolKind kind;
+      gboolean has_children;
+      gboolean use_markup;
+
+      symbol = ide_symbol_tree_get_nth_child (symbol_tree, parent, i);
+      name = ide_symbol_node_get_name (symbol);
+      kind = ide_symbol_node_get_kind (symbol);
+      use_markup = ide_symbol_node_get_use_markup (symbol);
+      icon_name = ide_symbol_kind_get_icon_name (kind);
+
+      has_children = !!ide_symbol_tree_get_n_children (symbol_tree, symbol);
+
+      child = g_object_new (DZL_TYPE_TREE_NODE,
+                            "children-possible", has_children,
+                            "text", name,
+                            "use-markup", use_markup,
+                            "icon-name", icon_name,
+                            "item", symbol,
+                            NULL);
+      dzl_tree_node_append (node, child);
+    }
+}
+
+static void
+gbp_symbol_tree_builder_get_location_cb (GObject      *object,
+                                         GAsyncResult *result,
+                                         gpointer      user_data)
+{
+  IdeSymbolNode *node = (IdeSymbolNode *)object;
+  g_autoptr(GbpSymbolTreeBuilder) self = user_data;
+  g_autoptr(IdeSourceLocation) location = NULL;
+  g_autoptr(GError) error = NULL;
+  IdePerspective *editor;
+  IdeWorkbench *workbench;
+  DzlTree *tree;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_SYMBOL_TREE_BUILDER (self));
+
+  location = ide_symbol_node_get_location_finish (node, result, &error);
+
+  if (location == NULL)
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("%s", error->message);
+      IDE_EXIT;
+    }
+
+  tree = dzl_tree_builder_get_tree (DZL_TREE_BUILDER (self));
+  workbench = ide_widget_get_workbench (GTK_WIDGET (tree));
+  editor = ide_workbench_get_perspective_by_name (workbench, "editor");
+
+  ide_editor_perspective_focus_location (IDE_EDITOR_PERSPECTIVE (editor), location);
+
+  IDE_EXIT;
+}
+
+static gboolean
+gbp_symbol_tree_builder_node_activated (DzlTreeBuilder *builder,
+                                        DzlTreeNode    *node)
+{
+  GbpSymbolTreeBuilder *self = (GbpSymbolTreeBuilder *)builder;
+  GObject *item;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_SYMBOL_TREE_BUILDER (self));
+
+  item = dzl_tree_node_get_item (node);
+
+  if (IDE_IS_SYMBOL_NODE (item))
+    {
+      ide_symbol_node_get_location_async (IDE_SYMBOL_NODE (item),
+                                          NULL,
+                                          gbp_symbol_tree_builder_get_location_cb,
+                                          g_object_ref (self));
+
+      IDE_RETURN (TRUE);
+    }
+
+  g_warning ("IdeSymbolNode did not create a source location");
+
+  IDE_RETURN (FALSE);
+}
+
+static void
+gbp_symbol_tree_builder_class_init (GbpSymbolTreeBuilderClass *klass)
+{
+  DzlTreeBuilderClass *builder_class = DZL_TREE_BUILDER_CLASS (klass);
+
+  builder_class->build_node = gbp_symbol_tree_builder_build_node;
+  builder_class->node_activated = gbp_symbol_tree_builder_node_activated;
+}
+
+static void
+gbp_symbol_tree_builder_init (GbpSymbolTreeBuilder *self)
+{
+}
diff --git a/plugins/symbol-tree/symbol-tree.h b/plugins/symbol-tree/gbp-symbol-tree-builder.h
similarity index 76%
copy from plugins/symbol-tree/symbol-tree.h
copy to plugins/symbol-tree/gbp-symbol-tree-builder.h
index 1e3b720..b4fdc68 100644
--- a/plugins/symbol-tree/symbol-tree.h
+++ b/plugins/symbol-tree/gbp-symbol-tree-builder.h
@@ -1,4 +1,4 @@
-/* symbol-tree.h
+/* gbp-symbol-tree-builder.h
  *
  * Copyright (C) 2015 Christian Hergert <christian hergert me>
  *
@@ -16,18 +16,14 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SYMBOL_TREE_H
-#define SYMBOL_TREE_H
+#pragma once
 
-#include <glib-object.h>
 #include <ide.h>
 
 G_BEGIN_DECLS
 
-#define SYMBOL_TYPE_TREE (symbol_tree_get_type())
+#define GBP_TYPE_SYMBOL_TREE_BUILDER (gbp_symbol_tree_builder_get_type())
 
-G_DECLARE_FINAL_TYPE (SymbolTree, symbol_tree, SYMBOL, TREE, IdeObject)
+G_DECLARE_FINAL_TYPE (GbpSymbolTreeBuilder, gbp_symbol_tree_builder, GBP, SYMBOL_TREE_BUILDER, 
DzlTreeBuilder)
 
 G_END_DECLS
-
-#endif /* SYMBOL_TREE_H */
diff --git a/plugins/symbol-tree/meson.build b/plugins/symbol-tree/meson.build
index 2d43ced..093bc16 100644
--- a/plugins/symbol-tree/meson.build
+++ b/plugins/symbol-tree/meson.build
@@ -9,20 +9,21 @@ symbol_tree_resources = gnome.compile_resources(
 symbol_tree_sources = [
   symbol_tree_resources[0],
   symbol_tree_resources[1],
-  'symbol-tree-builder.c',
-  'symbol-tree-builder.h',
-  'symbol-tree-panel.c',
-  'symbol-tree-panel.h',
-  'symbol-tree.c',
-  'symbol-tree.h',
+  'gbp-symbol-layout-stack-addin.c',
+  'gbp-symbol-layout-stack-addin.h',
+  'gbp-symbol-menu-button.c',
+  'gbp-symbol-menu-button.h',
+  'gbp-symbol-tree-builder.c',
+  'gbp-symbol-tree-builder.h',
+  'symbol-tree-plugin.c',
 ]
 
-shared_module('symbol-tree', symbol_tree_sources,
+shared_module('symbol-tree-plugin', symbol_tree_sources,
   dependencies: plugin_deps,
-  link_args: plugin_link_args,
+     link_args: plugin_link_args,
   link_depends: plugin_link_deps,
-  install: true,
-  install_dir: plugindir,
+       install: true,
+   install_dir: plugindir,
 )
 
 configure_file(
diff --git a/plugins/symbol-tree/symbol-tree-builder.h b/plugins/symbol-tree/symbol-tree-builder.h
index c6ca6e6..679b170 100644
--- a/plugins/symbol-tree/symbol-tree-builder.h
+++ b/plugins/symbol-tree/symbol-tree-builder.h
@@ -16,8 +16,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SYMBOL_TREE_BUILDER_H
-#define SYMBOL_TREE_BUILDER_H
+#pragma once
 
 #include <ide.h>
 
@@ -28,5 +27,3 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (SymbolTreeBuilder, symbol_tree_builder, SYMBOL, TREE_BUILDER, DzlTreeBuilder)
 
 G_END_DECLS
-
-#endif /* SYMBOL_TREE_BUILDER_H */
diff --git a/plugins/symbol-tree/symbol-tree.h b/plugins/symbol-tree/symbol-tree-plugin.c
similarity index 61%
rename from plugins/symbol-tree/symbol-tree.h
rename to plugins/symbol-tree/symbol-tree-plugin.c
index 1e3b720..861e16f 100644
--- a/plugins/symbol-tree/symbol-tree.h
+++ b/plugins/symbol-tree/symbol-tree-plugin.c
@@ -1,6 +1,6 @@
-/* symbol-tree.h
+/* symbol-tree-plugin.c
  *
- * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ * Copyright (C) 2017 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
@@ -16,18 +16,15 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SYMBOL_TREE_H
-#define SYMBOL_TREE_H
-
-#include <glib-object.h>
+#include <libpeas/peas.h>
 #include <ide.h>
 
-G_BEGIN_DECLS
-
-#define SYMBOL_TYPE_TREE (symbol_tree_get_type())
-
-G_DECLARE_FINAL_TYPE (SymbolTree, symbol_tree, SYMBOL, TREE, IdeObject)
-
-G_END_DECLS
+#include "gbp-symbol-layout-stack-addin.h"
 
-#endif /* SYMBOL_TREE_H */
+void
+peas_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_LAYOUT_STACK_ADDIN,
+                                              GBP_TYPE_SYMBOL_LAYOUT_STACK_ADDIN);
+}
diff --git a/plugins/symbol-tree/symbol-tree.gresource.xml b/plugins/symbol-tree/symbol-tree.gresource.xml
index 359d189..e0d01a5 100644
--- a/plugins/symbol-tree/symbol-tree.gresource.xml
+++ b/plugins/symbol-tree/symbol-tree.gresource.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/builder/plugins/symbol-tree">
+  <gresource prefix="/org/gnome/builder/plugins/symbol-tree-plugin">
     <file>themes/shared.css</file>
-    <file>symbol-tree-panel.ui</file>
+    <file>gbp-symbol-menu-button.ui</file>
   </gresource>
 </gresources>
diff --git a/plugins/symbol-tree/symbol-tree.plugin b/plugins/symbol-tree/symbol-tree.plugin
index 51d3284..8780015 100644
--- a/plugins/symbol-tree/symbol-tree.plugin
+++ b/plugins/symbol-tree/symbol-tree.plugin
@@ -1,5 +1,5 @@
 [Plugin]
-Module=symbol-tree
+Module=symbol-tree-plugin
 Name=Symbol Tree
 Description=Provides a Symbol Tree for the currently focused document
 Authors=Christian Hergert <christian hergert me>
diff --git a/plugins/symbol-tree/themes/shared.css b/plugins/symbol-tree/themes/shared.css
index 67f43c6..07eaa58 100644
--- a/plugins/symbol-tree/themes/shared.css
+++ b/plugins/symbol-tree/themes/shared.css
@@ -1,4 +1,10 @@
-symboltreepanel entry {
-  border-radius: 0;
-  border-width: 0 0 1px 0;
-}
+popover.symbols-button {
+  padding: 12px;
+  }
+popover.symbols-button treeview {
+  background: transparent;
+  color: @theme_fg_color;
+  }
+popover.symbols-button treeview:backdrop {
+  color: @theme_unfocused_fg_color;
+  }


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