[anjuta/newproject] Implement remove group for dir project backend



commit 8d6c6808acbb49fa21c23073d92d56354597db1f
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Fri May 7 21:59:40 2010 +0200

    Implement remove group for dir project backend

 libanjuta/anjuta-project.c        |   11 ++++++++
 libanjuta/anjuta-project.h        |    5 +++-
 plugins/dir-project/dir-project.c |   51 +++++++++++++++++++++----------------
 plugins/project-manager/plugin.c  |   27 ++++++++++++++++---
 plugins/project-manager/project.c |   45 ++++++++++++++++++++++++++++++--
 5 files changed, 108 insertions(+), 31 deletions(-)
---
diff --git a/libanjuta/anjuta-project.c b/libanjuta/anjuta-project.c
index f64e876..5a54530 100644
--- a/libanjuta/anjuta-project.c
+++ b/libanjuta/anjuta-project.c
@@ -289,6 +289,17 @@ anjuta_project_node_insert_after (AnjutaProjectNode *parent, AnjutaProjectNode *
 }
 
 AnjutaProjectNode *
+anjuta_project_node_remove (AnjutaProjectNode *node)
+{
+	if (node->parent != NULL)
+	{
+		g_node_unlink (node);
+	}
+	
+	return node;
+}
+
+AnjutaProjectNode *
 anjuta_project_node_replace (AnjutaProjectNode *node, AnjutaProjectNode *replacement)
 {
 	if (node->parent != NULL)
diff --git a/libanjuta/anjuta-project.h b/libanjuta/anjuta-project.h
index f86e3d1..a16d1a7 100644
--- a/libanjuta/anjuta-project.h
+++ b/libanjuta/anjuta-project.h
@@ -73,13 +73,15 @@ typedef enum
 	ANJUTA_PROJECT_MODIFIED = 1 << 0,		/* Node has been modified */
 	ANJUTA_PROJECT_INCOMPLETE = 1 << 1,	/* Node is not fully loaded */
 	ANJUTA_PROJECT_LOADING = 1 << 2,	/* Node is send to the worker thread */
+	ANJUTA_PROJECT_REMOVED = 1 << 3,		/* Node has been removed */
 	ANJUTA_PROJECT_CAN_ADD_GROUP = 1 << 8,
 	ANJUTA_PROJECT_CAN_ADD_TARGET = 1 << 9,
 	ANJUTA_PROJECT_CAN_ADD_SOURCE = 1 << 10,
 	ANJUTA_PROJECT_CAN_ADD_MODULE = 1 << 11,
 	ANJUTA_PROJECT_CAN_ADD_PACKAGE = 1 << 12,
 	ANJUTA_PROJECT_CAN_REMOVE = 1 << 16,
-	ANJUTA_PROJECT_CAN_SAVE = 1 << 17
+	ANJUTA_PROJECT_CAN_SAVE = 1 << 17,
+	ANJUTA_PROJECT_REMOVE_FILE = 1 << 18
 } AnjutaProjectNodeState;
 
 typedef struct 
@@ -169,6 +171,7 @@ AnjutaProjectNode *anjuta_project_node_insert_after (AnjutaProjectNode *parent,
 AnjutaProjectNode *anjuta_project_node_replace (AnjutaProjectNode *node, AnjutaProjectNode *replacement);
 AnjutaProjectNode *anjuta_project_node_grab_children (AnjutaProjectNode *parent, AnjutaProjectNode *node);
 AnjutaProjectNode *anjuta_project_node_exchange (AnjutaProjectNode *node, AnjutaProjectNode *replacement);
+AnjutaProjectNode *anjuta_project_node_remove (AnjutaProjectNode *node);
 
 void anjuta_project_node_all_foreach (AnjutaProjectNode *node, AnjutaProjectNodeFunc func, gpointer data);
 void anjuta_project_node_children_foreach (AnjutaProjectNode *node, AnjutaProjectNodeFunc func, gpointer data);
diff --git a/plugins/dir-project/dir-project.c b/plugins/dir-project/dir-project.c
index b0955f7..5876bc6 100644
--- a/plugins/dir-project/dir-project.c
+++ b/plugins/dir-project/dir-project.c
@@ -205,7 +205,9 @@ dir_group_new (GFile *file, GObject *emitter)
 	group->base.type = ANJUTA_PROJECT_GROUP;
 	group->base.file = g_object_ref (file);
 	group->base.state = ANJUTA_PROJECT_CAN_ADD_GROUP |
-						ANJUTA_PROJECT_CAN_REMOVE;
+						ANJUTA_PROJECT_CAN_ADD_SOURCE |
+						ANJUTA_PROJECT_CAN_REMOVE |
+						ANJUTA_PROJECT_REMOVE_FILE;
 	
 	group->emitter = emitter;
 	
@@ -238,20 +240,6 @@ dir_group_free (DirGroup *node)
 	g_node_destroy (node);
 }
 
