[anjuta/newproject] am: Fix adding and removing targets in most common case



commit a855d7cb8a7875cdb94ad548ca0713df0b3f782d
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Tue Sep 28 23:04:07 2010 +0200

    am: Fix adding and removing targets in most common case

 libanjuta/anjuta-token-file.c      |   66 +++++++++++-----
 libanjuta/anjuta-token-list.c      |   59 +++++++++-----
 libanjuta/anjuta-token-list.h      |    3 +-
 libanjuta/anjuta-token.c           |   23 +++++-
 libanjuta/anjuta-token.h           |    1 +
 plugins/am-project/am-parser.y     |    3 +-
 plugins/am-project/am-project.c    |  151 ++++++++++++++++++++++++++++--------
 plugins/am-project/am-project.h    |    2 +
 plugins/am-project/am-writer.c     |    4 +-
 plugins/am-project/projectparser.c |   21 ++---
 10 files changed, 241 insertions(+), 92 deletions(-)
---
diff --git a/libanjuta/anjuta-token-file.c b/libanjuta/anjuta-token-file.c
index 4d2b356..0ab70d1 100644
--- a/libanjuta/anjuta-token-file.c
+++ b/libanjuta/anjuta-token-file.c
@@ -1,4 +1,5 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
 /*
  * anjuta-token-file.c
  * Copyright (C) Sébastien Granjoux 2009 <seb sfo free fr>
@@ -200,6 +201,47 @@ anjuta_token_file_move (AnjutaTokenFile *file, GFile *new_file)
 	file->file = new_file != NULL ? g_object_ref (new_file) : NULL;
 }
 
+static AnjutaToken *
+anjuta_token_file_remove_token (AnjutaTokenFile *file, AnjutaToken *token)
+{
+	AnjutaToken *last;
+	AnjutaToken *next;
+
+	if ((anjuta_token_get_length (token) > 0))
+	{
+		AnjutaToken *pos = anjuta_token_file_find_position (file, token);
+		guint len = anjuta_token_get_length (token);
+
+		if (pos != NULL)
+		{
+			while (len != 0)
+			{
+				guint flen = anjuta_token_get_length (pos);
+				if (len < flen)
+				{
+					pos = anjuta_token_split (pos, len);
+					flen = len;
+				}
+				pos = anjuta_token_free (pos);
+				len -= flen;
+			}
+		}
+	}
+	
+	last = anjuta_token_last (token); 
+	if ((last != NULL) && (last != token))
+	{
+		next = anjuta_token_next (token);
+		while (next != last)
+		{
+			next = anjuta_token_file_remove_token (file, next);
+		}
+		anjuta_token_file_remove_token (file, next);
+	}		
+
+	return anjuta_token_free (token);
+}
+
 /**
  * anjuta_token_file_update:
  * @file: a #AnjutaTokenFile derived class object.
@@ -257,27 +299,11 @@ anjuta_token_file_update (AnjutaTokenFile *file, AnjutaToken *token)
 	{
 		gint flags = anjuta_token_get_flags (next);
 		
-		if ((flags & ANJUTA_TOKEN_REMOVED) && (anjuta_token_get_length (next) > 0))
+		if (flags & ANJUTA_TOKEN_REMOVED)
 		{
-			AnjutaToken *pos = anjuta_token_file_find_position (file, next);
-			guint len = anjuta_token_get_length (next);
-
-			if (pos != NULL)
-			{
-				while (len != 0)
-				{
-					guint flen = anjuta_token_get_length (pos);
-					if (len < flen)
-					{
-						pos = anjuta_token_split (pos, len);
-						flen = len;
-					}
-					pos = anjuta_token_free (pos);
-					len -= flen;
-				}
-				next = anjuta_token_free (next);
-				continue;
-			}
+			anjuta_token_dump (anjuta_token_list (next));
+			next = anjuta_token_file_remove_token (file, next);
+			continue;
 		}
 		else if (flags & ANJUTA_TOKEN_ADDED)
 		{
diff --git a/libanjuta/anjuta-token-list.c b/libanjuta/anjuta-token-list.c
index 3cf616e..19687ed 100644
--- a/libanjuta/anjuta-token-list.c
+++ b/libanjuta/anjuta-token-list.c
@@ -40,6 +40,7 @@ struct _AnjutaTokenStyle
 {
 	guint max_width;
 	GHashTable *separator;
+	AnjutaTokenStyle *base;
 };
 
 /* Private functions
@@ -148,8 +149,14 @@ anjuta_token_style_lookup (AnjutaTokenStyle *style, AnjutaTokenType type, gboole
 	GList *list;
 	
 	list = g_hash_table_lookup (style->separator, GINT_TO_POINTER (type));
-
-	return anjuta_token_new_string (ANJUTA_TOKEN_NAME, ((AnjutaTokenStyleSeparator *)list->data)->value);
+	if ((list == NULL) && (style->base != NULL))
+	{
+		return anjuta_token_style_lookup (style->base, type, eol);
+	}
+	else
+	{
+		return anjuta_token_new_string (ANJUTA_TOKEN_NAME, ((AnjutaTokenStyleSeparator *)list->data)->value);
+	}
 }
 
 /* Public style functions
@@ -523,8 +530,8 @@ anjuta_token_insert_word_before (AnjutaToken *list, AnjutaToken *sibling, Anjuta
 		default:
 			if (token == sibling)
 			{
-				anjuta_token_insert_before (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
 				anjuta_token_insert_before (token, item);
+				anjuta_token_insert_before (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
 				return item;
 			}
 			break;
@@ -604,34 +611,32 @@ anjuta_token_insert_word_after (AnjutaToken *list, AnjutaToken *sibling, AnjutaT
 }
 
 AnjutaToken*
-anjuta_token_remove_word (AnjutaToken *token, AnjutaTokenStyle *user_style)
+anjuta_token_remove_word (AnjutaToken *token)
 {
-	AnjutaTokenStyle *style;
-	AnjutaToken *space;
+	AnjutaToken *next;
 
-	style = user_style != NULL ? user_style : anjuta_token_style_new (NULL," ","\n",NULL,0);
-	anjuta_token_style_update (style, anjuta_token_parent (token));
-	
 	anjuta_token_set_flags (token, ANJUTA_TOKEN_REMOVED);
-	space = anjuta_token_next_item (token);
-	if (space && (anjuta_token_get_type (space) == ANJUTA_TOKEN_SPACE) && (anjuta_token_next (space) != NULL))
+	next = anjuta_token_next_item (token);
+	if ((next != NULL) && (anjuta_token_list (token) == anjuta_token_list (next)) && (anjuta_token_get_type (next) == ANJUTA_TOKEN_NEXT))
 	{
-		/* Remove following space */
-		anjuta_token_set_flags (space, ANJUTA_TOKEN_REMOVED);
+		/* Remove following separator */
+		anjuta_token_set_flags (next, ANJUTA_TOKEN_REMOVED);
 	}
 	else
 	{
-		space = anjuta_token_previous_item (token);
-		if (space && (anjuta_token_get_type (space) == ANJUTA_TOKEN_SPACE) && (anjuta_token_previous (space) != NULL))
+		next = anjuta_token_previous_item (token);
+		if ((next != NULL) && (anjuta_token_list (token) == anjuta_token_list (next)) && (anjuta_token_get_type (next) == ANJUTA_TOKEN_NEXT))
+		{
+			/* Remove previous separator */
+			anjuta_token_set_flags (next, ANJUTA_TOKEN_REMOVED);
+		}
+		else
 		{
-			anjuta_token_set_flags (space, ANJUTA_TOKEN_REMOVED);
+			next = NULL;
 		}
 	}
 	
