[gnome-builder/wip/lazy-tree: 4/5] tree: style cleanup



commit 703f1cef35c7af46c8af62868bc0d5fba98a6003
Author: Christian Hergert <christian hergert me>
Date:   Sun Jun 14 11:49:30 2015 -0700

    tree: style cleanup
    
     - Move types to gb-tree-types.h to avoid cyclic includes
     - Move public tree functions to bottom of file
     - Move node functions to gb-tree-node.h
     - Make gb_tree_get_path() private

 src/Makefile.am            |    5 +-
 src/tree/gb-tree-builder.h |    5 +-
 src/tree/gb-tree-node.c    |    2 +-
 src/tree/gb-tree-node.h    |    7 +-
 src/tree/gb-tree-private.h |   14 ++--
 src/tree/gb-tree-types.h   |   36 +++++++++
 src/tree/gb-tree.c         |  180 ++++++++++++++++++++++----------------------
 src/tree/gb-tree.h         |   22 ++----
 8 files changed, 148 insertions(+), 123 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index e7b9fad..7fcf197 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -98,11 +98,12 @@ libgnome_builder_la_SOURCES = \
        support/gb-support.h \
        tree/gb-tree-builder.c \
        tree/gb-tree-builder.h \
+       tree/gb-tree.c \
+       tree/gb-tree.h \
        tree/gb-tree-node.c \
        tree/gb-tree-node.h \
        tree/gb-tree-private.h \
-       tree/gb-tree.c \
-       tree/gb-tree.h \
+       tree/gb-tree-types.h \
        util/gb-cairo.c \
        util/gb-cairo.h \
        util/gb-dnd.c \
diff --git a/src/tree/gb-tree-builder.h b/src/tree/gb-tree-builder.h
index ee94972..08723f3 100644
--- a/src/tree/gb-tree-builder.h
+++ b/src/tree/gb-tree-builder.h
@@ -22,13 +22,10 @@
 #include <glib-object.h>
 
 #include "gb-tree-node.h"
+#include "gb-tree-types.h"
 
 G_BEGIN_DECLS
 