-/* Target objects
- *---------------------------------------------------------------------------*/
-
-static void
-dir_target_free (DirTarget *node)
-{
-    DirTargetData *target = DIR_TARGET_DATA (node);
-	
-    g_free (target->base.name);
-    g_slice_free (DirTargetData, target);
-
-	g_node_destroy (node);
-}
-
 /* Source objects
  *---------------------------------------------------------------------------*/
 
@@ -263,6 +251,8 @@ dir_source_new (GFile *file)
 	source = g_slice_new0(DirSourceData); 
 	source->base.type = ANJUTA_PROJECT_SOURCE;
 	source->base.file = g_object_ref (file);
+	source->base.state = ANJUTA_PROJECT_CAN_REMOVE |
+						ANJUTA_PROJECT_REMOVE_FILE;
 
     return g_node_new (source);
 }
@@ -291,9 +281,6 @@ foreach_node_destroy (AnjutaProjectNode *node,
 		case ANJUTA_PROJECT_GROUP:
 			dir_group_free (node);
 			break;
-		case ANJUTA_PROJECT_TARGET:
-			dir_target_free (node);
-			break;
 		case ANJUTA_PROJECT_SOURCE:
 			dir_source_free (node);
 			break;
@@ -762,9 +749,11 @@ static void
 foreach_node_save (AnjutaProjectNode *node,
 					gpointer  data)
 {
-	gint type = anjuta_project_node_get_full_type (node);
+	gint state = anjuta_project_node_get_state (node);
+	GError *err = NULL;
+	gboolean ret;
 	
-	if (type & ANJUTA_PROJECT_MODIFIED)
+	if (state & ANJUTA_PROJECT_MODIFIED)
 	{
 		switch (anjuta_project_node_get_type (node))
 		{
@@ -775,11 +764,28 @@ foreach_node_save (AnjutaProjectNode *node,
 			break;
 		}
 	}
+	else if (state & ANJUTA_PROJECT_REMOVED)
+	{
+		switch (anjuta_project_node_get_type (node))
+		{
+		case ANJUTA_PROJECT_GROUP:
+			ret = g_file_trash (anjuta_project_node_get_file (node), NULL, &err);
+			if (err != NULL)
+			{
+				g_warning ("trashing file failed with %s", err->message);
+				g_error_free (err);
+			}
+			break;
+		default:
+			break;
+		}
+	}
 }
 
 AnjutaProjectNode *
 dir_project_save_node (DirProject *project, AnjutaProjectNode *node, GError **error)
 {
+	/* Save children */
 	anjuta_project_node_all_foreach (node, foreach_node_save, project);
 	
 	return node;
@@ -995,8 +1001,9 @@ iproject_new_node (IAnjutaProject *obj, AnjutaProjectNode *parent, AnjutaProject
 {
 	AnjutaProjectNode *node;
 	
-	node = project_node_new (DIR_PROJECT (obj), parent, type | ANJUTA_PROJECT_MODIFIED, file, name, error);
-
+	node = project_node_new (DIR_PROJECT (obj), parent, type, file, name, error);
+	anjuta_project_node_set_state (node, ANJUTA_PROJECT_MODIFIED);
+	
 	return node;
 }
 
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index 68cc2ff..2f936d7 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -611,17 +611,30 @@ confirm_removal (ProjectManagerPlugin *plugin, GList *selected)
 	GList *item;
 	GbfTreeNodeType type;
 	gboolean group = FALSE;
+	gboolean remove_group_file = FALSE;
 	gboolean source = FALSE;
-
+	gboolean remove_source_file = FALSE;
+	
 	g_return_val_if_fail (selected != NULL, FALSE);
 
 	type = ((GbfTreeData *)selected->data)->type;
 	for (item = g_list_first (selected); item != NULL; item = g_list_next (item))
 	{
 		GbfTreeData *data = (GbfTreeData *)item->data;
+		AnjutaProjectNode *node;
 
-		if (data->type == GBF_TREE_NODE_GROUP) group = TRUE;
-		if (data->type == GBF_TREE_NODE_SOURCE) source = TRUE;
+		if (data->type == GBF_TREE_NODE_GROUP)
+		{
+			group = TRUE;
+			node = gbf_tree_data_get_node (data);
+			remove_group_file = anjuta_project_node_get_state (node) & ANJUTA_PROJECT_REMOVE_FILE;
+		}
+		if (data->type == GBF_TREE_NODE_SOURCE)
+		{
+			source = TRUE;
+			node = gbf_tree_data_get_node (data);
+			remove_source_file = anjuta_project_node_get_state (node) & ANJUTA_PROJECT_REMOVE_FILE;
+		}
 		if (type != data->type) type = GBF_TREE_NODE_UNKNOWN;
 	}
 
@@ -674,9 +687,13 @@ confirm_removal (ProjectManagerPlugin *plugin, GList *selected)
 	if (group || source)
 	{
 		g_string_append (mesg, "\n");
-		if (group)
+		if (remove_group_file)
+			g_string_append (mesg, _("The group will be deleted from the file system."));
+		else if (group)
 			g_string_append (mesg, _("The group will not be deleted from the file system."));
-		if (source)
+		if (remove_source_file)
+			g_string_append (mesg, _("The source file will be deleted from the file system."));
+		else if (source)
 			g_string_append (mesg, _("The source file will not be deleted from the file system."));
 	}			    
 	
diff --git a/plugins/project-manager/project.c b/plugins/project-manager/project.c
index b716aa5..cd0a0c4 100644
--- a/plugins/project-manager/project.c
+++ b/plugins/project-manager/project.c
@@ -103,6 +103,7 @@ typedef enum
 	LOAD = 0,
 	RELOAD,
 	ADD,
+	REMOVE,
 	EXIT,
 	LAST_COMMAND
 } PmCommand;
@@ -268,7 +269,7 @@ pm_command_load_work (AnjutaPmProject *project, PmJob *job)
 }
 
 static gboolean
-pm_command_add_work (AnjutaPmProject *project, PmJob *job)
+pm_command_save_work (AnjutaPmProject *project, PmJob *job)
 {
 	AnjutaProjectNode *node;
 	
@@ -547,6 +548,41 @@ pm_command_add_setup (AnjutaPmProject *project, PmJob *job)
 	
 	return TRUE;
 }
+
+static gboolean
+pm_command_remove_setup (AnjutaPmProject *project, PmJob *job)
+{
+	GtkTreeIter iter;
+	
+	g_return_val_if_fail (job != NULL, FALSE);
+	g_return_val_if_fail (job->node != NULL, FALSE);
+
+	/* Remove node from project tree */
+	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);
+		
+		return TRUE;
+	}
+	else
+	{
+		return FALSE;
+	}
+}
+
+static gboolean
+pm_command_remove_complete (AnjutaPmProject *project, PmJob *job)
+{
+	g_return_val_if_fail (job != NULL, FALSE);
+	g_return_val_if_fail (job->node != NULL, FALSE);
+
+	/* Remove node from node tree */
+	anjuta_project_node_remove (job->node);
+	anjuta_project_node_all_foreach (job->node, (AnjutaProjectNodeFunc)pm_free_node, project->project);
+	
+	return TRUE;
+}
  
 static PmCommandWork PmCommands[LAST_COMMAND] = {
 			{pm_command_load_setup,
@@ -556,8 +592,11 @@ static PmCommandWork PmCommands[LAST_COMMAND] = {
 			pm_command_load_work,
 			pm_command_load_complete},
 			{pm_command_add_setup,
-			pm_command_add_work,
+			pm_command_save_work,
 			NULL},
+			{pm_command_remove_setup,
+			pm_command_save_work,
+			pm_command_remove_complete},
 			{NULL,
 			pm_command_exit_work,
 			NULL}};
@@ -847,7 +886,7 @@ anjuta_pm_project_add_source (AnjutaPmProject *project, AnjutaProjectNode *targe
 gboolean
 anjuta_pm_project_remove (AnjutaPmProject *project, AnjutaProjectNode *node, GError **error)
 {
-	ianjuta_project_remove_node (project->project, node, error);
+	pm_project_push_command (project, REMOVE, node);
 
 	return TRUE;
 }



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