[anjuta] am-project: Fix a crash when removing source files (again due to object nodes)



commit ee7853027421fc28dedefbbdae5f0c3d2c2696d0
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Sun Jul 10 10:34:26 2011 +0200

    am-project: Fix a crash when removing source files (again due to object nodes)

 libanjuta/anjuta-project.c     |   14 ++++++++++++++
 libanjuta/anjuta-project.h     |    1 +
 plugins/am-project/ac-writer.c |    8 ++++----
 plugins/am-project/am-writer.c |   34 +++++++++++++++-------------------
 plugins/am-project/amp-node.c  |    5 +----
 plugins/am-project/amp-node.h  |    1 -
 6 files changed, 35 insertions(+), 28 deletions(-)
---
diff --git a/libanjuta/anjuta-project.c b/libanjuta/anjuta-project.c
index 5caeac3..d81567e 100644
--- a/libanjuta/anjuta-project.c
+++ b/libanjuta/anjuta-project.c
@@ -360,6 +360,20 @@ anjuta_project_node_children_foreach (AnjutaProjectNode *node, AnjutaProjectNode
 	}
 }
 
+AnjutaProjectNode *
+anjuta_project_node_parent_type(AnjutaProjectNode *node,  AnjutaProjectNodeType type)
+{
+	do
+	{
+		node = anjuta_project_node_parent (node);
+		if (node == NULL) break;
+	}
+	while (anjuta_project_node_get_node_type (node) != type);
+
+	return node;
+}
+
+
 
 /* Debugging functions
  *---------------------------------------------------------------------------*/
diff --git a/libanjuta/anjuta-project.h b/libanjuta/anjuta-project.h
index f95f757..20eeada 100644
--- a/libanjuta/anjuta-project.h
+++ b/libanjuta/anjuta-project.h
@@ -175,6 +175,7 @@ AnjutaProjectNode *anjuta_project_node_last_child (AnjutaProjectNode *node);
 AnjutaProjectNode *anjuta_project_node_next_sibling (AnjutaProjectNode *node);
 AnjutaProjectNode *anjuta_project_node_prev_sibling (AnjutaProjectNode *node);
 AnjutaProjectNode *anjuta_project_node_nth_child (AnjutaProjectNode *node, guint n);
+AnjutaProjectNode *anjuta_project_node_parent_type (AnjutaProjectNode *node, AnjutaProjectNodeType type);
 
 void anjuta_project_node_foreach (AnjutaProjectNode *node, GTraverseType order, AnjutaProjectNodeForeachFunc func, gpointer data);
 void anjuta_project_node_children_foreach (AnjutaProjectNode *node, AnjutaProjectNodeForeachFunc func, gpointer data);
diff --git a/plugins/am-project/ac-writer.c b/plugins/am-project/ac-writer.c
index 55c206e..2105ae1 100644
--- a/plugins/am-project/ac-writer.c
+++ b/plugins/am-project/ac-writer.c
@@ -374,8 +374,8 @@ amp_package_node_create_token (AmpProject  *project, AmpPackageNode *package, GE
 
 
 	/* Get parent module */
-	module = AMP_MODULE_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (package)));
-	if ((module == NULL) || (anjuta_project_node_get_node_type (ANJUTA_PROJECT_NODE (module)) != ANJUTA_PROJECT_MODULE)) return FALSE;
+	module = AMP_MODULE_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (package), ANJUTA_PROJECT_MODULE));
+	if (module == NULL) return FALSE;
 
 
 	/* Add in configure.ac */
@@ -443,8 +443,8 @@ amp_package_node_delete_token (AmpProject  *project, AmpPackageNode *package, GE
 	AnjutaToken *token;
 
 	/* Get parent module */
-	module = anjuta_project_node_parent (ANJUTA_PROJECT_NODE (package));
-	if ((module == NULL) || (anjuta_project_node_get_node_type (module) != ANJUTA_PROJECT_MODULE))
+	module = anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (package), ANJUTA_PROJECT_MODULE);
+	if (module == NULL)
 	{
 		return FALSE;
 	}
diff --git a/plugins/am-project/am-writer.c b/plugins/am-project/am-writer.c
index fe442de..1311055 100644
--- a/plugins/am-project/am-writer.c
+++ b/plugins/am-project/am-writer.c
@@ -63,7 +63,7 @@ anjuta_token_find_target_property_position (AmpTargetNode *target,
 	AmpGroupNode *group;
 	AnjutaToken *makefile;
 	
-	group = AMP_GROUP_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (target)));
+	group = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP));
 	
 	/* Try to find a better position */
 
@@ -491,7 +491,7 @@ amp_group_node_create_token (AmpProject  *project, AmpGroupNode *group, GError *
 	const gchar *name;
 	
 	/* Get parent target */
-	parent = AMP_GROUP_NODE (anjuta_project_node_parent(ANJUTA_PROJECT_NODE (group)));
+	parent = AMP_GROUP_NODE (anjuta_project_node_parent_type(ANJUTA_PROJECT_NODE (group), ANJUTA_PROJECT_GROUP));
 	name = anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (group));
 	directory = g_file_get_child (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (parent)), name);
 
