[anjuta] am-project: Allow to create the root group in an empty project



commit 4dfbff3ff9b6fdb5201f8a587a00ac0d14f5ae46
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Sat Mar 31 11:02:35 2012 +0200

    am-project: Allow to create the root group in an empty project

 plugins/am-project/am-project.c   |    8 ++++++--
 plugins/am-project/am-writer.c    |   13 +++++++++++--
 plugins/am-project/amp-node.c     |   14 ++++++++++++--
 plugins/am-project/tests/empty.at |   22 ++++++++++++++++++++++
 4 files changed, 51 insertions(+), 6 deletions(-)
---
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index 4489dd2..45408f6 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -2197,7 +2197,9 @@ static PmCommandWork amp_save_job = {amp_save_setup, amp_save_work, amp_save_com
 static gboolean
 amp_add_before_setup (PmJob *job)
 {
-	anjuta_project_node_insert_before (job->parent, job->sibling, job->node);
+	/* If add is called to add the root group, the node is already existing */
+	if (job->parent != job->node)
+		anjuta_project_node_insert_before (job->parent, job->sibling, job->node);
 
 	return TRUE;
 }
@@ -2205,7 +2207,9 @@ amp_add_before_setup (PmJob *job)
 static gboolean
 amp_add_after_setup (PmJob *job)
 {
-	anjuta_project_node_insert_after (job->parent, job->sibling, job->node);
+	/* If add is called to add the root group, the node is already existing */
+	if (job->parent != job->node)
+		anjuta_project_node_insert_after (job->parent, job->sibling, job->node);
 
 	return TRUE;
 }
diff --git a/plugins/am-project/am-writer.c b/plugins/am-project/am-writer.c
index eedb520..91bdeda 100644
--- a/plugins/am-project/am-writer.c
+++ b/plugins/am-project/am-writer.c
@@ -495,9 +495,18 @@ amp_group_node_create_token (AmpProject  *project, AmpGroupNode *group, GError *
 	const gchar *name;
 
 	/* Get parent target */
-	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);
+	parent = AMP_GROUP_NODE (anjuta_project_node_parent_type(ANJUTA_PROJECT_NODE (group), ANJUTA_PROJECT_GROUP));
+	if (parent != NULL)
+	{
+		directory = g_file_get_child (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (parent)), name);
+	}
+	else
+	{
+		/* Used only when adding root group (a group named . in an empty project) */
+		parent = group;
+		directory = g_object_ref (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (parent)));
+	}
 
 	/* Find a sibling if possible */
 	after = TRUE;
diff --git a/plugins/am-project/amp-node.c b/plugins/am-project/amp-node.c
index 7fbcc5a..7827010 100644
--- a/plugins/am-project/amp-node.c
+++ b/plugins/am-project/amp-node.c
@@ -96,7 +96,16 @@ amp_node_new_valid(AnjutaProjectNode *parent, AnjutaProjectNodeType type, GFile
 				}
 				file = new_file;
 			}
-			node = ANJUTA_PROJECT_NODE (amp_group_node_new_valid (file, FALSE, error));
+			/* We can create group named . to create a root node in an empty project */
+			if (!g_file_equal (anjuta_project_node_get_file (parent), file))
+			{
+				node = ANJUTA_PROJECT_NODE (amp_group_node_new_valid (file, FALSE, error));
+				if (node != NULL) node->type = type;
+			}
+			else
+			{
+				node = parent;
+			}
 			break;
 		case ANJUTA_PROJECT_TARGET:
 			node = ANJUTA_PROJECT_NODE (amp_target_node_new_valid (name, type, NULL, 0, parent, error));
@@ -159,15 +168,16 @@ amp_node_new_valid(AnjutaProjectNode *parent, AnjutaProjectNodeType type, GFile
 			break;
 		case ANJUTA_PROJECT_MODULE:
 			node = ANJUTA_PROJECT_NODE (amp_module_node_new_valid (name, error));
+			if (node != NULL) node->type = type;
 			break;
 		case ANJUTA_PROJECT_PACKAGE:
 			node = ANJUTA_PROJECT_NODE (amp_package_node_new_valid (name, error));
+			if (node != NULL) node->type = type;
 			break;
 		default:
 			g_assert_not_reached ();
 			break;
 	}
-	if (node != NULL) node->type = type;
 	if (new_file != NULL) g_object_unref (new_file);
 
 	return node;
diff --git a/plugins/am-project/tests/empty.at b/plugins/am-project/tests/empty.at
index 735112e..b9f1497 100644
--- a/plugins/am-project/tests/empty.at
+++ b/plugins/am-project/tests/empty.at
@@ -54,4 +54,26 @@ AT_CHECK([diff output expect])
 
 
 
+AS_MKDIR_P([empty5])
+AT_DATA([empty5/configure.ac],
+[[]])
+AT_DATA([empty5/Makefile.am],
+[[]])
+AT_DATA([expect],
+[[ROOT (): empty6
+    SOURCE (): configure.ac
+    SOURCE (): Makefile.am
+]])
+AT_PARSER_CHECK([load empty5 \
+		 move empty6 \
+		 add group 0 . \
+		 save \
+		 list])
+AT_CHECK([diff output expect])
+AT_PARSER_CHECK([load empty6 \
+		 list])
+AT_CHECK([diff output expect])
+
+
+
 AT_CLEANUP



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