[gnome-builder/wip/plugins: 17/36] tree: modernize GbTree a bit
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/plugins: 17/36] tree: modernize GbTree a bit
- Date: Mon, 8 Jun 2015 20:28:18 +0000 (UTC)
commit 5058dec21c3fb012951f1b96132ee202ce78b6d4
Author: Christian Hergert <christian hergert me>
Date: Sat Jun 6 13:35:59 2015 -0700
tree: modernize GbTree a bit
This came from some code written a few years back. Lets modernize the
styling a bit to match the rest of Builder. Also, move extern funcs
into a private header.
src/Makefile.am | 1 +
src/tree/gb-tree-builder.c | 183 +++++++++++++++-----------------------------
src/tree/gb-tree-node.c | 4 +-
src/tree/gb-tree-private.h | 35 +++++++++
src/tree/gb-tree.c | 3 +-
5 files changed, 101 insertions(+), 125 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1f71f5e..fbec396 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -124,6 +124,7 @@ libgnome_builder_la_SOURCES = \
tree/gb-tree-builder.h \
tree/gb-tree-node.c \
tree/gb-tree-node.h \
+ tree/gb-tree-private.h \
tree/gb-tree.c \
tree/gb-tree.h \
util/gb-cairo.c \
diff --git a/src/tree/gb-tree-builder.c b/src/tree/gb-tree-builder.c
index 6fbd377..afec38d 100644
--- a/src/tree/gb-tree-builder.c
+++ b/src/tree/gb-tree-builder.c
@@ -28,7 +28,7 @@ typedef struct
GbTree *tree;
} GbTreeBuilderPrivate;
-G_DEFINE_TYPE_WITH_PRIVATE(GbTreeBuilder, gb_tree_builder, G_TYPE_INITIALLY_UNOWNED)
+G_DEFINE_TYPE_WITH_PRIVATE (GbTreeBuilder, gb_tree_builder, G_TYPE_INITIALLY_UNOWNED)
enum
{
@@ -48,19 +48,16 @@ static GParamSpec *gParamSpecs[LAST_PROP];
* or perform an action on such an event.
*
* Returns: %TRUE if the node activation was handled.
- * Side effects: None.
*/
gboolean
gb_tree_builder_node_activated (GbTreeBuilder *builder,
GbTreeNode *node)
{
- g_return_val_if_fail(GB_IS_TREE_BUILDER(builder), FALSE);
- g_return_val_if_fail(GB_IS_TREE_NODE(node), FALSE);
+ g_return_val_if_fail (GB_IS_TREE_BUILDER(builder), FALSE);
+ g_return_val_if_fail (GB_IS_TREE_NODE(node), FALSE);
- if (GB_TREE_BUILDER_GET_CLASS(builder)->node_activated) {
- return GB_TREE_BUILDER_GET_CLASS(builder)->
- node_activated(builder, node);
- }
+ if (GB_TREE_BUILDER_GET_CLASS (builder)->node_activated)
+ return GB_TREE_BUILDER_GET_CLASS (builder)->node_activated(builder, node);
return FALSE;
}
@@ -70,12 +67,12 @@ gb_tree_builder_node_popup (GbTreeBuilder *builder,
GbTreeNode *node,
GMenu *menu)
{
- g_return_if_fail (GB_IS_TREE_BUILDER (builder));
- g_return_if_fail (GB_IS_TREE_NODE (node));
- g_return_if_fail (G_IS_MENU (menu));
+ g_return_if_fail (GB_IS_TREE_BUILDER (builder));
+ g_return_if_fail (GB_IS_TREE_NODE (node));
+ g_return_if_fail (G_IS_MENU (menu));
- if (GB_TREE_BUILDER_GET_CLASS(builder)->node_popup)
- GB_TREE_BUILDER_GET_CLASS(builder)->node_popup (builder, node, menu);
+ if (GB_TREE_BUILDER_GET_CLASS (builder)->node_popup)
+ GB_TREE_BUILDER_GET_CLASS (builder)->node_popup (builder, node, menu);
}
/**
@@ -85,20 +82,16 @@ gb_tree_builder_node_popup (GbTreeBuilder *builder,
*
* Update @node for being selected and update any actions or ui based
* on @node being selected.
- *
- * Returns: None.
- * Side effects: None.
*/
void
gb_tree_builder_node_selected (GbTreeBuilder *builder,
GbTreeNode *node)
{
- g_return_if_fail(GB_IS_TREE_BUILDER(builder));
- g_return_if_fail(GB_IS_TREE_NODE(node));
+ g_return_if_fail (GB_IS_TREE_BUILDER (builder));
+ g_return_if_fail (GB_IS_TREE_NODE (node));
- if (GB_TREE_BUILDER_GET_CLASS(builder)->node_selected) {
- GB_TREE_BUILDER_GET_CLASS(builder)->node_selected(builder, node);
- }
+ if (GB_TREE_BUILDER_GET_CLASS (builder)->node_selected)
+ GB_TREE_BUILDER_GET_CLASS (builder)->node_selected (builder, node);
}
/**
@@ -108,20 +101,16 @@ gb_tree_builder_node_selected (GbTreeBuilder *builder,
*
* Update @node and any actions that may be related to @node to account
* for it being unselected within the #GbTree.
- *
- * Returns: None.
- * Side effects: None.
*/
void
gb_tree_builder_node_unselected (GbTreeBuilder *builder,
GbTreeNode *node)
{
- g_return_if_fail(GB_IS_TREE_BUILDER(builder));
- g_return_if_fail(GB_IS_TREE_NODE(node));
+ g_return_if_fail (GB_IS_TREE_BUILDER (builder));
+ g_return_if_fail (GB_IS_TREE_NODE (node));
- if (GB_TREE_BUILDER_GET_CLASS(builder)->node_selected) {
- GB_TREE_BUILDER_GET_CLASS(builder)->node_unselected(builder, node);
- }
+ if (GB_TREE_BUILDER_GET_CLASS (builder)->node_selected)
+ GB_TREE_BUILDER_GET_CLASS (builder)->node_unselected (builder, node);
}
/**
@@ -131,21 +120,17 @@ gb_tree_builder_node_unselected (GbTreeBuilder *builder,
*
* Build @node by setting any needed properties for the item or
* updating it's appearance. Additional actions may be registered
- * based on @node<!-- -->'s type if needed.
- *
- * Returns: None.
- * Side effects: None.
+ * based on @node's type if needed.
*/
void
gb_tree_builder_build_node (GbTreeBuilder *builder,
GbTreeNode *node)
{
- g_return_if_fail(GB_IS_TREE_BUILDER(builder));
- g_return_if_fail(GB_IS_TREE_NODE(node));
+ g_return_if_fail (GB_IS_TREE_BUILDER (builder));
+ g_return_if_fail (GB_IS_TREE_NODE (node));
- if (GB_TREE_BUILDER_GET_CLASS(builder)->build_node) {
- GB_TREE_BUILDER_GET_CLASS(builder)->build_node(builder, node);
- }
+ if (GB_TREE_BUILDER_GET_CLASS (builder)->build_node)
+ GB_TREE_BUILDER_GET_CLASS (builder)->build_node (builder, node);
}
/**
@@ -154,9 +139,6 @@ gb_tree_builder_build_node (GbTreeBuilder *builder,
* @tree: (in): A #GbTree.
*
* Sets the tree the builder is associated with.
- *
- * Returns: None.
- * Side effects: None.
*/
static void
gb_tree_builder_set_tree (GbTreeBuilder *builder,
@@ -164,15 +146,15 @@ gb_tree_builder_set_tree (GbTreeBuilder *builder,
{
GbTreeBuilderPrivate *priv = gb_tree_builder_get_instance_private (builder);
- g_return_if_fail(GB_IS_TREE_BUILDER(builder));
- g_return_if_fail(priv->tree == NULL);
- g_return_if_fail(GB_IS_TREE(tree));
+ g_return_if_fail (GB_IS_TREE_BUILDER (builder));
+ g_return_if_fail (priv->tree == NULL);
+ g_return_if_fail (GB_IS_TREE (tree));
- if (tree) {
- priv->tree = tree;
- g_object_add_weak_pointer(G_OBJECT(priv->tree),
- (gpointer *)&priv->tree);
- }
+ if (tree)
+ {
+ priv->tree = tree;
+ g_object_add_weak_pointer (G_OBJECT (priv->tree), (gpointer *)&priv->tree);
+ }
}
/**
@@ -181,48 +163,33 @@ gb_tree_builder_set_tree (GbTreeBuilder *builder,
*
* Gets the tree that owns the builder.
*
- * Returns: (transfer none) (type GbTree*): A #GbTree.
+ * Returns: (transfer none) (type GbTree) (nullable): A #GbTree or %NULL.
*/
GtkWidget *
gb_tree_builder_get_tree (GbTreeBuilder *builder)
{
GbTreeBuilderPrivate *priv = gb_tree_builder_get_instance_private (builder);
- g_return_val_if_fail(GB_IS_TREE_BUILDER(builder), NULL);
+ g_return_val_if_fail (GB_IS_TREE_BUILDER (builder), NULL);
- return GTK_WIDGET(priv->tree);
+ return (GtkWidget *)priv->tree;
}
-/**
- * gb_tree_builder_finalize:
- * @object: (in): A #GbTreeBuilder.
- *
- * Finalizer for a #GbTreeBuilder instance.
- */
static void
gb_tree_builder_finalize (GObject *object)
{
GbTreeBuilder *builder = GB_TREE_BUILDER (object);
GbTreeBuilderPrivate *priv = gb_tree_builder_get_instance_private (builder);
- if (priv->tree) {
- g_object_remove_weak_pointer(G_OBJECT(priv->tree),
- (gpointer *)&priv->tree);
- priv->tree = NULL;
- }
+ if (priv->tree)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (priv->tree), (gpointer *)&priv->tree);
+ priv->tree = NULL;
+ }
- G_OBJECT_CLASS(gb_tree_builder_parent_class)->finalize(object);
+ G_OBJECT_CLASS (gb_tree_builder_parent_class)->finalize (object);
}
-/**
- * gb_tree_builder_get_property:
- * @object: (in): A #GObject.
- * @prop_id: (in): The property identifier.
- * @value: (out): The given property.
- * @pspec: (in): A #ParamSpec.
- *
- * Get a given #GObject property.
- */
static void
gb_tree_builder_get_property (GObject *object,
guint prop_id,
@@ -230,58 +197,43 @@ gb_tree_builder_get_property (GObject *object,
GParamSpec *pspec)
{
GbTreeBuilder *builder = GB_TREE_BUILDER (object);
- GbTreeBuilderPrivate *priv = gb_tree_builder_get_instance_private (builder);
-
- switch (prop_id) {
- case PROP_TREE:
- g_value_set_object(value, priv->tree);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- }
+ GbTreeBuilderPrivate *priv = gb_tree_builder_get_instance_private (builder);
+
+ switch (prop_id)
+ {
+ case PROP_TREE:
+ g_value_set_object (value, priv->tree);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
-/**
- * gb_tree_builder_set_property:
- * @object: (in): A #GObject.
- * @prop_id: (in): The property identifier.
- * @value: (in): The given property.
- * @pspec: (in): A #ParamSpec.
- *
- * Set a given #GObject property.
- */
static void
gb_tree_builder_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
- GbTreeBuilder *builder = GB_TREE_BUILDER(object);
-
- switch (prop_id) {
- case PROP_TREE:
- gb_tree_builder_set_tree(builder, g_value_get_object(value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- }
+ GbTreeBuilder *builder = GB_TREE_BUILDER (object);
+
+ switch (prop_id)
+ {
+ case PROP_TREE:
+ gb_tree_builder_set_tree (builder, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
-/**
- * gb_tree_builder_class_init:
- * @klass: (in): A #GbTreeBuilderClass.
- *
- * Initializes the #GbTreeBuilderClass and prepares the vtable.
- *
- * Returns: None.
- * Side effects: None.
- */
static void
gb_tree_builder_class_init (GbTreeBuilderClass *klass)
{
- GObjectClass *object_class;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class = G_OBJECT_CLASS(klass);
object_class->finalize = gb_tree_builder_finalize;
object_class->get_property = gb_tree_builder_get_property;
object_class->set_property = gb_tree_builder_set_property;
@@ -296,15 +248,6 @@ gb_tree_builder_class_init (GbTreeBuilderClass *klass)
g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
}
-/**
- * gb_tree_builder_init:
- * @: (in): A #GbTreeBuilder.
- *
- * Initializes the newly created #GbTreeBuilder instance.
- *
- * Returns: None.
- * Side effects: None.
- */
static void
gb_tree_builder_init (GbTreeBuilder *builder)
{
diff --git a/src/tree/gb-tree-node.c b/src/tree/gb-tree-node.c
index 2684608..83ce79c 100644
--- a/src/tree/gb-tree-node.c
+++ b/src/tree/gb-tree-node.c
@@ -22,6 +22,7 @@
#include "gb-tree.h"
#include "gb-tree-node.h"
+#include "gb-tree-private.h"
struct _GbTreeNode
{
@@ -56,9 +57,6 @@ enum {
static GParamSpec *gParamSpecs [LAST_PROP];
-extern void _gb_tree_rebuild_node (GbTree *tree,
- GbTreeNode *node);
-
/**
* gb_tree_node_new:
*
diff --git a/src/tree/gb-tree-private.h b/src/tree/gb-tree-private.h
new file mode 100644
index 0000000..0d5b25b
--- /dev/null
+++ b/src/tree/gb-tree-private.h
@@ -0,0 +1,35 @@
+/* gb-tree-private.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_PRIVATE_H
+#define GB_TREE_PRIVATE_H
+
+#include "gb-tree.h"
+#include "gb-tree-builder.h"
+#include "gb-tree-node.h"
+
+G_BEGIN_DECLS
+
+void _gb_tree_rebuild_node (GbTree *tree,
+ GbTreeNode *node);
+void _gb_tree_node_set_tree (GbTreeNode *node,
+ GbTree *tree);
+
+G_END_DECLS
+
+#endif /* GB_TREE_PRIVATE_H */
diff --git a/src/tree/gb-tree.c b/src/tree/gb-tree.c
index 024241b..a8e0082 100644
--- a/src/tree/gb-tree.c
+++ b/src/tree/gb-tree.c
@@ -23,6 +23,7 @@
#include "gb-tree.h"
#include "gb-tree-node.h"
+#include "gb-tree-private.h"
#include "gb-widget.h"
typedef struct
@@ -46,8 +47,6 @@ typedef struct
} NodeLookup;
static void gb_tree_buildable_init (GtkBuildableIface *iface);
-extern void _gb_tree_node_set_tree (GbTreeNode *node,
- GbTree *tree);
G_DEFINE_TYPE_WITH_CODE (GbTree, gb_tree, GTK_TYPE_TREE_VIEW,
G_ADD_PRIVATE (GbTree)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]