@@ -633,9 +633,9 @@ amp_group_node_delete_token (AmpProject  *project, AmpGroupNode *group, GError *
 	GList *item;
 	AnjutaProjectNode *parent;
 
-	/* Get parent target */
-	parent =  anjuta_project_node_parent (ANJUTA_PROJECT_NODE (group));
-	if (anjuta_project_node_get_node_type  (parent) != ANJUTA_PROJECT_GROUP) return FALSE;
+	/* Get parent group */
+	parent =  anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (group), ANJUTA_PROJECT_GROUP);
+	if (parent == NULL) return FALSE;
 
 	for (item = amp_group_node_get_token (group, AM_GROUP_TOKEN_SUBDIRS); item != NULL; item = g_list_next (item))
 	{
@@ -751,7 +751,7 @@ amp_target_add_in_list (AmpProject *project, AnjutaToken *list, AnjutaProjectNod
 	g_return_val_if_fail (list != NULL, NULL);
 	
 	/* Get parent target */
-	parent = AMP_GROUP_NODE (anjuta_project_node_parent (target));
+	parent = AMP_GROUP_NODE (anjuta_project_node_parent_type (target, ANJUTA_PROJECT_GROUP));
 	
 	style = anjuta_token_style_new_from_base (project->am_space_list);
 	anjuta_token_style_update (style, list);
@@ -793,7 +793,7 @@ amp_target_node_create_token (AmpProject  *project, AmpTargetNode *target, GErro
 	gboolean after;
 
 	/* Get parent target */
-	parent = AMP_GROUP_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (target)));
+	parent = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP));
 	
 	info = (AmpNodeInfo *)amp_project_get_type_info (project, anjuta_project_node_get_full_type (ANJUTA_PROJECT_NODE (target)));
 	name = anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (target));
@@ -906,8 +906,8 @@ amp_target_node_delete_token (AmpProject  *project, AmpTargetNode *target, GList
 	GList *removed_dir = NULL;
 	AmpGroupNode *parent;
 
-	/* Get parent target */
-	parent = AMP_GROUP_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (target)));
+	/* Get parent group */
+	parent = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP));
 
 	/* Remove all associated token */
 	for (item = list; item != NULL;	 item = g_list_next (item))
@@ -1064,10 +1064,10 @@ amp_source_node_create_token (AmpProject  *project, AmpSourceNode *source, GErro
 	gchar *relative_name;
 
 	/* Get parent target */
-	target = AMP_TARGET_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (source)));
-	if ((target == NULL) || (anjuta_project_node_get_node_type (ANJUTA_PROJECT_NODE (target)) != ANJUTA_PROJECT_TARGET)) return FALSE;
+	target = AMP_TARGET_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (source), ANJUTA_PROJECT_TARGET));
+	if (target == NULL) return FALSE;
 	
-	group = AMP_GROUP_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (target)));
+	group = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP));
 	relative_name = get_relative_path (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (group)), anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (source)));
 	
 	/* Add in Makefile.am */
@@ -1195,11 +1195,7 @@ amp_source_node_delete_token (AmpProject  *project, AmpSourceNode *source, GErro
 	AnjutaToken *token;
 
 	/* Get parent group */
-	group = anjuta_project_node_parent (ANJUTA_PROJECT_NODE (source));
-	if (anjuta_project_node_get_node_type (group) == ANJUTA_PROJECT_TARGET)
-	{
-		group = anjuta_project_node_parent (ANJUTA_PROJECT_NODE (group));
-	}
+	group = anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (source), ANJUTA_PROJECT_GROUP);
 	if (group == NULL) return FALSE;
 
 	token = amp_source_node_get_token (source);
@@ -1311,7 +1307,7 @@ amp_property_rename_target (AmpProject *project, AnjutaProjectNode *node)
 
 	g_return_val_if_fail (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_TARGET, NULL);
 
-	group = anjuta_project_node_parent (node);
+	group = anjuta_project_node_parent_type (node, ANJUTA_PROJECT_GROUP);
 
 	/* Find all program properties */
 	props = NULL;
@@ -1618,7 +1614,7 @@ gboolean amp_project_update_am_property (AmpProject *project, AnjutaProjectNode
 	}
 	else
 	{
-		group = anjuta_project_node_parent (node);
+		group = anjuta_project_node_parent_type (node, ANJUTA_PROJECT_GROUP);
 	}
 
 	if (((property->native->value == NULL) && ((property->value == NULL) || (*property->value == '\0'))) ||
diff --git a/plugins/am-project/amp-node.c b/plugins/am-project/amp-node.c
index 596720a..058e3a9 100644
--- a/plugins/am-project/amp-node.c
+++ b/plugins/am-project/amp-node.c
@@ -76,10 +76,7 @@ amp_node_new_valid(AnjutaProjectNode *parent, AnjutaProjectNodeType type, GFile
 			break;
 		case ANJUTA_PROJECT_SOURCE:
 			/* Look for parent */
-			if (anjuta_project_node_get_node_type (parent) == ANJUTA_PROJECT_TARGET)
-			{
-				parent = anjuta_project_node_parent (parent);
-			}
+			parent = anjuta_project_node_parent_type (parent, ANJUTA_PROJECT_GROUP);
 			
 			if ((file == NULL) && (name != NULL))
 			{
diff --git a/plugins/am-project/amp-node.h b/plugins/am-project/amp-node.h
index 3cafe29..bfddadb 100644
--- a/plugins/am-project/amp-node.h
+++ b/plugins/am-project/amp-node.h
@@ -122,7 +122,6 @@ gboolean						amp_node_erase					(AmpNode *node,
 											                       AmpProject *project,
 											                       GError **error);
 
-
 void amp_node_register (GTypeModule *module);
 
 G_END_DECLS



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