-	anjuta_token_style_format (style, anjuta_token_parent (token));
-	if (user_style == NULL) anjuta_token_style_free (style);
-	
-	return NULL;
+	return next;
 }
 
 AnjutaToken *
@@ -767,6 +772,20 @@ anjuta_token_style_new (const gchar *start, const gchar *next, const gchar *eol,
 	return style;	
 }
 
+AnjutaTokenStyle *
+anjuta_token_style_new_from_base (AnjutaTokenStyle *base)
+{
+	AnjutaTokenStyle *style;
+	
+	style = g_slice_new0 (AnjutaTokenStyle);
+	style->max_width = base->max_width;
+	style->base = base;
+	
+	style->separator = g_hash_table_new (g_direct_hash, NULL);
+
+	return style;
+}
+
 void
 anjuta_token_style_free (AnjutaTokenStyle *style)
 {
diff --git a/libanjuta/anjuta-token-list.h b/libanjuta/anjuta-token-list.h
index 83ef9cb..cffb55d 100644
--- a/libanjuta/anjuta-token-list.h
+++ b/libanjuta/anjuta-token-list.h
@@ -39,6 +39,7 @@ enum AnjutaTokenSearchFlag
 };
 
 AnjutaTokenStyle *anjuta_token_style_new (const gchar *start, const gchar *next, const gchar *eol, const gchar *last, guint max_width);
