[anjuta] am-project: Split project and root node data



commit 570d4ab441cba22499cbddd717dbe48afafecb0e
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Mon Dec 27 09:29:06 2010 +0100

    am-project: Split project and root node data

 plugins/am-project/Makefile.am          |    2 +
 plugins/am-project/am-project-private.h |    2 +-
 plugins/am-project/am-project.c         |   20 ++---
 plugins/am-project/am-project.h         |   11 +--
 plugins/am-project/amp-root.c           |  123 +++++++++++++++++++++++++++++++
 plugins/am-project/amp-root.h           |   63 ++++++++++++++++
 6 files changed, 201 insertions(+), 20 deletions(-)
---
diff --git a/plugins/am-project/Makefile.am b/plugins/am-project/Makefile.am
index d6ea914..e956fb5 100644
--- a/plugins/am-project/Makefile.am
+++ b/plugins/am-project/Makefile.am
@@ -49,6 +49,8 @@ libam_project_la_SOURCES = \
 	am-properties.h \
 	amp-node.c \
 	amp-node.h \
+	amp-root.c \
+	amp-root.h \
 	amp-module.h \
 	amp-module.c \
 	amp-package.h \
diff --git a/plugins/am-project/am-project-private.h b/plugins/am-project/am-project-private.h
index eaaf6e0..5032fd2 100644
--- a/plugins/am-project/am-project-private.h
+++ b/plugins/am-project/am-project-private.h
@@ -43,7 +43,7 @@ struct _AmpProperty {
 };
 
 struct _AmpProject {
-	AnjutaProjectNode base;
+	AmpRootNode base;
 
 	/* GFile corresponding to root configure */
 	GFile *configure;
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index 4838af1..6f89ded 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -450,9 +450,6 @@ amp_project_clear (AmpProject *project)
 	if (project->configure_file != NULL) anjuta_token_file_free (project->configure_file);
 	project->configure_file = NULL;
 	if (project->configure_token) anjuta_token_free (project->configure_token);
-	
-	g_list_foreach (project->base.custom_properties, (GFunc)amp_property_free, NULL);
-	project->base.custom_properties = NULL;
 }
 
 static void
@@ -2300,8 +2297,7 @@ amp_project_move (AmpProject *project, const gchar *path)
 	/* Change project root directory */
 	packet.old_root_file = g_object_ref (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (project)));
 	root_file = g_file_new_for_path (path);
-	g_object_unref (project->base.file);
-	project->base.file = g_object_ref (root_file);
+	amp_root_node_set_file (AMP_ROOT_NODE (project), root_file);
 	
 	/* Change project root directory in groups */
 	old_hash = project->groups;
@@ -2370,9 +2366,12 @@ AmpProject *
 amp_project_new (GFile *file, GError **error)
 {
 	AmpProject *project;
+	GFile *new_file;
 	
 	project = AMP_PROJECT (g_object_new (AMP_TYPE_PROJECT, NULL));
-	project->base.file = g_file_dup (file);
+	new_file = g_file_dup (file);
+	amp_root_node_set_file (AMP_ROOT_NODE (project), new_file);
+	g_object_unref (new_file);
 	
 	return project;
 }
@@ -3086,12 +3085,6 @@ amp_project_init (AmpProject *project)
 	g_return_if_fail (project != NULL);
 	g_return_if_fail (AMP_IS_PROJECT (project));
 
-	project->base.type = ANJUTA_PROJECT_ROOT;
-	project->base.native_properties = amp_get_project_property_list();
-	project->base.state = ANJUTA_PROJECT_CAN_ADD_GROUP |
-						ANJUTA_PROJECT_CAN_ADD_PACKAGE,
-						ANJUTA_PROJECT_CAN_SAVE;
-	
 	/* project data */
 	project->configure_file = NULL;
 	project->configure_token = NULL;
@@ -3131,7 +3124,7 @@ amp_project_class_finalize (AmpProjectClass *klass)
 
 G_DEFINE_DYNAMIC_TYPE_EXTENDED (AmpProject,
                                 amp_project,
-                                AMP_TYPE_NODE,
+                                AMP_TYPE_ROOT_NODE,
                                 0,
                                 G_IMPLEMENT_INTERFACE_DYNAMIC (IANJUTA_TYPE_PROJECT,
                                                                iproject_iface_init));
