[gnome-builder/wip/symbol-tree] symbol-tree: stub out builder for panel based symbol tree



commit 79145c08f76172f4fef9a624708ed3bc6eb507a0
Author: Christian Hergert <christian hergert me>
Date:   Wed Jun 17 01:08:55 2015 -0700

    symbol-tree: stub out builder for panel based symbol tree

 plugins/symbol-tree/Makefile.am           |    3 +
 plugins/symbol-tree/symbol-tree-builder.c |   66 +++++++++++++++++++++++++++++
 plugins/symbol-tree/symbol-tree-builder.h |   33 ++++++++++++++
 plugins/symbol-tree/symbol-tree.c         |   44 +++++++++++++++++++-
 plugins/symbol-tree/symbol-tree.ui        |    1 +
 5 files changed, 146 insertions(+), 1 deletions(-)
---
diff --git a/plugins/symbol-tree/Makefile.am b/plugins/symbol-tree/Makefile.am
index 1bd8882..89e0172 100644
--- a/plugins/symbol-tree/Makefile.am
+++ b/plugins/symbol-tree/Makefile.am
@@ -6,6 +6,8 @@ EXTRA_DIST =
 noinst_LTLIBRARIES = libsymbol-tree.la
 
 libsymbol_tree_la_SOURCES = \
+       symbol-tree-builder.c \
+       symbol-tree-builder.h \
        symbol-tree-resources.c \
        symbol-tree-resources.h \
        symbol-tree.c \
@@ -17,6 +19,7 @@ libsymbol_tree_la_CFLAGS = \
        $(BUILDER_CFLAGS) \
        -I$(top_srcdir)/src \
        -I$(top_srcdir)/src/documents \
+       -I$(top_srcdir)/src/editor \
        -I$(top_srcdir)/src/views \
        -I$(top_srcdir)/src/tree \
        -I$(top_srcdir)/src/workbench \
diff --git a/plugins/symbol-tree/symbol-tree-builder.c b/plugins/symbol-tree/symbol-tree-builder.c
new file mode 100644
index 0000000..17c1d89
--- /dev/null
+++ b/plugins/symbol-tree/symbol-tree-builder.c
@@ -0,0 +1,66 @@
+/* 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/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "symbol-tree-builder.h"
+
+struct _SymbolTreeBuilder
+{
+  GbTreeBuilder parent_instance;
+};
+
+G_DEFINE_TYPE (SymbolTreeBuilder, symbol_tree_builder, GB_TYPE_TREE_BUILDER)
+
+static void
+symbol_tree_builder_build_node (GbTreeBuilder *builder,
+                                GbTreeNode    *node)
+{
+  GObject *item;
+
+  g_assert (GB_IS_TREE_BUILDER (builder));
+  g_assert (GB_IS_TREE_NODE (node));
+
+  item = gb_tree_node_get_item (node);
+
+  if (GB_IS_EDITOR_DOCUMENT (item))
+    {
+#if 0
+      GbTreeNode *child;
+
+      child = g_object_new (GB_TYPE_TREE_NODE,
+                            "text", _("Symbols"),
+                            "icon-name", "lang-class-symbolic",
+                            NULL);
+      gb_tree_node_append (node, child);
+#endif
+    }
+}
+
+static void
+symbol_tree_builder_class_init (SymbolTreeBuilderClass *klass)
+{
+  GbTreeBuilderClass *builder_class = GB_TREE_BUILDER_CLASS (klass);
+
+  builder_class->build_node = symbol_tree_builder_build_node;
+}
+
+static void
+symbol_tree_builder_init (SymbolTreeBuilder *self)
+{
+}
diff --git a/plugins/symbol-tree/symbol-tree-builder.h b/plugins/symbol-tree/symbol-tree-builder.h
new file mode 100644
index 0000000..9dfbf04
--- /dev/null
+++ b/plugins/symbol-tree/symbol-tree-builder.h
@@ -0,0 +1,33 @@
+/* symbol-tree-builder.h
+ *
+ * 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/>.
+ */
+
+#ifndef SYMBOL_TREE_BUILDER_H
+#define SYMBOL_TREE_BUILDER_H
+
+#include "gb-editor-document.h"
+#include "gb-tree-builder.h"
+
+G_BEGIN_DECLS
+
+#define SYMBOL_TYPE_TREE_BUILDER (symbol_tree_builder_get_type())
+
+G_DECLARE_FINAL_TYPE (SymbolTreeBuilder, symbol_tree_builder, SYMBOL, TREE_BUILDER, GbTreeBuilder)
+
+G_END_DECLS
+
+#endif /* SYMBOL_TREE_BUILDER_H */
diff --git a/plugins/symbol-tree/symbol-tree.c b/plugins/symbol-tree/symbol-tree.c
index 5d78565..04c6438 100644
--- a/plugins/symbol-tree/symbol-tree.c
+++ b/plugins/symbol-tree/symbol-tree.c
@@ -20,11 +20,13 @@
 #include <libpeas/peas.h>
 
 