+AnjutaTokenStyle *anjuta_token_style_new_from_base (AnjutaTokenStyle *base);
 void anjuta_token_style_free (AnjutaTokenStyle *style);
 
 void anjuta_token_style_update (AnjutaTokenStyle *style, AnjutaToken *list);
@@ -51,7 +52,7 @@ AnjutaToken *anjuta_token_next_word (AnjutaToken *item);
 AnjutaToken *anjuta_token_replace_nth_word (AnjutaToken *list, guint n, AnjutaToken *item);
 AnjutaToken *anjuta_token_insert_word_before (AnjutaToken *list, AnjutaToken *sibling, AnjutaToken *baby);
 AnjutaToken *anjuta_token_insert_word_after (AnjutaToken *list, AnjutaToken *sibling, AnjutaToken *baby);
-AnjutaToken *anjuta_token_remove_word (AnjutaToken *token, AnjutaTokenStyle *user_style);
+AnjutaToken *anjuta_token_remove_word (AnjutaToken *token);
 
 AnjutaToken *anjuta_token_insert_token_list (gboolean after, AnjutaToken *list,...);
 AnjutaToken *anjuta_token_find_type (AnjutaToken *list, gint flags, AnjutaTokenType* types);
diff --git a/libanjuta/anjuta-token.c b/libanjuta/anjuta-token.c
index f7d1319..8d54def 100644
--- a/libanjuta/anjuta-token.c
+++ b/libanjuta/anjuta-token.c
@@ -156,7 +156,7 @@ anjuta_token_next_child (AnjutaToken *child, AnjutaToken **last)
 	return child;
 }
 
-static AnjutaToken *
+AnjutaToken *
 anjuta_token_next_after_children (AnjutaToken *token)
 {
 	while (token->next == NULL)
@@ -234,6 +234,27 @@ anjuta_token_unlink_token (AnjutaToken *token)
 	}
 	token->parent = NULL;
 