@@ -3140,6 +3133,7 @@ void
 amp_project_register_project (GTypeModule *module)
 {
 	amp_node_register (module);
+	amp_root_node_register (module);
 	amp_module_node_register (module);
 	amp_package_node_register (module);
 	amp_group_node_register (module);
diff --git a/plugins/am-project/am-project.h b/plugins/am-project/am-project.h
index 36cac18..532e71d 100644
--- a/plugins/am-project/am-project.h
+++ b/plugins/am-project/am-project.h
@@ -24,7 +24,7 @@
 
 #include <glib-object.h>
 
-#include "amp-node.h"
+#include "amp-root.h"
 
 #include <libanjuta/anjuta-project.h>
 #include <libanjuta/anjuta-token.h>
@@ -42,17 +42,16 @@ G_BEGIN_DECLS
 typedef struct _AmpProject        AmpProject;
 typedef struct _AmpProjectClass   AmpProjectClass;
 
-struct _AmpProjectClass {
-	AmpNodeClass parent_class;
-};
-
-typedef struct _AnjutaAmRootNode AnjutaAmRootNode;
 typedef struct _AmpModuleNode AmpModuleNode;
 typedef struct _AmpPackageNode AmpPackageNode;
 typedef struct _AmpGroupNode AmpGroupNode;
 typedef struct _AmpTargetNode AmpTargetNode;
 typedef struct _AmpSourceNode AmpSourceNode;
 
+struct _AmpProjectClass {
+	AmpRootNodeClass parent_class;
+};
+
 typedef struct _AmpProperty AmpProperty;
 
 GType         amp_project_get_type (void);
diff --git a/plugins/am-project/amp-root.c b/plugins/am-project/amp-root.c
new file mode 100644
index 0000000..2ef3458
--- /dev/null
+++ b/plugins/am-project/amp-root.c
@@ -0,0 +1,123 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4; coding: utf-8 -*- */
+/* am-root.c
+ *
+ * Copyright (C) 2010  Sébastien Granjoux
+ *
+ * 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 2 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "amp-root.h"
+
+#include "amp-node.h"
+#include "am-scanner.h"
+#include "am-properties.h"
+
+
+#include <libanjuta/interfaces/ianjuta-project.h>
+
+#include <libanjuta/anjuta-debug.h>
+
+#include <glib/gi18n.h>
+
+#include <memory.h>
+#include <string.h>
+#include <ctype.h>
+
+/* Types
+ *---------------------------------------------------------------------------*/
+
+
+
+
+
+/* Root object
+ *---------------------------------------------------------------------------*/
+
+gboolean
+amp_root_node_set_file (AmpRootNode *root, GFile *new_file)
+{
+	if (root->base.file != NULL) g_object_unref (root->base.file);
+	root->base.file = new_file != NULL ? g_object_ref (new_file) : NULL;
+
+	return TRUE;
+}
+
+AnjutaProjectNode*
+amp_root_node_new (GFile *file, GError **error)
+{
+	AmpRootNode *node = NULL;
+
+	node = g_object_new (AMP_TYPE_ROOT_NODE, NULL);
+	node->base.file = g_object_ref (file);
+
+	return ANJUTA_PROJECT_NODE (node);
+}
+
+void
+amp_root_node_free (AmpRootNode *node)
+{
+	g_object_unref (G_OBJECT (node));
+}
+
+
+/* GObjet implementation
+ *---------------------------------------------------------------------------*/
+
+G_DEFINE_DYNAMIC_TYPE (AmpRootNode, amp_root_node, AMP_TYPE_NODE);
+
+static void
+amp_root_node_init (AmpRootNode *node)
+{
+	node->base.type = ANJUTA_PROJECT_ROOT;
+	node->base.native_properties = amp_get_project_property_list();
+	node->base.state = ANJUTA_PROJECT_CAN_ADD_GROUP |
+						ANJUTA_PROJECT_CAN_ADD_PACKAGE,
+						ANJUTA_PROJECT_CAN_SAVE;
+}
+
+static void
+amp_root_node_finalize (GObject *object)
+{
+	AmpRootNode *node = AMP_ROOT_NODE (object);
+
+	g_list_foreach (node->base.custom_properties, (GFunc)amp_property_free, NULL);
+	G_OBJECT_CLASS (amp_root_node_parent_class)->finalize (object);
+}
+
+static void
+amp_root_node_class_init (AmpRootNodeClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	
+	object_class->finalize = amp_root_node_finalize;
+}
+
+static void
+amp_root_node_class_finalize (AmpRootNodeClass *klass)
+{
+}
+
+void
+amp_root_node_register (GTypeModule *module)
+{
+	amp_root_node_register_type (module);
+}
+
diff --git a/plugins/am-project/amp-root.h b/plugins/am-project/amp-root.h
new file mode 100644
index 0000000..76205d0
--- /dev/null
+++ b/plugins/am-project/amp-root.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4; coding: utf-8 -*- */
+/* amp-root.h
+ *
+ * Copyright (C) 2010  Sébastien Granjoux
+ *
+ * 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 2 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _AMP_ROOT_H_
+#define _AMP_ROOT_H_
+
+#include	"amp-node.h"
+
+#include <glib-object.h>
+
+#include <libanjuta/anjuta-project.h>
+#include <libanjuta/anjuta-token.h>
+#include <libanjuta/anjuta-token-file.h>
+
+G_BEGIN_DECLS
+
+/* Type macros
+ *---------------------------------------------------------------------------*/
+
+#define AMP_TYPE_ROOT_NODE						(amp_root_node_get_type ())
+#define AMP_ROOT_NODE(obj)						(G_TYPE_CHECK_INSTANCE_CAST ((obj), AMP_TYPE_ROOT_NODE, AmpRootNode))
+
+GType amp_root_node_get_type (void) G_GNUC_CONST;
+
+typedef struct _AmpRootNode					AmpRootNode;
+typedef struct _AmpRootNodeClass	AmpRootNodeClass;
+
+struct _AmpRootNode {
+	AnjutaProjectNode base;
+};
+
+struct _AmpRootNodeClass {
+	AmpNodeClass parent_class;
+};
+
+void amp_root_node_register (GTypeModule *module);
+
+AnjutaProjectNode* amp_root_node_new (GFile *file, GError **error);
+void amp_root_node_free (AmpRootNode *node);
+gboolean amp_root_node_set_file (AmpRootNode *source, GFile *new_file);
+
+
+G_END_DECLS
+
+#endif /* _AMP_ROOT_H_ */



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