[anjuta] project-manager: Add a function in the interface to remove a file from a project



commit 1fea8d07ac8d47d1d8c02fe047464be88d7c80c7
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Fri Jul 5 22:54:12 2013 +0200

    project-manager: Add a function in the interface to remove a file from a project

 libanjuta/interfaces/libanjuta.idl |   14 +++++++
 plugins/project-manager/plugin.c   |   68 ++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 0 deletions(-)
---
diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index 6056a89..6db48ba 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -3883,6 +3883,20 @@ interface IAnjutaProjectManager
        GFile* add_group (const gchar *name, GFile *default_group);
 
        /**
+        * ianjuta_project_manager_remove_file:
+        * @obj: Self.
+        * @file: A #GFile that will be removed from the project
+        * @err: Error propagation and reporting.
+        *
+        * Remove a source file from the project. If the file is used in several
+        * targets, it is removed from all targets. The file could be removed from
+        * the disk.
+        *
+        * Returns: %TRUE if the file has been removed from the project else %FALSE
+        */
+       gboolean remove_file (GFile *file);
+
+       /**
        * ianjuta_project_manager_is_open:
        * @obj: Self
        * @err: Error propagation and reporting.
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index ceebd56..38340a9 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -1856,6 +1856,29 @@ get_node_from_file (const AnjutaProjectNode *root, GFile *file)
        return node;
 }
 
+static void
+project_node_compare_and_append (AnjutaProjectNode *node, gpointer data)
+{
+       GList **list = (GList **)data;
+       GFile *file = (GFile *)(*list)->data;
+
+       if (project_node_compare (node, file))
+       {
+               *list = g_list_insert_before (*list, (*list)->next, node);
+       }
+}
+
+static GList*
+get_all_node_from_file (const AnjutaProjectNode *root, GFile *file)
+{
+       GList *list = g_list_append (NULL, file);
+
+       anjuta_project_node_foreach ((AnjutaProjectNode *)root, G_PRE_ORDER, project_node_compare_and_append, 
&list);
+       list = g_list_delete_link (list, list);
+
+       return list;
+}
+
 static GList*
 iproject_manager_get_children (IAnjutaProjectManager *project_manager,
                                                           GFile *parent,
@@ -2236,6 +2259,50 @@ iproject_manager_add_group (IAnjutaProjectManager *project_manager,
 }
 
 static gboolean
+iproject_manager_remove_file (IAnjutaProjectManager *project_manager,
+                              GFile *file,
+                              GError **error)
+{
+       ProjectManagerPlugin *plugin;
+
+       g_return_val_if_fail (ANJUTA_IS_PLUGIN (project_manager), FALSE);
+
+       plugin = ANJUTA_PLUGIN_PROJECT_MANAGER (G_OBJECT (project_manager));
+       if (plugin->project !=  NULL)
+       {
+               AnjutaProjectNode *root;
+
+               root = anjuta_pm_project_get_root  (plugin->project);
+               if (root != NULL)
+               {
+                       GList *list = NULL;
+                       
+                       list = get_all_node_from_file (root, file);
+                       if (list == NULL) return FALSE;
+
+                       update_operation_begin (plugin);
+                       for (; list != NULL; list = g_list_delete_link(list, list))
+                       {
+                               GError *err = NULL;
+
+                               anjuta_pm_project_remove (plugin->project, (AnjutaProjectNode *)list->data, 
&err);
+                               if (err)
+                               {
+                                       g_propagate_error (error, err);
+                                       update_operation_end (plugin, TRUE);
+                                       return FALSE;
+                               }
+                       }
+                       update_operation_end (plugin, TRUE);
+                       
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+static gboolean
 iproject_manager_is_open (IAnjutaProjectManager *project_manager, GError **err)
 {
        ProjectManagerPlugin *plugin;
@@ -2280,6 +2347,7 @@ iproject_manager_iface_init(IAnjutaProjectManagerIface *iface)
        iface->add_sources = iproject_manager_add_source_multi;
        iface->add_target = iproject_manager_add_target;
        iface->add_group = iproject_manager_add_group;
+       iface->remove_file = iproject_manager_remove_file;
        iface->is_open = iproject_manager_is_open;
        iface->get_packages = iproject_manager_get_packages;
        iface->get_current_project = iproject_manager_get_current_project;



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