+	if ((token->group != NULL) && (token->group->last == token))
+	{
+		AnjutaToken *prev;
+
+		for (prev = token->prev; prev != NULL; prev = prev->prev)
+		{
+			if (prev->group == token->group)
+			{
+				/* Find previous token in the same group */
+				token->group->last = prev;
+				break;
+			}
+			else if (prev == token->group)
+			{
+				/* No more token in group */
+				token->group->last = NULL;
+				break;
+			}
+		}
+	}
+	
 	if (token->next != NULL)
 	{
 		token->next->prev = token->prev;
diff --git a/libanjuta/anjuta-token.h b/libanjuta/anjuta-token.h
index 5a06a27..08909d0 100644
--- a/libanjuta/anjuta-token.h
+++ b/libanjuta/anjuta-token.h
@@ -108,6 +108,7 @@ AnjutaToken *anjuta_token_previous (AnjutaToken *token);
 AnjutaToken *anjuta_token_last (AnjutaToken *token);
 AnjutaToken *anjuta_token_parent (AnjutaToken *token);
 AnjutaToken *anjuta_token_list (AnjutaToken *token);
+AnjutaToken *anjuta_token_next_after_children (AnjutaToken *token);
 
 AnjutaToken *anjuta_token_first_item (AnjutaToken *list);
 AnjutaToken *anjuta_token_next_item (AnjutaToken *item);
diff --git a/plugins/am-project/am-parser.y b/plugins/am-project/am-parser.y
index ab7bc2e..ee18f97 100644
--- a/plugins/am-project/am-parser.y
+++ b/plugins/am-project/am-parser.y
@@ -178,8 +178,9 @@ statement:
 am_variable:
 	optional_space  automake_token  optional_space  equal_token  value_list {
 		$$ = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL);
+		if ($1 != NULL) anjuta_token_set_type ($1, ANJUTA_TOKEN_START);
 		anjuta_token_merge ($$, $2);
-		if ($3 != NULL) anjuta_token_set_type ($3, ANJUTA_TOKEN_START);
+		if ($3 != NULL) anjuta_token_set_type ($3, ANJUTA_TOKEN_NEXT);
 		anjuta_token_merge ($$, $4);
 		anjuta_token_merge ($$, $5);
 		amp_am_scanner_set_am_variable (scanner, amp_am_automake_variable ($2), $2, anjuta_token_last_item ($$));
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index 000a550..c2e699e 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -722,7 +722,7 @@ amp_group_fill_token (AmpProject  *project, AnjutaAmGroupNode *group, GError **e
 		if (sibling)
 		{
 			prev = amp_group_get_first_token (sibling, AM_GROUP_TOKEN_SUBDIRS);
-		}		
+		}
 		
 		token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, name);
 		if (after)
@@ -851,6 +851,7 @@ amp_target_fill_token (AmpProject  *project, AnjutaAmTargetNode *target, GError
 		{
 			AnjutaToken *token = (AnjutaToken *)last->data;
 
+			/* Check that the sibling is of the same kind */
 			token = anjuta_token_list (token);
 			if (token != NULL)
 			{
@@ -864,16 +865,16 @@ amp_target_fill_token (AmpProject  *project, AnjutaAmTargetNode *target, GError
 						gchar *value;
 						
 						value = anjuta_token_evaluate (token);
-		
+
 						if ((value != NULL) && (strcmp (targetname, value) == 0))
 						{
 							g_free (value);
 							prev = (AnjutaToken *)last->data;
-							args = anjuta_token_last_item (anjuta_token_list (prev));
+							args = anjuta_token_list (prev);
 						}
 					}
 				}
-			}	
+			}
 		}
 	}
 
