[anjuta/newproject] Implement new IAnjutaProject interface without free_node function



commit 4dc3e6d03f8bcedbcf14384d69cf7037eecdd4c0
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Sat Sep 25 21:39:19 2010 +0200

    Implement new IAnjutaProject interface without free_node function

 libanjuta/interfaces/libanjuta.idl      |   70 +++++++++--
 plugins/am-project/am-node.c            |   13 ++-
 plugins/am-project/am-node.h            |    1 +
 plugins/am-project/am-project-private.h |    2 +-
 plugins/am-project/am-project.c         |  201 ++++++++++++++++++-------------
 plugins/am-project/am-project.h         |    2 +-
 plugins/am-project/plugin.c             |    5 +-
 plugins/am-project/projectparser.c      |   35 ++----
 plugins/dir-project/dir-project.c       |  107 ++++++++++-------
 plugins/dir-project/dir-project.h       |    2 +-
 plugins/dir-project/plugin.c            |    9 +-
 plugins/project-manager/project.c       |   94 +++++----------
 12 files changed, 311 insertions(+), 230 deletions(-)
---
diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index 6e8fec3..9919aa9 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -3113,9 +3113,9 @@ interface IAnjutaProject
 	 *
 	 * Reload a project node
 	 *
-	 * Return value: The newly loaded node, NULL if error
+	 * Return value: TRUE if the node has been loaded without error
 	 */
-	AnjutaProjectNode *load_node (AnjutaProjectNode *node);
+	gboolean load_node (AnjutaProjectNode *node);
 
 	/**
 	 * ianjuta_project_save_node:
@@ -3125,34 +3125,53 @@ interface IAnjutaProject
 	 *
 	 * Save a project node
 	 *
-	 * Return value: The saved node, NULL if error
+	 * Return value: TRUE if the node has been saved without error
 	 */
-	AnjutaProjectNode *save_node (AnjutaProjectNode *node);
+	gboolean save_node (AnjutaProjectNode *node);
 
 	/**
-	 * ianjuta_project_new_node:
+	 * ianjuta_project_add_node_after:
 	 * @obj: Self
 	 * @parent: Parent
+	 * @sibling: Sibling
 	 * @type: Node type
 	 * @file: Optional file object for the node
 	 * @name: Optional name for the node
 	 * @err: Error propagation and reporting
 	 *
-	 * Create a new node
+	 * Create a new node and insert it after sibling
 	 *
 	 * Return value: The new node, NULL if error
 	 */
-	AnjutaProjectNode *new_node (AnjutaProjectNode *parent, AnjutaProjectNodeType type, GFile *file, const gchar *name);
+	AnjutaProjectNode *add_node_after (AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNodeType type, GFile *file, const gchar *name);
 
 	/**
-	 * ianjuta_project_free_node:
+	 * ianjuta_project_add_node_before:
+	 * @obj: Self
+	 * @parent: Parent
+	 * @sibling: Sibling
+	 * @type: Node type
+	 * @file: Optional file object for the node
+	 * @name: Optional name for the node
+	 * @err: Error propagation and reporting
+	 *
+	 * Create a new node and insert it before sibling
+	 *
+	 * Return value: The new node, NULL if error
+	 */
+	AnjutaProjectNode *add_node_before (AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNodeType type, GFile *file, const gchar *name);
+
+	/**
+	 * ianjuta_project_remove_node:
 	 * @obj: Self
 	 * @node: Node
 	 * @err: Error propagation and reporting
 	 *
-	 * Free an already existing node
+	 * Remove a node
+	 *
+	 * Return value: TRUE if the node can be removed
 	 */
-	void free_node (AnjutaProjectNode *node);
+	gboolean remove_node (AnjutaProjectNode *node);
 
 	/**
 	 * ianjuta_project_set_property:
@@ -3169,6 +3188,30 @@ interface IAnjutaProject
 	gboolean set_property (AnjutaProjectNode *parent, AnjutaProjectProperty* property, const gchar *value);
 
 	/**
+	 * ianjuta_project_remove_property:
+	 * @obj: Self
+	 * @node: Node
+	 * @property: Property
+	 * @err: Error propagation and reporting
+	 *
+	 * Remove a property of the node
+	 *
+	 * Return value: TRUE if the node can be removed
+	 */
+	gboolean remove_property (AnjutaProjectNode *node, AnjutaProjectProperty* property);
+
+	/**
+	 * ianjuta_project_get_root:
+	 * @obj: Self
+	 * @err: Error propagation and reporting
+	 *
+	 * Get root_node
+	 *
+	 * Return value: The root node
+	 */
+	AnjutaProjectNode *get_root ();
+
+	/**
 	 * ianjuta_project_get_node_info:
 	 * @obj: Self
 	 * @err: Error propagation and reporting
@@ -3197,19 +3240,20 @@ interface IAnjutaProjectBackend
 	/**
 	 * ianjuta_project_backend_new_project:
 	 * @obj: Self
+	 * @file: Project file or directory
 	 * @err: Error propagation and reporting
 	 *
-	 * Get a new GbfProject
+	 * Get a new Anjuta project.
 	 *
 	 * Return value: An object derived from GbfProject
 	 */
-	IAnjutaProject* new_project ();
+	IAnjutaProject* new_project (GFile *file);
 
 	
 	/**
 	 * ianjuta_project_backend_probe:
 	 * @obj: Self
-	 * @file: Project directory
+	 * @file: Project file or directory
 	 * @err: Error propagation and reporting
 	 *
 	 * Check if the directory contains a project supported by this
diff --git a/plugins/am-project/am-node.c b/plugins/am-project/am-node.c
index a6a2a3a..b9cfd92 100644
--- a/plugins/am-project/am-node.c
+++ b/plugins/am-project/am-node.c
@@ -138,6 +138,16 @@ amp_root_free (AnjutaAmRootNode *node)
 	g_object_unref (G_OBJECT (node));
 }
 
+void
+amp_root_clear (AnjutaAmRootNode *node)
+{
+	if (node->configure_file != NULL) anjuta_token_file_free (node->configure_file);
+	node->configure_file = NULL;
+	
+	g_list_foreach (node->base.custom_properties, (GFunc)amp_property_free, NULL);
+	node->base.custom_properties = NULL;
+}
+
 AnjutaTokenFile*
 amp_root_set_configure (AnjutaProjectNode *node, GFile *configure)
 {
@@ -172,8 +182,7 @@ anjuta_am_root_node_finalize (GObject *object)
 {
 	AnjutaAmRootNode *root = ANJUTA_AM_ROOT_NODE (object);
 
-	if (root->configure_file != NULL) anjuta_token_file_free (root->configure_file);
-	g_list_foreach (root->base.custom_properties, (GFunc)amp_property_free, NULL);
+	amp_root_clear (root);
 	
 	G_OBJECT_CLASS (anjuta_am_root_node_parent_class)->finalize (object);
 }
diff --git a/plugins/am-project/am-node.h b/plugins/am-project/am-node.h
index 83ab1ab..94cf77d 100644
--- a/plugins/am-project/am-node.h
+++ b/plugins/am-project/am-node.h
@@ -45,6 +45,7 @@ AmpVariable* amp_variable_new (gchar *name, AnjutaTokenType assign, AnjutaToken
 
 AnjutaProjectNode* amp_root_new (GFile *file, GError **error);
 void amp_root_free (AnjutaAmRootNode *node);
+void amp_root_clear (AnjutaAmRootNode *node);
 AnjutaTokenFile* amp_root_set_configure (AnjutaProjectNode *node, GFile *configure);
 
 AnjutaProjectNode* amp_module_new (AnjutaToken *token, GError **error);
diff --git a/plugins/am-project/am-project-private.h b/plugins/am-project/am-project-private.h
index dfdebe6..59def9d 100644
--- a/plugins/am-project/am-project-private.h
+++ b/plugins/am-project/am-project-private.h
@@ -50,7 +50,7 @@ struct _AmpProject {
 
 	/* uri of the project; this can be a full uri, even though we
 	 * can only work with native local files */