-#define GB_TYPE_TREE_BUILDER            (gb_tree_builder_get_type())
-
-G_DECLARE_DERIVABLE_TYPE (GbTreeBuilder, gb_tree_builder, GB, TREE_BUILDER, GInitiallyUnowned)
-
 struct _GbTreeBuilderClass
 {
   GInitiallyUnownedClass parent_class;
diff --git a/src/tree/gb-tree-node.c b/src/tree/gb-tree-node.c
index 83ce79c..afc5982 100644
--- a/src/tree/gb-tree-node.c
+++ b/src/tree/gb-tree-node.c
@@ -207,7 +207,7 @@ gb_tree_node_get_path (GbTreeNode *node)
   g_assert (toplevel->tree);
 
   list = g_list_remove_link (list, list);
-  path = gb_tree_get_path (toplevel->tree, list);
+  path = _gb_tree_get_path (toplevel->tree, list);
 
   g_list_free (list);
 
diff --git a/src/tree/gb-tree-node.h b/src/tree/gb-tree-node.h
index b51414d..be5b5b4 100644
--- a/src/tree/gb-tree-node.h
+++ b/src/tree/gb-tree-node.h
@@ -19,14 +19,10 @@
 #ifndef GB_TREE_NODE_H
 #define GB_TREE_NODE_H
 
-#include <gtk/gtk.h>
+#include "gb-tree-types.h"
 
 G_BEGIN_DECLS
 
-#define GB_TYPE_TREE_NODE (gb_tree_node_get_type())
-
-G_DECLARE_FINAL_TYPE (GbTreeNode, gb_tree_node, GB, TREE_NODE, GInitiallyUnowned)
-
 GbTreeNode    *gb_tree_node_new           (void);
 void           gb_tree_node_append        (GbTreeNode   *node,
                                            GbTreeNode   *child);
@@ -55,6 +51,7 @@ void           gb_tree_node_show_popover  (GbTreeNode   *node,
 const gchar   *gb_tree_node_get_text      (GbTreeNode   *node);
 void           gb_tree_node_set_text      (GbTreeNode   *node,
                                            const gchar  *text);
+GbTree       *gb_tree_node_get_tree       (GbTreeNode   *node);
 
 G_END_DECLS
 
diff --git a/src/tree/gb-tree-private.h b/src/tree/gb-tree-private.h
index 0d5b25b..da00704 100644
--- a/src/tree/gb-tree-private.h
+++ b/src/tree/gb-tree-private.h
@@ -19,16 +19,16 @@
 #ifndef GB_TREE_PRIVATE_H
 #define GB_TREE_PRIVATE_H
 
-#include "gb-tree.h"
-#include "gb-tree-builder.h"
-#include "gb-tree-node.h"
+#include "gb-tree-types.h"
 
 G_BEGIN_DECLS
 
-void _gb_tree_rebuild_node  (GbTree     *tree,
-                             GbTreeNode *node);
-void _gb_tree_node_set_tree (GbTreeNode *node,
-                             GbTree     *tree);
+void         _gb_tree_rebuild_node  (GbTree     *tree,
+                                     GbTreeNode *node);
+void         _gb_tree_node_set_tree (GbTreeNode *node,
+                                     GbTree     *tree);
+GtkTreePath *_gb_tree_get_path      (GbTree     *tree,
+                                     GList      *list);
 
 G_END_DECLS
 
diff --git a/src/tree/gb-tree-types.h b/src/tree/gb-tree-types.h
new file mode 100644
index 0000000..4a3fb26
--- /dev/null
+++ b/src/tree/gb-tree-types.h
@@ -0,0 +1,36 @@
+/* gb-tree-types.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 GB_TREE_TYPES_H
+#define GB_TREE_TYPES_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_TREE         (gb_tree_get_type())
+#define GB_TYPE_TREE_NODE    (gb_tree_node_get_type())
+#define GB_TYPE_TREE_BUILDER (gb_tree_builder_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (GbTree,        gb_tree,         GB, TREE,         GtkTreeView)
+G_DECLARE_DERIVABLE_TYPE (GbTreeBuilder, gb_tree_builder, GB, TREE_BUILDER, GInitiallyUnowned)
+G_DECLARE_FINAL_TYPE     (GbTreeNode,    gb_tree_node,    GB, TREE_NODE,    GInitiallyUnowned)
+
+G_END_DECLS
+
+#endif /* GB_TREE_TYPES_H */
diff --git a/src/tree/gb-tree.c b/src/tree/gb-tree.c
index c5a33d5..d721097 100644
--- a/src/tree/gb-tree.c
+++ b/src/tree/gb-tree.c
@@ -361,40 +361,6 @@ gb_tree_selection_changed (GbTree           *tree,
 }
 
 /**
- * gb_tree_get_selected:
- * @tree: (in): A #GbTree.
- *
- * Gets the currently selected node in the tree.
- *
- * Returns: (transfer none): A #GbTreeNode.
- */
-GbTreeNode *
-gb_tree_get_selected (GbTree *tree)
-{
-  GtkTreeSelection *selection;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  GbTreeNode *ret = NULL;
-
-  g_return_val_if_fail (GB_IS_TREE (tree), NULL);
-
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
-  if (gtk_tree_selection_get_selected (selection, &model, &iter))
-    {
-      gtk_tree_model_get (model, &iter, 0, &ret, -1);
-
-      /*
-       * We incurred an extra reference when extracting the value from
-       * the treemodel. Since it owns the reference, we can drop it here
-       * so that we don't transfer the ownership to the caller.
-       */
-      g_object_unref (ret);
-    }
-
-  return ret;
-}
-
-/**
  * gb_tree_get_iter_for_node:
  * @tree: (in): A #GbTree.
  * @parent: (in) (allow-none): A #GtkTreeIter of parent or %NULL.
@@ -447,48 +413,6 @@ gb_tree_get_iter_for_node (GbTree      *tree,
   return FALSE;
 }
 
-/**
- * gb_tree_get_path:
- * @tree: (in): A #GbTree.
- * @list: (in) (element-type GbTreeNode): A list of #GbTreeNode.
- *
- * Retrieves the GtkTreePath for a list of GbTreeNode.
- *
- * Returns: (transfer full): A #GtkTreePath.
- */
-GtkTreePath *
-gb_tree_get_path (GbTree *tree,
-                  GList  *list)
-{
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  GtkTreeIter old_iter;
-  GtkTreeIter *parent = NULL;
-  GbTreePrivate *priv = gb_tree_get_instance_private (tree);
-
-  g_return_val_if_fail (GB_IS_TREE (tree), NULL);
-
-  model = GTK_TREE_MODEL (priv->store);
-
-  if (!list || !gtk_tree_model_get_iter_first (model, &iter))
-    return NULL;
-
-  if (list->data == priv->root)
-    list = list->next;
-
-  while (gb_tree_get_iter_for_node (tree, parent, &iter, list->data))
-    {
-      old_iter = iter;
-      parent = &old_iter;
-      if (list->next)
-        list = list->next;
-      else
-        return gtk_tree_model_get_path (model, &iter);
-    }
-
-  return NULL;
-}
-
 static gboolean
 gb_tree_add_builder_foreach_cb (GtkTreeModel *model,
                                 GtkTreePath  *path,
@@ -976,20 +900,6 @@ gb_tree_button_press_event (GbTree         *tree,
   return FALSE;
 }
 
-void
-gb_tree_scroll_to_node (GbTree     *tree,
-                        GbTreeNode *node)
-{
-  GtkTreePath *path;
-
-  g_return_if_fail (GB_IS_TREE (tree));
-  g_return_if_fail (GB_IS_TREE_NODE (node));
-
-  path = gb_tree_node_get_path (node);
-  gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree), path, NULL, FALSE, 0, 0);
-  gtk_tree_path_free (path);
-}
-
 static gboolean
 gb_tree_find_item_foreach_cb (GtkTreeModel *model,
                               GtkTreePath  *path,
@@ -1414,3 +1324,93 @@ gb_tree_set_show_icons (GbTree   *tree,
                                 gParamSpecs [PROP_SHOW_ICONS]);
     }
 }