@@ -902,7 +903,11 @@ amp_target_fill_token (AmpProject  *project, AnjutaAmTargetNode *target, GError
 	
 	if (args != NULL)
 	{
-		token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, name);
+		AnjutaTokenStyle *style;
+
+		anjuta_token_dump (anjuta_token_list (args));
+		
+		token = anjuta_token_new_string (ANJUTA_TOKEN_ARGUMENT | ANJUTA_TOKEN_ADDED, name);
 		if (after)
 		{
 			anjuta_token_insert_word_after (args, prev, token);
@@ -911,8 +916,12 @@ amp_target_fill_token (AmpProject  *project, AnjutaAmTargetNode *target, GError
 		{
 			anjuta_token_insert_word_before (args, prev, token);
 		}
-	
-		anjuta_token_style_format (project->am_space_list, args);
+
+		/* Try to use the same style than the current target list */
+		style = anjuta_token_style_new_from_base (project->am_space_list);
+		anjuta_token_style_update (style, args);
+		anjuta_token_style_format (style, args);
+		anjuta_token_style_free (style);
 		anjuta_token_file_update (AMP_GROUP_DATA (parent)->tfile, token);
 		
 		amp_target_add_token (target, token);
@@ -922,6 +931,37 @@ amp_target_fill_token (AmpProject  *project, AnjutaAmTargetNode *target, GError
 	return TRUE;
 }
 
+static gboolean 
+amp_target_remove_token (AmpProject  *project, AnjutaAmTargetNode *target, GError **error)
+{
+	GList *item;
+	AnjutaAmGroupNode *parent;
+
+	/* Get parent target */
+	parent = ANJUTA_AM_GROUP_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (target)));
+
+	for (item = amp_target_get_token (target); item != NULL; item = g_list_next (item))
+	{
+		AnjutaToken *token = (AnjutaToken *)item->data;
+		AnjutaToken *args;
+		AnjutaTokenStyle *style;
+
+		args = anjuta_token_list (token);
+
+		/* Try to use the same style than the current target list */
+		style = anjuta_token_style_new_from_base (project->am_space_list);
+		anjuta_token_style_update (style, args);
+		
+		anjuta_token_remove_word (token);
+		
+		anjuta_token_style_format (style, args);
+		anjuta_token_style_free (style);
+		
+		anjuta_token_file_update (AMP_GROUP_DATA (parent)->tfile, args);
+	}
+
+	return TRUE;
+}
 
 /* Source objects
  *---------------------------------------------------------------------------*/
@@ -2226,15 +2266,15 @@ amp_project_remove_group (AmpProject  *project,
 	
 	for (token_list = amp_group_get_token (group, AM_GROUP_TOKEN_CONFIGURE); token_list != NULL; token_list = g_list_next (token_list))
 	{
-		anjuta_token_remove_word ((AnjutaToken *)token_list->data, NULL);
+		anjuta_token_remove_word ((AnjutaToken *)token_list->data);
 	}
 	for (token_list = amp_group_get_token (group, AM_GROUP_TOKEN_SUBDIRS); token_list != NULL; token_list = g_list_next (token_list))
 	{
-		anjuta_token_remove_word ((AnjutaToken *)token_list->data, NULL);
+		anjuta_token_remove_word ((AnjutaToken *)token_list->data);
 	}
 	for (token_list = amp_group_get_token (group, AM_GROUP_TOKEN_DIST_SUBDIRS); token_list != NULL; token_list = g_list_next (token_list))
 	{
-		anjuta_token_remove_word ((AnjutaToken *)token_list->data, NULL);
+		anjuta_token_remove_word ((AnjutaToken *)token_list->data);
 	}
 
 	amp_group_free (group);
@@ -2251,7 +2291,7 @@ amp_project_remove_target (AmpProject  *project,
 	
 	for (token_list = amp_target_get_token (target); token_list != NULL; token_list = g_list_next (token_list))
 	{
-		anjuta_token_remove_word ((AnjutaToken *)token_list->data, NULL);
+		anjuta_token_remove_word ((AnjutaToken *)token_list->data);
 	}
 
 	amp_target_free (target);
@@ -2265,7 +2305,7 @@ amp_project_remove_source (AmpProject  *project,
 	amp_dump_node (source);
 	if (anjuta_project_node_get_node_type (source) != ANJUTA_PROJECT_SOURCE) return;
 	
-	anjuta_token_remove_word (AMP_SOURCE_DATA (source)->token, NULL);
+	anjuta_token_remove_word (AMP_SOURCE_DATA (source)->token);
 
 	amp_source_free (source);
 }
@@ -2424,6 +2464,25 @@ amp_project_move (AmpProject *project, const gchar *path)
 	return TRUE;
 }
 
+/* Dump file content of corresponding node */
+gboolean
+amp_project_dump (AmpProject *project, AnjutaProjectNode *node)
+{
+	gboolean ok = FALSE;
+	
+	switch (anjuta_project_node_get_node_type (node))
+	{
+	case ANJUTA_PROJECT_GROUP:
+		anjuta_token_dump (AMP_GROUP_DATA (node)->make_token);
+		break;
+	default:
+		break;
+	}
+
+	return ok;
+}
+
+
 AmpProject *
 amp_project_new (GFile *file, GError **error)
 {
@@ -2639,23 +2698,8 @@ iproject_save_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **error
 				node = NULL;
 			}
 			break;
-		case ANJUTA_PROJECT_SOURCE:
-			amp_source_fill_token (AMP_PROJECT (obj), node, NULL);
-			node = project_node_save (AMP_PROJECT (obj), node, error);
-			break;
-		case ANJUTA_PROJECT_TARGET:
-			amp_target_fill_token (AMP_PROJECT (obj), node, NULL);
-			node = project_node_save (AMP_PROJECT (obj), node, error);
-			break;
-		case ANJUTA_PROJECT_GROUP:
-			amp_group_fill_token (AMP_PROJECT (obj), node, NULL);
-			node = project_node_save (AMP_PROJECT (obj), node, error);
-			break;
 		default:
 			node = project_node_save (AMP_PROJECT (obj), node, error);
-			/*node = NULL;
-			error_set (error, IANJUTA_PROJECT_ERROR_NOT_SUPPORTED,
-				   _("Only the root node can be saved in an autotools project"));*/
 			break;
 	}
 	
@@ -2678,12 +2722,24 @@ iproject_add_node_before (IAnjutaProject *obj, AnjutaProjectNode *parent, Anjuta
 			}
 			node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
 			if (directory != NULL) g_object_unref (directory);
+			anjuta_project_node_insert_before (parent, sibling, node);
+			amp_group_fill_token (AMP_PROJECT (obj), node, NULL);
+			break;
+		case ANJUTA_PROJECT_TARGET:
+			node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+			anjuta_project_node_insert_before (parent, sibling, node);
+			amp_target_fill_token (AMP_PROJECT (obj), node, NULL);
+			break;
+		case ANJUTA_PROJECT_SOURCE:
+			node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+			anjuta_project_node_insert_before (parent, sibling, node);
+			amp_source_fill_token (AMP_PROJECT (obj), node, NULL);
 			break;
 		default:
-				node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
-				break;
+			node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+			anjuta_project_node_insert_before (parent, sibling, node);
+			break;
 	}