-	GFile			*root_file;
+	AnjutaProjectNode			*root;
 
 	/* project data */
 	AnjutaTokenFile		*configure_file;		/* configure.in file */
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index aabf2d1..467f59f 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -668,7 +668,7 @@ amp_group_fill_token (AmpProject  *project, AnjutaAmGroupNode *group, GError **e
 		}
 		//prev_token = (AnjutaToken *)token_list->data;
 
-		relative_make = g_file_get_relative_path (project->root_file, makefile);
+		relative_make = g_file_get_relative_path (anjuta_project_node_get_file (project->root), makefile);
 		ext = relative_make + strlen (relative_make) - 3;
 		if (strcmp (ext, ".am") == 0)
 		{
@@ -1098,7 +1098,7 @@ foreach_node_destroy (AnjutaProjectNode    *g_node,
 			amp_package_free (g_node);
 			break;
 		case ANJUTA_PROJECT_ROOT:
-			amp_root_free (g_node);
+			amp_root_clear (g_node);
 			break;
 		default:
 			g_assert_not_reached ();
@@ -1188,7 +1188,7 @@ project_node_save (AmpProject *project, AnjutaProjectNode *g_node, GError **erro
 	switch (AMP_NODE_DATA (g_node)->type & ANJUTA_PROJECT_TYPE_MASK) {
 		case ANJUTA_PROJECT_GROUP:
 			g_hash_table_insert (files, AMP_GROUP_DATA (g_node)->tfile, NULL);
-			g_hash_table_insert (files, AMP_ROOT_DATA (project->root_node)->configure_file, NULL);
+			g_hash_table_insert (files, AMP_ROOT_DATA (project->root)->configure_file, NULL);
 			break;
 		case ANJUTA_PROJECT_TARGET:
 		case ANJUTA_PROJECT_SOURCE:
@@ -1198,7 +1198,7 @@ project_node_save (AmpProject *project, AnjutaProjectNode *g_node, GError **erro
 		case ANJUTA_PROJECT_MODULE:
 		case ANJUTA_PROJECT_PACKAGE:
 			/* Save only configure file */
-			g_hash_table_insert (files, AMP_ROOT_DATA (project->root_node)->configure_file, NULL);
+			g_hash_table_insert (files, AMP_ROOT_DATA (project->root)->configure_file, NULL);
 			break;
 		case ANJUTA_PROJECT_ROOT:
 			/* Get all project files */
@@ -1236,7 +1236,7 @@ amp_project_load_properties (AmpProject *project, AnjutaToken *macro, AnjutaToke
 	project->ac_init = macro;
 	project->args = args;
 
-	for (item = anjuta_project_node_get_native_properties (project->root_node); item != NULL; item = g_list_next (item))
+	for (item = anjuta_project_node_get_native_properties (project->root); item != NULL; item = g_list_next (item))
 	{
 		AmpProperty *prop = (AmpProperty *)item->data;
 
@@ -1245,20 +1245,20 @@ amp_project_load_properties (AmpProject *project, AnjutaToken *macro, AnjutaToke
 			AnjutaProjectProperty *new_prop;
 			AnjutaToken *arg;
 
-			new_prop = anjuta_project_node_remove_property (project->root_node, prop);
+			new_prop = anjuta_project_node_remove_property (project->root, prop);
 			if (new_prop != NULL)
 			{
 				amp_property_free (new_prop);
 			}
 			new_prop = amp_property_new (NULL, prop->token_type, prop->position, NULL, macro);
-			anjuta_project_node_insert_property (project->root_node, prop, new_prop);
+			anjuta_project_node_insert_property (project->root, prop, new_prop);
 
 			arg = anjuta_token_nth_word (args, prop->position);
 			if ((new_prop->value != NULL) && (new_prop->value != prop->base.value)) g_free (new_prop->value);
 			new_prop->value = anjuta_token_evaluate (arg);
 		}
 	}
-	//g_message ("prop list %p get prop %p", *list, anjuta_project_node_get_property (project->root_node));
+	//g_message ("prop list %p get prop %p", *list, anjuta_project_node_get_property (project->root);
 }
 
 void
@@ -1281,7 +1281,7 @@ amp_project_load_module (AmpProject *project, AnjutaToken *module_token)
 		arg = anjuta_token_first_item (module_token);
 		value = anjuta_token_evaluate (arg);
 		module = amp_module_new (arg, NULL);
-		anjuta_project_node_append (project->root_node, module);
+		anjuta_project_node_append (project->root, module);
 		if (value != NULL) g_hash_table_insert (project->modules, value, module);
 
 		/* Package list */
@@ -1359,7 +1359,7 @@ amp_project_load_config (AmpProject *project, AnjutaToken *arg_list)
 			value = anjuta_token_evaluate (item);
 			if (value == NULL) continue;
 		
-			cfg = amp_config_file_new (value, project->root_file, item);
+			cfg = amp_config_file_new (value, anjuta_project_node_get_file (project->root), item);
 			g_hash_table_insert (project->configs, cfg->file, cfg);
 			g_free (value);
 		}
@@ -1915,7 +1915,7 @@ amp_project_get_type_info (AmpProject *project, AnjutaProjectNodeType type)
 }
 
 static AnjutaProjectNode *
-amp_project_load_root (AmpProject *project, AnjutaProjectNode *node, GError **error) 
+amp_project_load_root (AmpProject *project, GError **error) 
 {
 	AmpAcScanner *scanner;
 	AnjutaToken *arg;
@@ -1929,9 +1929,7 @@ amp_project_load_root (AmpProject *project, AnjutaProjectNode *node, GError **er
 	amp_project_unload (project);
 	DEBUG_PRINT ("reload project %p root file %p", project, root_file);
 
-	root_file = g_object_ref (anjuta_project_node_get_file (node));
-	project->root_file = root_file;
-	project->root_node = node;
+	root_file = anjuta_project_node_get_file (project->root);
 
 	/* shortcut hash tables */
 	project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
@@ -1963,7 +1961,7 @@ amp_project_load_root (AmpProject *project, AnjutaProjectNode *node, GError **er
 	}
 
 	/* Parse configure */
-	project->configure_file = amp_root_set_configure (node, configure_file);
+	project->configure_file = amp_root_set_configure (project->root, configure_file);
 	g_hash_table_insert (project->files, configure_file, project->configure_file);
 	g_object_add_toggle_ref (G_OBJECT (project->configure_file), remove_config_file, project);
 	arg = anjuta_token_file_load (project->configure_file, NULL);
@@ -1989,7 +1987,7 @@ amp_project_load_root (AmpProject *project, AnjutaProjectNode *node, GError **er
 	/* Load all makefiles recursively */
 	group = amp_group_new (root_file, FALSE, NULL);
 	g_hash_table_insert (project->groups, g_file_get_uri (root_file), group);
-	anjuta_project_node_append (node, group);
+	anjuta_project_node_append (project->root, group);
 	
 	if (project_load_makefile (project, group) == NULL)
 	{
@@ -2000,7 +1998,7 @@ amp_project_load_root (AmpProject *project, AnjutaProjectNode *node, GError **er
 		return NULL;
 	}
 
-	return node;
+	return project->root;
 }
 
 static void
@@ -2118,7 +2116,7 @@ amp_project_load_node (AmpProject *project, AnjutaProjectNode *node, GError **er
 	switch (anjuta_project_node_get_node_type (node))
 	{
 	case ANJUTA_PROJECT_ROOT:
-		return amp_project_load_root (project, node, error);
+		return amp_project_load_root (project, error);
 	case ANJUTA_PROJECT_PACKAGE:
 		return amp_project_load_package (project, node, error);
 	case ANJUTA_PROJECT_GROUP:
@@ -2128,37 +2126,16 @@ amp_project_load_node (AmpProject *project, AnjutaProjectNode *node, GError **er
 	}
 }
 
-gboolean
-amp_project_load (AmpProject  *project,
-    GFile *directory,
-	GError     **error)
-{
-	g_return_val_if_fail (directory != NULL, FALSE);
-
-	project->root_file = g_object_ref (directory);
-	/*if (!amp_project_reload (project, error))
-	{
-		g_object_unref (project->root_file);
-		project->root_file = NULL;
-	}*/
-
-	return project->root_file != NULL;
-}
-
 void
 amp_project_unload (AmpProject *project)
 {
 	/* project data */
-	//project_node_destroy (project, project->root_node);
-	project->root_node = NULL;
+	if (project->root) project_node_destroy (project, project->root);
 
 	if (project->configure_file)	g_object_unref (G_OBJECT (project->configure_file));
 	project->configure_file = NULL;
 	if (project->configure_token) anjuta_token_free (project->configure_token);
 
-	if (project->root_file) g_object_unref (project->root_file);
-	project->root_file = NULL;
-
 	g_list_foreach (project->properties, (GFunc)amp_property_free, NULL);
 	project->properties = amp_get_project_property_list ();
 	
@@ -2347,6 +2324,7 @@ foreach_node_move (AnjutaProjectNode *g_node, gpointer data)
 {
 	AmpProject *project = ((AmpMovePacket *)data)->project;
 	const gchar *old_root_file = ((AmpMovePacket *)data)->old_root_file;
+	GFile *root_file = anjuta_project_node_get_file (project->root);
 	GFile *relative;
 	GFile *new_file;
 	
@@ -2354,7 +2332,7 @@ foreach_node_move (AnjutaProjectNode *g_node, gpointer data)
 	{
 	case ANJUTA_PROJECT_GROUP:
 		relative = get_relative_path (old_root_file, AMP_GROUP_DATA (g_node)->base.file);
-		new_file = g_file_resolve_relative_path (project->root_file, relative);
+		new_file = g_file_resolve_relative_path (root_file, relative);
 		g_free (relative);
 		g_object_unref (AMP_GROUP_DATA (g_node)->base.file);
 		AMP_GROUP_DATA (g_node)->base.file = new_file;
@@ -2363,14 +2341,14 @@ foreach_node_move (AnjutaProjectNode *g_node, gpointer data)
 		break;
 	case ANJUTA_PROJECT_SOURCE:
 		relative = get_relative_path (old_root_file, AMP_SOURCE_DATA (g_node)->base.file);
-		new_file = g_file_resolve_relative_path (project->root_file, relative);
+		new_file = g_file_resolve_relative_path (root_file, relative);
 		g_free (relative);
 		g_object_unref (AMP_SOURCE_DATA (g_node)->base.file);
 		AMP_SOURCE_DATA (g_node)->base.file = new_file;
 		break;
 	case ANJUTA_PROJECT_ROOT:
 		relative = get_relative_path (old_root_file, AMP_GROUP_DATA (g_node)->base.file);
-		new_file = g_file_resolve_relative_path (project->root_file, relative);
+		new_file = g_file_resolve_relative_path (root_file, relative);
 		g_free (relative);
 		g_object_unref (AMP_ROOT_DATA (g_node)->base.file);
 		AMP_ROOT_DATA (g_node)->base.file = new_file;
@@ -2384,6 +2362,7 @@ gboolean
 amp_project_move (AmpProject *project, const gchar *path)
 {
 	GFile *new_file;
+	GFile *root_file;
 	gchar *relative;
 	GHashTableIter iter;
 	gpointer key;
@@ -2393,13 +2372,15 @@ amp_project_move (AmpProject *project, const gchar *path)
 	AmpMovePacket packet= {project, NULL};
 
 	/* Change project root directory */
-	packet.old_root_file = project->root_file;
-	project->root_file = g_file_new_for_path (path);
+	packet.old_root_file = g_object_ref (anjuta_project_node_get_file (project->root));
+	root_file = g_file_new_for_path (path);
+	g_object_unref (AMP_ROOT_DATA (project->root)->base.file);
+	AMP_ROOT_DATA (project->root)->base.file = g_object_ref (root_file);
 
 	/* Change project root directory in groups */
 	old_hash = project->groups;
 	project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-	anjuta_project_node_foreach (project->root_node, G_POST_ORDER, foreach_node_move, &packet);
+	anjuta_project_node_foreach (project->root, G_POST_ORDER, foreach_node_move, &packet);
 	g_hash_table_destroy (old_hash);
 
 	/* Change all files */
@@ -2409,7 +2390,7 @@ amp_project_move (AmpProject *project, const gchar *path)
 	while (g_hash_table_iter_next (&iter, &key, (gpointer *)&tfile))
 	{
 		relative = get_relative_path (packet.old_root_file, anjuta_token_file_get_file (tfile));
-		new_file = g_file_resolve_relative_path (project->root_file, relative);
+		new_file = g_file_resolve_relative_path (root_file, relative);
 		g_free (relative);
 		anjuta_token_file_move (tfile, new_file);
 		
@@ -2426,7 +2407,7 @@ amp_project_move (AmpProject *project, const gchar *path)
 	while (g_hash_table_iter_next (&iter, &key, (gpointer *)&cfg))
 	{
 		relative = get_relative_path (packet.old_root_file, cfg->file);
-		new_file = g_file_resolve_relative_path (project->root_file, relative);
+		new_file = g_file_resolve_relative_path (root_file, relative);
 		g_free (relative);
 		g_object_unref (cfg->file);
 		cfg->file = new_file;
@@ -2436,16 +2417,22 @@ amp_project_move (AmpProject *project, const gchar *path)
 	g_hash_table_steal_all (old_hash);
 	g_hash_table_destroy (old_hash);
 
-	
+
+	g_object_unref (root_file);
 	g_object_unref (packet.old_root_file);
 
 	return TRUE;
 }
 
 AmpProject *
-amp_project_new (void)
+amp_project_new (GFile *file, GError **error)
 {
-	return AMP_PROJECT (g_object_new (AMP_TYPE_PROJECT, NULL));
+	AmpProject *project;
+	
+	project = AMP_PROJECT (g_object_new (AMP_TYPE_PROJECT, NULL));
+	project->root = amp_root_new (file, error);
+
+	return project;
 }
 
 /* Project access functions
@@ -2455,15 +2442,8 @@ AnjutaAmRootNode *
 amp_project_get_root (AmpProject *project)
 {
 	AnjutaAmRootNode *g_node = NULL;
-	
-	if (project->root_file != NULL)
-	{
-		gchar *id = g_file_get_uri (project->root_file);
-		g_node = ANJUTA_AM_ROOT_NODE (g_hash_table_lookup (project->groups, id));
-		g_free (id);
-	}
 
-	return g_node;
+	return ANJUTA_AM_ROOT_NODE (project->root);
 }
 
 AnjutaAmGroupNode *
@@ -2520,7 +2500,7 @@ amp_project_get_node_id (AmpProject *project, const gchar *path)
 
 			if (node == NULL)
 			{
-				if (child == 0) node = project->root_node;
+				if (child == 0) node = project->root;
 			}
 			else
 			{
@@ -2554,7 +2534,7 @@ amp_project_get_uri (AmpProject *project)
 {
 	g_return_val_if_fail (project != NULL, NULL);
 
-	return project->root_file != NULL ? g_file_get_uri (project->root_file) : NULL;
+	return project->root != NULL ? g_file_get_uri (anjuta_project_node_get_file (project->root)) : NULL;
 }
 
 GFile*
@@ -2562,7 +2542,7 @@ amp_project_get_file (AmpProject *project)
 {
 	g_return_val_if_fail (project != NULL, NULL);
 
-	return project->root_file;
+	return anjuta_project_node_get_file (project->root);
 }
 
 AnjutaProjectProperty *
@@ -2636,15 +2616,21 @@ amp_project_set_property (AmpProject *project, AmpPropertyType type, const gchar
 /* Implement IAnjutaProject
  *---------------------------------------------------------------------------*/
 
-static AnjutaProjectNode *
+static gboolean
 iproject_load_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
 {
-	return amp_project_load_node (AMP_PROJECT (obj), node, err);
+	if (node == NULL) node = AMP_PROJECT (obj)->root;
+	
+	node = amp_project_load_node (AMP_PROJECT (obj), node, err);
+
+	return node != NULL;
 }
 
-static AnjutaProjectNode *
+static gboolean
 iproject_save_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **error)
 {
+	if (node == NULL) node = AMP_PROJECT (obj)->root;
+	
 	switch (anjuta_project_node_get_node_type (node))
 	{
 		case ANJUTA_PROJECT_ROOT:
@@ -2673,22 +2659,37 @@ iproject_save_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **error
 			break;
 	}
 	
-	return node;
+	return node != NULL;
 }
 
-static gboolean
-iproject_set_property (IAnjutaProject *obj, AnjutaProjectNode *node, AnjutaProjectProperty *property, const gchar *value, GError **error)
+static AnjutaProjectNode *
+iproject_add_node_before (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNodeType type, GFile *file, const gchar *name, GError **err)
 {
-	AnjutaProjectProperty *new_prop;
+	AnjutaProjectNode *node;
+	GFile *directory = NULL;
 	
-	new_prop = amp_node_property_set (node, property, value);
-	amp_project_update_property (AMP_PROJECT (obj), new_prop);
+	switch (type & ANJUTA_PROJECT_TYPE_MASK)
+	{
+		case ANJUTA_PROJECT_GROUP:
+			if ((file == NULL) && (name != NULL))
+			{
+				directory = g_file_get_child (AMP_GROUP_DATA (parent)->base.file, name);
+				file = directory;
+			}
+			node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+			if (directory != NULL) g_object_unref (directory);
+			break;
+		default:
+				node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+				break;
+	}
+	anjuta_project_node_insert_before (parent, sibling, node);
 	
-	return TRUE;
+	return node;
 }
 
 static AnjutaProjectNode *
-iproject_new_node (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaProjectNodeType type, GFile *file, const gchar *name, GError **err)
+iproject_add_node_after (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNodeType type, GFile *file, const gchar *name, GError **err)
 {
 	AnjutaProjectNode *node;
 	GFile *directory = NULL;
@@ -2708,15 +2709,45 @@ iproject_new_node (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaProject
 				node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
 				break;
 	}
-	node->parent = parent;
+	anjuta_project_node_insert_after (parent, sibling, node);
 	
 	return node;
 }
 
-static void
-iproject_free_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
+static gboolean
+iproject_remove_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
+{
+	anjuta_project_node_set_state (node, ANJUTA_PROJECT_REMOVED);
+
+	return TRUE;
+}
+
+static gboolean
+iproject_set_property (IAnjutaProject *obj, AnjutaProjectNode *node, AnjutaProjectProperty *property, const gchar *value, GError **error)
 {
-	project_node_destroy (AMP_PROJECT (obj), node);
+	AnjutaProjectProperty *new_prop;
+	
+	new_prop = amp_node_property_set (node, property, value);
+	amp_project_update_property (AMP_PROJECT (obj), new_prop);
+	
+	return TRUE;
+}
+
+static gboolean
+iproject_remove_property (IAnjutaProject *obj, AnjutaProjectNode *node, AnjutaProjectProperty *property, GError **error)
+{
+	AnjutaProjectProperty *old_prop;
+
+	old_prop = anjuta_project_node_remove_property (node, property);
+	amp_property_free (old_prop);
+	
+	return TRUE;
+}
+
+static AnjutaProjectNode *
+iproject_get_root (IAnjutaProject *obj, GError **err)
+{
+	return AMP_PROJECT (obj)->root;
 }
 
 static GList* 
@@ -2730,9 +2761,12 @@ iproject_iface_init(IAnjutaProjectIface* iface)
 {
 	iface->load_node = iproject_load_node;
 	iface->save_node = iproject_save_node;
+	iface->add_node_before = iproject_add_node_before;
+	iface->add_node_after = iproject_add_node_after;
+	iface->remove_node = iproject_remove_node;
 	iface->set_property = iproject_set_property;
-	iface->new_node = iproject_new_node;
-	iface->free_node = iproject_free_node;
+	iface->remove_property = iproject_remove_property;
+	iface->get_root = iproject_get_root;
 	iface->get_node_info = iproject_get_node_info;
 }
 
@@ -2844,9 +2878,13 @@ amp_source_get_file (AnjutaAmSourceNode *source)
 static void
 amp_project_dispose (GObject *object)
 {
+	AmpProject *project;
+	
 	g_return_if_fail (AMP_IS_PROJECT (object));
 
-	amp_project_unload (AMP_PROJECT (object));
+	project = AMP_PROJECT (object);
+	amp_project_unload (project);
+	if (project->root) amp_root_free (project->root);
 
 	G_OBJECT_CLASS (parent_class)->dispose (object);	
 }
@@ -2858,10 +2896,9 @@ amp_project_instance_init (AmpProject *project)
 	g_return_if_fail (AMP_IS_PROJECT (project));
 	
 	/* project data */
-	project->root_file = NULL;
+	project->root = NULL;
 	project->configure_file = NULL;
 	project->configure_token = NULL;
-	project->root_node = NULL;
 	project->properties = amp_get_project_property_list ();
 	project->ac_init = NULL;
 	project->args = NULL;
diff --git a/plugins/am-project/am-project.h b/plugins/am-project/am-project.h
index 03be24b..4573d26 100644
--- a/plugins/am-project/am-project.h
+++ b/plugins/am-project/am-project.h
@@ -66,7 +66,7 @@ typedef struct _AmpPropertyInfo   AmpPropertyInfo;
 typedef struct _AmpTargetPropertyBuffer AmpTargetPropertyBuffer;
 
 GType         amp_project_get_type (void);
-AmpProject   *amp_project_new      (void);
+AmpProject   *amp_project_new      (GFile *file, GError **error);
 
 
 AmpTargetPropertyBuffer* amp_target_property_buffer_new (void);
diff --git a/plugins/am-project/plugin.c b/plugins/am-project/plugin.c
index d8d5809..404e433 100644
--- a/plugins/am-project/plugin.c
+++ b/plugins/am-project/plugin.c
@@ -52,11 +52,12 @@ deactivate_plugin (AnjutaPlugin *plugin)
  *---------------------------------------------------------------------------*/
 
 static IAnjutaProject*
-iproject_backend_new_project (IAnjutaProjectBackend* backend, GError** err)
+iproject_backend_new_project (IAnjutaProjectBackend* backend, GFile *file, GError** err)
 {
 	IAnjutaProject *project;
 	DEBUG_PRINT("create new amp project");	
-	project = (IAnjutaProject *)(g_object_new (AMP_TYPE_PROJECT, NULL));
+
+	project = (IAnjutaProject *)amp_project_new (file, err);
 		
 	return project;
 }
diff --git a/plugins/am-project/projectparser.c b/plugins/am-project/projectparser.c
index 7d8c463..7b13705 100644
--- a/plugins/am-project/projectparser.c
+++ b/plugins/am-project/projectparser.c
@@ -415,12 +415,12 @@ main(int argc, char *argv[])
 				}
 				else
 				{
-					project = IANJUTA_PROJECT (g_object_new (type, NULL));
+					project = amp_project_new (file, NULL);
 				}
 			}
 
-			root = ianjuta_project_new_node (project, NULL, ANJUTA_PROJECT_ROOT, file, NULL, &error);
-			root = ianjuta_project_load_node (project, root, &error);
+			root = ianjuta_project_get_root (project, &error);
+			ianjuta_project_load_node (project, root, &error);
 			g_object_unref (file);
 		}
 		else if (g_ascii_strcasecmp (*command, "list") == 0)
@@ -441,7 +441,7 @@ main(int argc, char *argv[])
 		else if (g_ascii_strcasecmp (*command, "remove") == 0)
 		{
 			node = get_node (project, root, *(++command));
-			anjuta_project_node_set_state (node, ANJUTA_PROJECT_REMOVED);
+			ianjuta_project_remove_node (project, node, NULL);
 			ianjuta_project_save_node (project, child, NULL);
 		}
 		else if (g_ascii_strcasecmp (command[0], "add") == 0)
@@ -453,23 +453,20 @@ main(int argc, char *argv[])
 				if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
 				{
 					sibling = get_node (project, root, command[5]);
-					child = ianjuta_project_new_node (project, node, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
-					anjuta_project_node_insert_before (node, sibling, child);
+					child = ianjuta_project_add_node_before (project, node, sibling, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
 					ianjuta_project_save_node (project, child, NULL);
 					command += 2;
 				}
 				else if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "after") == 0))
 				{
 					sibling = get_node (project, root, command[5]);
-					child = ianjuta_project_new_node (project, node, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
-					anjuta_project_node_insert_after (node, sibling, child);
+					child = ianjuta_project_add_node_after (project, node, sibling, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
 					ianjuta_project_save_node (project, child, NULL);
 					command += 2;
 				}
 				else
 				{
-					child = ianjuta_project_new_node (project, node, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
-					anjuta_project_node_insert_after (node, NULL, child);
+					child = ianjuta_project_add_node_after (project, node, NULL, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
 					ianjuta_project_save_node (project, child, NULL);
 				}
 			}
@@ -478,23 +475,20 @@ main(int argc, char *argv[])
 				if ((command[5] != NULL) && (g_ascii_strcasecmp (command[5], "before") == 0))
 				{
 					sibling = get_node (project, root, command[6]);
-					child = ianjuta_project_new_node (project, node, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
-					anjuta_project_node_insert_before (node, sibling, child);
+					child = ianjuta_project_add_node_before (project, node, sibling, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
 					ianjuta_project_save_node (project, child, NULL);
 					command += 2;
 				}
 				else if ((command[5] != NULL) && (g_ascii_strcasecmp (command[5], "after") == 0))
 				{
 					sibling = get_node (project, root, command[6]);
-					child = ianjuta_project_new_node (project, node, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
-					anjuta_project_node_insert_after (node, sibling, child);
+					child = ianjuta_project_add_node_after (project, node, sibling, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
 					ianjuta_project_save_node (project, child, NULL);
 					command += 2;
 				}
 				else
 				{
-					child = ianjuta_project_new_node (project, node, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
-					anjuta_project_node_insert_after (node, NULL, child);
+					child = ianjuta_project_add_node_after (project, node, NULL, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
 					ianjuta_project_save_node (project, child, NULL);
 				}
 				command++;
@@ -506,23 +500,20 @@ main(int argc, char *argv[])
 				if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
 				{
 					sibling = get_node (project, root, command[5]);
-					child = ianjuta_project_new_node (project, node, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
-					anjuta_project_node_insert_before (node, sibling, child);
+					child = ianjuta_project_add_node_before (project, node, sibling, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
 					ianjuta_project_save_node (project, child, NULL);
 					command += 2;
 				}
 				else if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "after") == 0))
 				{
 					sibling = get_node (project, root, command[5]);
-					child = ianjuta_project_new_node (project, node, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
-					anjuta_project_node_insert_after (node, sibling, child);
+					child = ianjuta_project_add_node_after (project, node, sibling, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
 					ianjuta_project_save_node (project, child, NULL);
 					command += 2;
 				}
 				else
 				{
-					child = ianjuta_project_new_node (project, node, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
-					anjuta_project_node_insert_after (node, NULL, child);
+					child = ianjuta_project_add_node_after (project, node, NULL, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
 					ianjuta_project_save_node (project, child, NULL);
 				}
 				g_object_unref (file);
diff --git a/plugins/dir-project/dir-project.c b/plugins/dir-project/dir-project.c
index 5e5a7a0..9421c9a 100644
--- a/plugins/dir-project/dir-project.c
+++ b/plugins/dir-project/dir-project.c
@@ -49,7 +49,7 @@
 struct _DirProject {
 	GObject         parent;
 
-	GFile			*root_file;
+	AnjutaProjectNode *root;
 
 	/* shortcut hash tables, mapping id -> GNode from the tree above */
 	GHashTable		*groups;
@@ -525,16 +525,14 @@ dir_project_load_directory (DirProject *project, AnjutaProjectNode *parent, GErr
 }
  
 static AnjutaProjectNode *
-dir_project_load_root (DirProject *project, AnjutaProjectNode *node, GError **error) 
+dir_project_load_root (DirProject *project, GError **error) 
 {
-	GFile *root_file;
 	GFile *source_file;
+	GFile *root_file;
 	AnjutaProjectNode *group;
 
-	root_file = g_object_ref (anjuta_project_node_get_file (node));
+	root_file = anjuta_project_node_get_file (project->root);
 	DEBUG_PRINT ("reload project %p root file %p", project, root_file);
-	project->root_file = root_file;
-	//project->root_node = node;
 
 	/* shortcut hash tables */
 	project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
@@ -549,7 +547,7 @@ dir_project_load_root (DirProject *project, AnjutaProjectNode *node, GError **er
 	}
 
 	group = project_node_new (project, NULL, ANJUTA_PROJECT_GROUP, root_file, NULL, NULL);
-	anjuta_project_node_append (node, group);
+	anjuta_project_node_append (project->root, group);
 	g_hash_table_insert (project->groups, g_file_get_uri (root_file), group);
 
 	/* Load source pattern */
@@ -559,16 +557,17 @@ dir_project_load_root (DirProject *project, AnjutaProjectNode *node, GError **er
 	
 	dir_project_load_directory (project, group, NULL);
 
-	return node;
+	return project->root;
 }
 
 AnjutaProjectNode *
 dir_project_load_node (DirProject *project, AnjutaProjectNode *node, GError **error) 
 {
+	if (node == NULL) node = project->root;
 	switch (anjuta_project_node_get_node_type (node))
 	{
 	case ANJUTA_PROJECT_ROOT:
-		return dir_project_load_root (project, node, error);
+		return dir_project_load_root (project, error);
 	case ANJUTA_PROJECT_GROUP:
 		return dir_project_load_directory (project, node, error);
 	default:
@@ -623,23 +622,6 @@ dir_project_save_node (DirProject *project, AnjutaProjectNode *node, GError **er
 	return node;
 }
 
-gboolean
-dir_project_load (DirProject  *project,
-    GFile *directory,
-	GError     **error)
-{
-	g_return_val_if_fail (directory != NULL, FALSE);
-
-	/*project->root_file = g_object_ref (directory);
-	if (!dir_project_reload (project, error))
-	{
-		g_object_unref (project->root_file);
-		project->root_file = NULL;
-	}*/
-
-	return project->root_file != NULL;
-}
-
 void
 dir_project_unload (DirProject *project)
 {
@@ -647,8 +629,8 @@ dir_project_unload (DirProject *project)
 	/*project_node_destroy (project, project->root_node);
 	project->root_node = NULL;*/
 
-	if (project->root_file) g_object_unref (project->root_file);
-	project->root_file = NULL;
+	if (project->root) project_node_destroy (project, project->root);
+	project->root = NULL;
 
 	/* shortcut hash tables */
 	if (project->groups) g_hash_table_destroy (project->groups);
@@ -713,42 +695,66 @@ dir_project_get_node_info (DirProject *project, GError **error)
  *---------------------------------------------------------------------------*/
 
 DirProject *
-dir_project_new (void)
+dir_project_new (GFile *directory, GError **error)
 {
-	return DIR_PROJECT (g_object_new (DIR_TYPE_PROJECT, NULL));
+	DirProject *project;
+	
+	project = DIR_PROJECT (g_object_new (DIR_TYPE_PROJECT, NULL));
+	project->root = dir_root_node_new (directory);
+
+	return project;
 }
 
 
 /* Implement IAnjutaProject
  *---------------------------------------------------------------------------*/
 
-static AnjutaProjectNode *
+static gboolean
 iproject_load_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
 {
-	return dir_project_load_node (DIR_PROJECT (obj), node, err);
+	node = dir_project_load_node (DIR_PROJECT (obj), node, err);
+
+	return node != NULL;
 }
 
-static AnjutaProjectNode *
+static gboolean
 iproject_save_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
 {
-	return dir_project_save_node (DIR_PROJECT (obj), node, err);
+	node = dir_project_save_node (DIR_PROJECT (obj), node, err);
+
+	return node != NULL;
 }
 
 static AnjutaProjectNode *
-iproject_new_node (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaProjectNodeType type, GFile *file, const gchar *name, GError **error)
+iproject_add_node_before (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNodeType type, GFile *file, const gchar *name, GError **error)
 {
 	AnjutaProjectNode *node;
 	
 	node = project_node_new (DIR_PROJECT (obj), parent, type, file, name, error);
 	anjuta_project_node_set_state (node, ANJUTA_PROJECT_MODIFIED);
+	anjuta_project_node_insert_before (parent, sibling, node);
 	
 	return node;
 }
 
-static void
-iproject_free_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
+static AnjutaProjectNode *
+iproject_add_node_after (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNodeType type, GFile *file, const gchar *name, GError **error)
 {
-	project_node_destroy (DIR_PROJECT (obj), node);
+	AnjutaProjectNode *node;
+	
+	node = project_node_new (DIR_PROJECT (obj), parent, type, file, name, error);
+	anjuta_project_node_set_state (node, ANJUTA_PROJECT_MODIFIED);
+	anjuta_project_node_insert_after (parent, sibling, node);
+	
+	return node;
+}
+
+static gboolean
+iproject_remove_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
+{
+	anjuta_project_node_set_state (node, ANJUTA_PROJECT_REMOVED);
+
+	return TRUE;
 }
 
 static gboolean
@@ -761,6 +767,22 @@ iproject_set_property (IAnjutaProject *obj, AnjutaProjectNode *node, AnjutaProje
 	return FALSE;
 }
 
+static gboolean
+iproject_remove_property (IAnjutaProject *obj, AnjutaProjectNode *node, AnjutaProjectProperty *property, GError **error)
+{
+	g_set_error (error, IANJUTA_PROJECT_ERROR, 
+				IANJUTA_PROJECT_ERROR_NOT_SUPPORTED,
+		_("Project doesn't allow to set properties"));
+		
+	return FALSE;
+}
+
+static AnjutaProjectNode *
+iproject_get_root (IAnjutaProject *obj, GError **error)
+{
+	return DIR_PROJECT (obj)->root;
+}
+
 static GList* 
 iproject_get_node_info (IAnjutaProject *obj, GError **err)
 {
@@ -772,9 +794,12 @@ iproject_iface_init(IAnjutaProjectIface* iface)
 {
 	iface->load_node = iproject_load_node;
 	iface->save_node = iproject_save_node;
-	iface->new_node = iproject_new_node;
-	iface->free_node = iproject_free_node;
+	iface->add_node_before = iproject_add_node_before;
+	iface->add_node_after = iproject_add_node_after;
+	iface->remove_node = iproject_remove_node;
 	iface->set_property = iproject_set_property;
+	iface->remove_property = iproject_remove_property;
+	iface->get_root = iproject_get_root;
 	iface->get_node_info = iproject_get_node_info;
 }
 
@@ -798,7 +823,7 @@ dir_project_instance_init (DirProject *project)
 	g_return_if_fail (DIR_IS_PROJECT (project));
 	
 	/* project data */
-	project->root_file = NULL;
+	project->root = NULL;
 	//project->root_node = NULL;
 
 	project->monitors = NULL;
diff --git a/plugins/dir-project/dir-project.h b/plugins/dir-project/dir-project.h
index 7fb11a0..d7e2100 100644
--- a/plugins/dir-project/dir-project.h
+++ b/plugins/dir-project/dir-project.h
@@ -47,7 +47,7 @@ struct _DirProjectClass {
 };
 
 GType         dir_project_get_type (void);
-DirProject   *dir_project_new      (void);
+DirProject   *dir_project_new      (GFile *directory, GError **error);
 
 gint dir_project_probe (GFile *directory, GError     **error);
 
diff --git a/plugins/dir-project/plugin.c b/plugins/dir-project/plugin.c
index ab9d8d6..6fc5b0b 100644
--- a/plugins/dir-project/plugin.c
+++ b/plugins/dir-project/plugin.c
@@ -52,12 +52,13 @@ deactivate_plugin (AnjutaPlugin *plugin)
  *---------------------------------------------------------------------------*/
 
 static IAnjutaProject*
-iproject_backend_new_project (IAnjutaProjectBackend* backend, GError** err)
+iproject_backend_new_project (IAnjutaProjectBackend* backend, GFile *file, GError** err)
 {
 	IAnjutaProject *project;
-	DEBUG_PRINT("create new directory project");	
-	project = (IAnjutaProject *)(g_object_new (DIR_TYPE_PROJECT, NULL));
-		
+	DEBUG_PRINT("create new directory project");
+	
+	project = (IAnjutaProject *)dir_project_new (file, err);
+	
 	return project;
 }
 
diff --git a/plugins/project-manager/project.c b/plugins/project-manager/project.c
index 27087be..8b47181 100644
--- a/plugins/project-manager/project.c
+++ b/plugins/project-manager/project.c
@@ -122,9 +122,11 @@ typedef struct _PmCommandWork
 struct _PmJob
 {
 	PmCommand command;
+	AnjutaProjectNodeType type;
 	GFile *file;
 	gchar *name;
 	AnjutaProjectNode *node;
+	AnjutaProjectNode *sibling;
 	GError *error;
 	AnjutaProjectNode *proxy;
 	GHashTable *map;
@@ -158,13 +160,17 @@ static gboolean pm_project_run_command (AnjutaPmProject *project);
  *---------------------------------------------------------------------------*/
 
 static PmJob *
-pm_job_new (PmCommand command, AnjutaProjectNode *node)
+pm_job_new (PmCommand command, AnjutaProjectNode *node, AnjutaProjectNode *sibling, AnjutaProjectNodeType type, GFile *file, const gchar *name)
 {
 	PmJob *job;
 
 	job = g_new0 (PmJob, 1);
 	job->command = command;
 	job->node = node;
+	job->sibling = sibling;
+	job->type = type;
+	if (file != NULL) job->file = g_object_ref (file);
+	if (name != NULL) job->name = g_strdup (name);
 
 	return job;
 }
@@ -174,6 +180,8 @@ pm_job_free (PmJob *job)
 {
 	if (job->error != NULL) g_error_free (job->error);
 	if (job->map != NULL) g_hash_table_destroy (job->map);
+	if (job->file != NULL) g_object_unref (job->file);
+	if (job->name != NULL) g_free (job->name);
 }
 
 /* Worker thread functions
@@ -259,8 +267,7 @@ pm_command_load_work (AnjutaPmProject *project, PmJob *job)
 	AnjutaProjectNode *node;
 	
 
-	node = ianjuta_project_load_node (project->project, job->node, &(job->error));
-	if (job->error == NULL)
+	if (ianjuta_project_load_node (project->project, job->node, &(job->error)))
 	{
 		pm_project_map_node (job);
 	}
@@ -271,11 +278,7 @@ pm_command_load_work (AnjutaPmProject *project, PmJob *job)
 static gboolean
 pm_command_save_work (AnjutaPmProject *project, PmJob *job)
 {
-	AnjutaProjectNode *node;
-	
-	node = ianjuta_project_save_node (project->project, job->node, &(job->error));
-	
-	return TRUE;
+	return ianjuta_project_save_node (project->project, job->node, &(job->error));
 }
 
 static gboolean
@@ -360,7 +363,7 @@ pm_project_stop_thread (AnjutaPmProject *project)
 		project->idle_func = 0;
 
 		// Request to terminate thread
-		job = pm_job_new (EXIT, NULL);
+		job = pm_job_new (EXIT, NULL, NULL, 0, NULL, NULL);
 		g_async_queue_push (project->work_queue, job);
 		g_thread_join (project->worker);
 		project->worker = NULL;
@@ -384,27 +387,11 @@ pm_project_stop_thread (AnjutaPmProject *project)
 }
 
 static void
-pm_free_node (AnjutaProjectNode *node, IAnjutaProject *project)
-{
-	gint type = anjuta_project_node_get_full_type (node);
-	
-	g_message ("free node %p type %x name %s", node, type, anjuta_project_node_get_name (node));
-	if (type & ANJUTA_PROJECT_PROXY)
-	{
-		anjuta_project_proxy_unref (node);
-	}
-	else
-	{
-		ianjuta_project_free_node (project, node, NULL);
-	}
-}
-
-static void
-pm_project_push_command (AnjutaPmProject *project, PmCommand command, AnjutaProjectNode *node)
+pm_project_push_command (AnjutaPmProject *project, PmCommand command, AnjutaProjectNode *node, AnjutaProjectNode *sibling, AnjutaProjectNodeType type, GFile *file, const gchar *name)
 {
 	PmJob *job;
 
-	job = pm_job_new (command, node);
+	job = pm_job_new (command, node, sibling, type, file, name);
 	g_queue_push_tail (project->job_queue, job);
 	
 	pm_project_run_command (project);
@@ -421,7 +408,7 @@ on_pm_project_load_incomplete (AnjutaProjectNode *node, AnjutaPmProject *project
 		project->incomplete_node++;
 		anjuta_project_node_set_state (node, ANJUTA_PROJECT_LOADING);
 		//g_message ("load incomplete %p", node);
-		pm_project_push_command (project, RELOAD, node);
+		pm_project_push_command (project, RELOAD, node, NULL, 0, NULL, NULL);
 	}
 }
 
@@ -538,7 +525,7 @@ pm_command_load_complete (AnjutaPmProject *project, PmJob *job)
 		check_queue (project->job_queue, job->map);
 	}
 
-	pm_free_node (job->proxy, project->project);
+	anjuta_project_proxy_unref  (job->proxy);
 	//anjuta_project_node_foreach (job->proxy, G_POST_ORDER, (AnjutaProjectNodeForeachFunc)pm_free_node, project->project);
 	
 	return TRUE;
@@ -547,19 +534,13 @@ pm_command_load_complete (AnjutaPmProject *project, PmJob *job)
 static gboolean
 pm_command_add_setup (AnjutaPmProject *project, PmJob *job)
 {
-	AnjutaProjectNode *parent;
-	AnjutaProjectNode *sibling;
+	AnjutaProjectNode *node;
 	
 	g_return_val_if_fail (job != NULL, FALSE);
 	g_return_val_if_fail (job->node != NULL, FALSE);
 
-	/* Add new node in project tree.
-	 * It is safe to do it here because the worker thread is waiting */
-	parent = anjuta_project_node_parent (job->node);
-	sibling = job->node->prev;
-	job->node->parent = NULL;
-	job->node->prev = NULL;
-	anjuta_project_node_insert_before (parent, sibling, job->node);
+	node = ianjuta_project_add_node_before (project->project, job->node, job->sibling, job->type, NULL, job->name, NULL);
+	job->node = node;
 	
 	return TRUE;
 }
@@ -576,7 +557,7 @@ pm_command_remove_setup (AnjutaPmProject *project, PmJob *job)
 	if (gbf_project_model_find_node (project->model, &iter, NULL, job->node))
 	{
 		gbf_project_model_remove (project->model, &iter);
-		anjuta_project_node_set_state (job->node, ANJUTA_PROJECT_REMOVED);
+		ianjuta_project_remove_node (project->project, job->node, NULL);
 		
 		return TRUE;
 	}
@@ -593,8 +574,8 @@ pm_command_remove_complete (AnjutaPmProject *project, PmJob *job)
 	g_return_val_if_fail (job->node != NULL, FALSE);
 
 	/* Remove node from node tree */
-	anjuta_project_node_remove (job->node);
-	pm_free_node (job->node, project->project);
+	//anjuta_project_node_remove (job->node);
+	//pm_free_node (job->node, project->project);
 	//anjuta_project_node_foreach (job->node, G_POST_ORDER, (AnjutaProjectNodeForeachFunc)pm_free_node, project->project);
 	
 	return TRUE;
@@ -705,7 +686,7 @@ pm_project_idle_func (AnjutaPmProject *project)
 static void
 on_node_updated (IAnjutaProject *sender, AnjutaProjectNode *node, AnjutaPmProject *project)
 {
-	pm_project_push_command (project, RELOAD, node);
+	pm_project_push_command (project, RELOAD, node, NULL, 0, NULL, NULL);
 }
  
 gboolean 
@@ -777,7 +758,7 @@ anjuta_pm_project_load (AnjutaPmProject *project, GFile *file, GError **error)
 	}
 	
 	DEBUG_PRINT ("%s", "Creating new gbf project\n");
-	project->project = ianjuta_project_backend_new_project (backend, NULL);
+	project->project = ianjuta_project_backend_new_project (backend, file, NULL);
 	if (!project->project)
 	{
 		/* FIXME: Set err */
@@ -795,8 +776,8 @@ anjuta_pm_project_load (AnjutaPmProject *project, GFile *file, GError **error)
 						G_CALLBACK (on_node_updated),
 						project);
 	
-	project->root = ianjuta_project_new_node (project->project, NULL, ANJUTA_PROJECT_ROOT, file, NULL, NULL);
-	pm_project_push_command (project, LOAD, project->root);
+	project->root = ianjuta_project_get_root (project->project, NULL);
+	pm_project_push_command (project, LOAD, project->root, NULL, 0, NULL, NULL);
 	
 	return TRUE;
 }
@@ -804,7 +785,7 @@ anjuta_pm_project_load (AnjutaPmProject *project, GFile *file, GError **error)
 static gboolean
 anjuta_pm_project_reload_node (AnjutaPmProject *project, AnjutaProjectNode *node, GError **error)
 {
-	pm_project_push_command (project, RELOAD, node);
+	pm_project_push_command (project, RELOAD, node, NULL, 0, NULL, NULL);
 
 	return TRUE;
 }
@@ -830,7 +811,7 @@ anjuta_pm_project_refresh (AnjutaPmProject *project, GError **error)
 {
 	//g_message ("reload project %p", project->root);
 	
-	pm_project_push_command (project, RELOAD, project->root);
+	pm_project_push_command (project, RELOAD, project->root, NULL, 0, NULL, NULL);
 
 	return TRUE;
 }
@@ -928,10 +909,7 @@ anjuta_pm_project_add_group (AnjutaPmProject *project, AnjutaProjectNode *parent
 	
 	g_return_val_if_fail (project->project != NULL, NULL);
 	
-	node = ianjuta_project_new_node (project->project, parent, ANJUTA_PROJECT_GROUP, NULL, name, error);
-	node->parent = parent;
-	node->prev = sibling;
-	pm_project_push_command (project, ADD, node);
+	pm_project_push_command (project, ADD, parent, sibling, ANJUTA_PROJECT_GROUP, NULL, name);
 
 	return node;
 }
@@ -943,10 +921,7 @@ anjuta_pm_project_add_target (AnjutaPmProject *project, AnjutaProjectNode *paren
 	
 	g_return_val_if_fail (project->project != NULL, NULL);
 
-	node = ianjuta_project_new_node (project->project, parent, ANJUTA_PROJECT_TARGET | type, NULL, name, error);
-	node->parent = parent;
-	node->prev = sibling;
-	pm_project_push_command (project, ADD, node);
+	pm_project_push_command (project, ADD, parent, sibling, ANJUTA_PROJECT_TARGET | type, NULL, name);
 
 	return node;
 }
@@ -958,10 +933,7 @@ anjuta_pm_project_add_source (AnjutaPmProject *project, AnjutaProjectNode *paren
 
 	g_return_val_if_fail (project->project != NULL, NULL);
 	
-	node = ianjuta_project_new_node (project->project, parent, ANJUTA_PROJECT_SOURCE, NULL, name, error);
-	node->parent = parent;
-	node->prev = sibling;
-	pm_project_push_command (project, ADD, node);
+	pm_project_push_command (project, ADD, parent, sibling, ANJUTA_PROJECT_SOURCE, NULL, name);
 
 	return node;
 }
@@ -969,7 +941,7 @@ anjuta_pm_project_add_source (AnjutaPmProject *project, AnjutaProjectNode *paren
 gboolean
 anjuta_pm_project_remove (AnjutaPmProject *project, AnjutaProjectNode *node, GError **error)
 {
-	pm_project_push_command (project, REMOVE, node);
+	pm_project_push_command (project, REMOVE, node, NULL, 0, NULL, NULL);
 
 	return TRUE;
 }
@@ -988,7 +960,7 @@ anjuta_pm_project_set_properties (AnjutaPmProject *project, AnjutaProjectNode *n
 		if (!valid) break;
 	}
 	
-	if (valid) pm_project_push_command (project, SAVE, node);
+	if (valid) pm_project_push_command (project, SAVE, node, NULL, 0, NULL, NULL);
 	
 	return valid;
 }



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