+#include "gb-editor-view.h"
 #include "gb-plugins.h"
 #include "gb-tree.h"
 #include "gb-workspace.h"
 
 #include "symbol-tree.h"
+#include "symbol-tree-builder.h"
 #include "symbol-tree-resources.h"
 
 struct _SymbolTree
@@ -32,7 +34,6 @@ struct _SymbolTree
   GtkBox       parent_instance;
 
   GbWorkbench *workbench;
-
   GbTree      *tree;
 };
 
@@ -50,6 +51,32 @@ G_DEFINE_TYPE_WITH_CODE (SymbolTree, symbol_tree, GTK_TYPE_BOX,
                          G_IMPLEMENT_INTERFACE (GB_TYPE_WORKBENCH_ADDIN, workbench_addin_init))
 
 static void
+notify_active_view_cb (SymbolTree  *self,
+                       GParamFlags *pspec,
+                       GbWorkbench *workbench)
+{
+  GbDocument *document = NULL;
+  GtkWidget *active_view;
+  GbTreeNode *root;
+
+  g_assert (SYMBOL_IS_TREE (self));
+  g_assert (pspec != NULL);
+  g_assert (GB_IS_WORKBENCH (workbench));
+
+  if ((active_view = gb_workbench_get_active_view (workbench)) && GB_IS_EDITOR_VIEW (active_view))
+    document = gb_view_get_document (GB_VIEW (active_view));
+
+  root = gb_tree_get_root (self->tree);
+
+  if ((GObject *)document != gb_tree_node_get_item (root))
+    {
+      root = gb_tree_node_new ();
+      gb_tree_node_set_item (root, G_OBJECT (document));
+      gb_tree_set_root (self->tree, root);
+    }
+}
+
+static void
 symbol_tree_load (GbWorkbenchAddin *addin)
 {
   SymbolTree *self = (SymbolTree *)addin;
@@ -59,6 +86,12 @@ symbol_tree_load (GbWorkbenchAddin *addin)
   g_assert (SYMBOL_IS_TREE (self));
   g_assert (GB_IS_WORKBENCH (self->workbench));
 
+  g_signal_connect_object (self->workbench,
+                           "notify::active-view",
+                           G_CALLBACK (notify_active_view_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   workspace = GB_WORKSPACE (gb_workbench_get_workspace (self->workbench));
   right_pane = gb_workspace_get_right_pane (workspace);
   gb_workspace_pane_add_page (GB_WORKSPACE_PANE (right_pane),
@@ -155,7 +188,16 @@ symbol_tree_class_init (SymbolTreeClass *klass)
 static void
 symbol_tree_init (SymbolTree *self)
 {
+  GbTreeNode *root;
+  GbTreeBuilder *builder;
+
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  root = gb_tree_node_new ();
+  gb_tree_set_root (self->tree, root);
+
+  builder = g_object_new (SYMBOL_TYPE_TREE_BUILDER, NULL);
+  gb_tree_add_builder (self->tree, builder);
 }
 
 GB_DEFINE_EMBEDDED_PLUGIN (symbol_tree,
diff --git a/plugins/symbol-tree/symbol-tree.ui b/plugins/symbol-tree/symbol-tree.ui
index 82316b4..6fb4e57 100644
--- a/plugins/symbol-tree/symbol-tree.ui
+++ b/plugins/symbol-tree/symbol-tree.ui
@@ -11,6 +11,7 @@
         <child>
           <object class="GbTree" id="tree">
             <property name="headers-visible">false</property>
+            <property name="show-icons">true</property>
             <property name="visible">true</property>
           </object>
         </child>


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