-	anjuta_project_node_insert_before (parent, sibling, node);
 	
 	return node;
 }
@@ -2693,7 +2749,7 @@ iproject_add_node_after (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaP
 {
 	AnjutaProjectNode *node;
 	GFile *directory = NULL;
-	
+
 	switch (type & ANJUTA_PROJECT_TYPE_MASK)
 	{
 		case ANJUTA_PROJECT_GROUP:
@@ -2704,12 +2760,24 @@ iproject_add_node_after (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaP
 			}
 			node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
 			if (directory != NULL) g_object_unref (directory);
+			anjuta_project_node_insert_after (parent, sibling, node);
+			amp_group_fill_token (AMP_PROJECT (obj), node, NULL);
+			break;
+		case ANJUTA_PROJECT_TARGET:
+			node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+			anjuta_project_node_insert_after (parent, sibling, node);
+			amp_target_fill_token (AMP_PROJECT (obj), node, NULL);
+			break;
+		case ANJUTA_PROJECT_SOURCE:
+			node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+			anjuta_project_node_insert_after (parent, sibling, node);
+			amp_source_fill_token (AMP_PROJECT (obj), node, NULL);
 			break;
 		default:
-				node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
-				break;
+			node = project_node_new (AMP_PROJECT (obj), type, file, name, err);
+			anjuta_project_node_insert_after (parent, sibling, node);
+			break;
 	}
-	anjuta_project_node_insert_after (parent, sibling, node);
 	
 	return node;
 }
@@ -2717,7 +2785,22 @@ iproject_add_node_after (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaP
 static gboolean
 iproject_remove_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
 {
+	AnjutaProjectNodeType type = anjuta_project_node_get_node_type (node);
+	
 	anjuta_project_node_set_state (node, ANJUTA_PROJECT_REMOVED);
+	
+	switch (type & ANJUTA_PROJECT_TYPE_MASK)
+	{
+		case ANJUTA_PROJECT_GROUP:
+			break;
+		case ANJUTA_PROJECT_TARGET:
+			amp_target_remove_token (AMP_PROJECT (obj), node, NULL);
+			break;
+		case ANJUTA_PROJECT_SOURCE:
+			break;
+		default:
+			break;
+	}
 
 	return TRUE;
 }
diff --git a/plugins/am-project/am-project.h b/plugins/am-project/am-project.h
index 4573d26..5a61d33 100644
--- a/plugins/am-project/am-project.h
+++ b/plugins/am-project/am-project.h
@@ -95,6 +95,8 @@ gboolean amp_project_get_token_location (AmpProject *project, AnjutaTokenFileLoc
 gboolean amp_project_move (AmpProject *project, const gchar *path);
 gboolean amp_project_save (AmpProject *project, GError **error);
 
+gboolean amp_project_dump (AmpProject *project, AnjutaProjectNode *node);
+
 gchar * amp_project_get_uri (AmpProject *project);
 GFile* amp_project_get_file (AmpProject *project);
 
diff --git a/plugins/am-project/am-writer.c b/plugins/am-project/am-writer.c
index f260cb8..21fbf7d 100644
--- a/plugins/am-project/am-writer.c
+++ b/plugins/am-project/am-writer.c
@@ -163,9 +163,9 @@ amp_project_write_target (AnjutaToken *makefile, gint type, const gchar *name, g
 	    		ANJUTA_TOKEN_SPACE, " ",
 	    		ANJUTA_TOKEN_OPERATOR, "=",
 	    		ANJUTA_TOKEN_LIST, NULL,
-	    		ANJUTA_TOKEN_START, NULL,
+	            ANJUTA_TOKEN_SPACE, " ",
 	    		NULL);
-
+	
 	return anjuta_token_last_item (token);
 }
 
diff --git a/plugins/am-project/projectparser.c b/plugins/am-project/projectparser.c
index 7b13705..0c9b1cb 100644
--- a/plugins/am-project/projectparser.c
+++ b/plugins/am-project/projectparser.c
@@ -442,7 +442,11 @@ main(int argc, char *argv[])
 		{
 			node = get_node (project, root, *(++command));
 			ianjuta_project_remove_node (project, node, NULL);
-			ianjuta_project_save_node (project, child, NULL);
+		}
+		else if (g_ascii_strcasecmp (*command, "dump") == 0)
+		{
+			node = get_node (project, root, *(++command));
+			amp_project_dump (AMP_PROJECT (project), node);
 		}
 		else if (g_ascii_strcasecmp (command[0], "add") == 0)
 		{
@@ -454,20 +458,17 @@ main(int argc, char *argv[])
 				{
 					sibling = get_node (project, root, command[5]);
 					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_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_add_node_after (project, node, NULL, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
-					ianjuta_project_save_node (project, child, NULL);
+					child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
 				}
 			}
 			else if (g_ascii_strcasecmp (command[1], "target") == 0)
@@ -476,20 +477,17 @@ main(int argc, char *argv[])
 				{
 					sibling = get_node (project, root, command[6]);
 					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_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_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);
+					child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
 				}
 				command++;
 			}
@@ -501,20 +499,17 @@ main(int argc, char *argv[])
 				{
 					sibling = get_node (project, root, command[5]);
 					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_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_add_node_after (project, node, NULL, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
-					ianjuta_project_save_node (project, child, NULL);
+					child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
 				}
 				g_object_unref (file);
 			}



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