+
+/**
+ * gb_tree_get_selected:
+ * @tree: (in): A #GbTree.
+ *
+ * Gets the currently selected node in the tree.
+ *
+ * Returns: (transfer none): A #GbTreeNode.
+ */
+GbTreeNode *
+gb_tree_get_selected (GbTree *tree)
+{
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GbTreeNode *ret = NULL;
+
+  g_return_val_if_fail (GB_IS_TREE (tree), NULL);
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
+  if (gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      gtk_tree_model_get (model, &iter, 0, &ret, -1);
+
+      /*
+       * We incurred an extra reference when extracting the value from
+       * the treemodel. Since it owns the reference, we can drop it here
+       * so that we don't transfer the ownership to the caller.
+       */
+      g_object_unref (ret);
+    }
+
+  return ret;
+}
+
+void
+gb_tree_scroll_to_node (GbTree     *tree,
+                        GbTreeNode *node)
+{
+  GtkTreePath *path;
+
+  g_return_if_fail (GB_IS_TREE (tree));
+  g_return_if_fail (GB_IS_TREE_NODE (node));
+
+  path = gb_tree_node_get_path (node);
+  gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree), path, NULL, FALSE, 0, 0);
+  gtk_tree_path_free (path);
+}
+
+/**
+ * gb_tree_get_path:
+ * @tree: (in): A #GbTree.
+ * @list: (in) (element-type GbTreeNode): A list of #GbTreeNode.
+ *
+ * Retrieves the GtkTreePath for a list of GbTreeNode.
+ *
+ * Returns: (transfer full): A #GtkTreePath.
+ */
+GtkTreePath *
+_gb_tree_get_path (GbTree *tree,
+                   GList  *list)
+{
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GtkTreeIter old_iter;
+  GtkTreeIter *parent = NULL;
+  GbTreePrivate *priv = gb_tree_get_instance_private (tree);
+
+  g_return_val_if_fail (GB_IS_TREE (tree), NULL);
+
+  model = GTK_TREE_MODEL (priv->store);
+
+  if (!list || !gtk_tree_model_get_iter_first (model, &iter))
+    return NULL;
+
+  if (list->data == priv->root)
+    list = list->next;
+
+  while (gb_tree_get_iter_for_node (tree, parent, &iter, list->data))
+    {
+      old_iter = iter;
+      parent = &old_iter;
+      if (list->next)
+        list = list->next;
+      else
+        return gtk_tree_model_get_path (model, &iter);
+    }
+
+  return NULL;
+}
diff --git a/src/tree/gb-tree.h b/src/tree/gb-tree.h
index 3c8720a..f29a233 100644
--- a/src/tree/gb-tree.h
+++ b/src/tree/gb-tree.h
@@ -23,13 +23,10 @@
 
 #include "gb-tree-builder.h"
 #include "gb-tree-node.h"
+#include "gb-tree-types.h"
 
 G_BEGIN_DECLS
 
-#define GB_TYPE_TREE (gb_tree_get_type())
-
-G_DECLARE_DERIVABLE_TYPE (GbTree, gb_tree, GB, TREE, GtkTreeView)
-
 struct _GbTreeClass
 {
        GtkTreeViewClass parent_class;
@@ -44,12 +41,15 @@ struct _GbTreeClass
 
 void          gb_tree_add_builder    (GbTree        *tree,
                                       GbTreeBuilder *builder);
-GtkTreePath  *gb_tree_get_path       (GbTree        *tree,
-                                      GList         *list);
-GbTreeNode   *gb_tree_get_selected   (GbTree        *tree);
-void          gb_tree_rebuild        (GbTree        *tree);
 void          gb_tree_remove_builder (GbTree        *tree,
                                       GbTreeBuilder *builder);
+GbTreeNode   *gb_tree_find_item      (GbTree        *tree,
+                                      GObject       *item);
+GbTreeNode   *gb_tree_find_custom    (GbTree        *tree,
+                                      GEqualFunc     equal_func,
+                                      gpointer       key);
+GbTreeNode   *gb_tree_get_selected   (GbTree        *tree);
+void          gb_tree_rebuild        (GbTree        *tree);
 void          gb_tree_append         (GbTree        *tree,
                                       GbTreeNode    *node,
                                       GbTreeNode    *child);
@@ -59,15 +59,9 @@ void          gb_tree_prepend        (GbTree        *tree,
 void          gb_tree_set_root       (GbTree        *tree,
                                       GbTreeNode    *node);
 GbTreeNode   *gb_tree_get_root       (GbTree        *tree);
-GbTree       *gb_tree_node_get_tree  (GbTreeNode    *node);
 void          gb_tree_set_show_icons (GbTree        *tree,
                                       gboolean       show_icons);
 gboolean      gb_tree_get_show_icons (GbTree        *tree);
-GbTreeNode   *gb_tree_find_item      (GbTree        *tree,
-                                      GObject       *item);
-GbTreeNode   *gb_tree_find_custom    (GbTree        *tree,
-                                      GEqualFunc     equal_func,
-                                      gpointer       key);
 void          gb_tree_scroll_to_node (GbTree        *tree,
                                       GbTreeNode    *node);
 void          gb_tree_expand_to_node (GbTree        *tree,


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