[anjuta/newproject] Start keeping node pointer in tree data
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/newproject] Start keeping node pointer in tree data
- Date: Tue, 13 Apr 2010 20:41:29 +0000 (UTC)
commit 547c664bd1f07fe6fa8b54cddcff3c05f5be1601
Author: Sébastien Granjoux <seb sfo free fr>
Date: Wed Apr 7 22:06:10 2010 +0200
Start keeping node pointer in tree data
libanjuta/anjuta-project.c | 131 ++++++++++++++++++---
libanjuta/anjuta-project.h | 7 +
plugins/am-project/am-project.c | 2 +-
plugins/project-manager/gbf-project-model.c | 39 ++++++-
plugins/project-manager/gbf-project-model.h | 5 +
plugins/project-manager/gbf-project-util.c | 2 +-
plugins/project-manager/gbf-project-view.c | 52 +++++++--
plugins/project-manager/gbf-project-view.h | 1 +
plugins/project-manager/gbf-tree-data.c | 163 +++++----------------------
plugins/project-manager/gbf-tree-data.h | 10 +-
plugins/project-manager/plugin.c | 44 +------
plugins/project-manager/project.c | 99 ++++++++++++++++
plugins/project-manager/project.h | 1 +
13 files changed, 348 insertions(+), 208 deletions(-)
---
diff --git a/libanjuta/anjuta-project.c b/libanjuta/anjuta-project.c
index 0a9ba86..5c3f457 100644
--- a/libanjuta/anjuta-project.c
+++ b/libanjuta/anjuta-project.c
@@ -50,7 +50,16 @@
/* convenient shortcut macro the get the AnjutaProjectNode from a GNode */
#define NODE_DATA(node) ((node) != NULL ? (AnjutaProjectNodeData *)((node)->data) : NULL)
+#define PROXY_DATA(node) ((node) != NULL ? (AnjutaProjectProxyData *)((node)->data) : NULL)
+/* Properties functions
+ *---------------------------------------------------------------------------*/
+
+typedef struct {
+ AnjutaProjectNodeData base;
+ AnjutaProjectNode *node;
+ guint reference;
+} AnjutaProjectProxyData;
/* Properties functions
*---------------------------------------------------------------------------*/
@@ -363,28 +372,21 @@ anjuta_project_node_get_uri (AnjutaProjectNode *node)
GFile*
anjuta_project_node_get_file (AnjutaProjectNode *node)
{
- AnjutaProjectNode *parent;
- GFile *file;
-
- switch (NODE_DATA (node)->type & ANJUTA_PROJECT_TYPE_MASK)
+ AnjutaProjectNodeData *data = NODE_DATA (node);
+
+ if ((data->file == NULL) && (data->name != NULL))
{
- case ANJUTA_PROJECT_TARGET:
+ /* Try to create a file */
+ AnjutaProjectNode *parent;
+
parent = anjuta_project_node_parent (node);
- file = g_file_get_child (anjuta_project_group_get_directory (parent), anjuta_project_target_get_name (node));
- break;
- case ANJUTA_PROJECT_GROUP:
- case ANJUTA_PROJECT_SOURCE:
- case ANJUTA_PROJECT_MODULE:
- case ANJUTA_PROJECT_PACKAGE:
- case ANJUTA_PROJECT_ROOT:
- file = g_object_ref (NODE_DATA (node)->file);
- break;
- default:
- file = NULL;
- break;
+ if (NODE_DATA (parent)->file != NULL)
+ {
+ data->file = g_file_get_child (NODE_DATA (parent)->file, data->name);
+ }
}
- return file;
+ return data->file;
}
AnjutaProjectPropertyList *
@@ -603,3 +605,96 @@ anjuta_project_target_type_class (const AnjutaProjectTargetType type)
{
return type->base;
}
+
+/* Proxy node functions
+ *---------------------------------------------------------------------------*/
+
+AnjutaProjectNode *
+anjuta_project_proxy_new (AnjutaProjectNode *node)
+{
+ if (NODE_DATA (node)->type & ANJUTA_PROJECT_PROXY)
+ {
+ PROXY_DATA (node)->reference++;
+ }
+ else
+ {
+ AnjutaProjectProxyData *proxy;
+ AnjutaProjectNodeData *data = NODE_DATA (node);
+
+ proxy = g_slice_new0(AnjutaProjectProxyData);
+ proxy->reference = 1;
+ proxy->node = node;
+ proxy->base.type = data->type | ANJUTA_PROJECT_PROXY;
+ if ((data->properties == NULL) || (((AnjutaProjectPropertyInfo *)data->properties->data)->override == NULL))
+ {
+ proxy->base.properties = data->properties;
+ }
+ else
+ {
+ GList *item;
+ proxy->base.properties = g_list_copy (data->properties);
+ for (item = g_list_first (proxy->base.properties); item != NULL; item = g_list_next (item))
+ {
+ AnjutaProjectPropertyInfo *info = (AnjutaProjectPropertyInfo *)item->data;
+ AnjutaProjectPropertyInfo *new_info;
+
+ new_info = g_slice_new0(AnjutaProjectPropertyInfo);
+ new_info->name = g_strdup (info->name);
+ new_info->type = info->type;
+ new_info->value = g_strdup (info->value);
+ new_info->override = info->override;
+ item->data = new_info;
+ }
+ }
+ proxy->base.file = g_object_ref (data->file);
+ proxy->base.name = g_strdup (data->name);
+ proxy->base.target_type = data->target_type;
+ node = g_node_new (proxy);
+ }
+
+ return node;
+}
+
+AnjutaProjectNode *
+anjuta_project_proxy_unref (AnjutaProjectNode *node)
+{
+ if (NODE_DATA (node)->type & ANJUTA_PROJECT_PROXY)
+ {
+ PROXY_DATA (node)->reference--;
+
+ if (PROXY_DATA (node)->reference == 0)
+ {
+ AnjutaProjectProxyData *proxy = PROXY_DATA (node);
+
+ if (proxy->base.file) g_object_unref (proxy->base.file);
+ g_free (proxy->base.name);
+ if ((proxy->base.properties != NULL) && (((AnjutaProjectPropertyInfo *)proxy->base.properties->data)->override != NULL))
+ {
+ GList *item;
+
+ for (item = g_list_first (proxy->base.properties); item != NULL; item = g_list_next (item))
+ {
+ AnjutaProjectPropertyInfo *info = (AnjutaProjectPropertyInfo *)item->data;
+
+ g_free (info->name);
+ g_free (info->value);
+ g_slice_free (AnjutaProjectPropertyInfo, info);
+ }
+ g_list_free (proxy->base.properties);
+ }
+ g_slice_free (AnjutaProjectProxyData, proxy);
+ g_node_destroy (node);
+ node = NULL;
+ }
+ }
+
+ return node;
+}
+
+gboolean
+anjuta_project_node_is_proxy (AnjutaProjectNode *node)
+{
+ g_return_val_if_fail (node != NULL, FALSE);
+
+ return NODE_DATA (node)->type & ANJUTA_PROJECT_PROXY ? TRUE : FALSE;
+}
diff --git a/libanjuta/anjuta-project.h b/libanjuta/anjuta-project.h
index 68e6004..a0de46a 100644
--- a/libanjuta/anjuta-project.h
+++ b/libanjuta/anjuta-project.h
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
typedef enum
{
ANJUTA_PROJECT_UNKNOWN = 0,
+ ANJUTA_PROJECT_PROXY = 1 << 14,
ANJUTA_PROJECT_EXECUTABLE = 1 << 15,
ANJUTA_PROJECT_TYPE_MASK = 0xFFFF << 16,
ANJUTA_PROJECT_ROOT = 1 << 16,
@@ -191,6 +192,12 @@ const gchar *anjuta_project_target_type_name (const AnjutaProjectTargetType type
const gchar *anjuta_project_target_type_mime (const AnjutaProjectTargetType type);
AnjutaProjectTargetClass anjuta_project_target_type_class (const AnjutaProjectTargetType type);
+AnjutaProjectNode *anjuta_project_proxy_new (AnjutaProjectNode *node);
+AnjutaProjectNode *anjuta_project_proxy_unref (AnjutaProjectNode *node);
+
+gboolean anjuta_project_node_is_proxy (AnjutaProjectNode *node);
+
+
G_END_DECLS
#endif
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index 80b180d..4e21bfe 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -1853,7 +1853,7 @@ amp_project_load_node (AmpProject *project, AnjutaProjectNode *node, GError **er
amp_project_unload (project);
DEBUG_PRINT ("reload project %p root file %p", project, root_file);
- root_file = anjuta_project_node_get_file (node);
+ root_file = g_object_ref (anjuta_project_node_get_file (node));
g_message ("reload project %s", g_file_get_path (root_file));
project->root_file = root_file;
project->root_node = node;
diff --git a/plugins/project-manager/gbf-project-model.c b/plugins/project-manager/gbf-project-model.c
index 9f61c6e..babda0b 100644
--- a/plugins/project-manager/gbf-project-model.c
+++ b/plugins/project-manager/gbf-project-model.c
@@ -837,6 +837,43 @@ gbf_project_model_find_tree_data (GbfProjectModel *model,
return retval;
}
+gboolean
+gbf_project_model_find_tree_file (GbfProjectModel *model,
+ GtkTreeIter *found,
+ GtkTreeIter *parent,
+ AnjutaProjectNodeType type,
+ GFile *file)
+{
+ GtkTreeIter iter;
+ gboolean valid;
+
+ /* Search for direct children */
+ for (valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (model), &iter, parent); valid == TRUE; valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter))
+ {
+ GbfTreeData *data;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
+ GBF_PROJECT_MODEL_COLUMN_DATA, &data, -1);
+
+ if (gbf_tree_data_equal_file (data, type, file))
+ {
+ *found = iter;
+ break;
+ }
+ }
+
+ /* Search for children of children */
+ if (!valid)
+ {
+ for (valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (model), &iter, parent); valid == TRUE; valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter))
+ {
+ if (gbf_project_model_find_tree_file (model, found, &iter, type, file)) return TRUE;
+ }
+ }
+
+ return valid;
+}
+
GbfProjectModel *
gbf_project_model_new (AnjutaPmProject *project)
{
@@ -889,7 +926,7 @@ gbf_project_model_get_node (GbfProjectModel *model,
GBF_PROJECT_MODEL_COLUMN_DATA, &data,
-1);
- return anjuta_pm_project_get_node (model->priv->proj, data);
+ return gbf_tree_data_get_node (data);
}
void
diff --git a/plugins/project-manager/gbf-project-model.h b/plugins/project-manager/gbf-project-model.h
index a20ca3e..dbeeae4 100644
--- a/plugins/project-manager/gbf-project-model.h
+++ b/plugins/project-manager/gbf-project-model.h
@@ -67,6 +67,11 @@ gboolean gbf_project_model_remove (GbfProjectModel *model,
gboolean gbf_project_model_find_tree_data (GbfProjectModel *model,
GtkTreeIter *iter,
GbfTreeData *data);
+gboolean gbf_project_model_find_tree_file (GbfProjectModel *model,
+ GtkTreeIter *iter,
+ GtkTreeIter *parent,
+ AnjutaProjectNodeType type,
+ GFile *file);
AnjutaProjectNode *gbf_project_model_get_node (GbfProjectModel *model,
GtkTreeIter *iter);
diff --git a/plugins/project-manager/gbf-project-util.c b/plugins/project-manager/gbf-project-util.c
index 5ccf039..3963990 100644
--- a/plugins/project-manager/gbf-project-util.c
+++ b/plugins/project-manager/gbf-project-util.c
@@ -868,7 +868,7 @@ gbf_project_util_replace_by_file (GList* list)
{
AnjutaProjectNode *node = (AnjutaProjectNode *)link->data;
- link->data = anjuta_project_node_get_file (node);
+ link->data = g_object_ref (anjuta_project_node_get_file (node));
}
return list;
diff --git a/plugins/project-manager/gbf-project-view.c b/plugins/project-manager/gbf-project-view.c
index 55b9621..0731a96 100644
--- a/plugins/project-manager/gbf-project-view.c
+++ b/plugins/project-manager/gbf-project-view.c
@@ -452,7 +452,7 @@ gbf_project_view_get_first_selected (GbfProjectView *view, GtkTreeIter* selected
}
static void
-on_each_selected_node (GtkTreeModel *model,
+on_each_get_data (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer user_data)
@@ -485,7 +485,42 @@ gbf_project_view_get_all_selected (GbfProjectView *view)
g_return_val_if_fail (GBF_IS_PROJECT_VIEW (view), FALSE);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
- gtk_tree_selection_selected_foreach (selection, on_each_selected_node, &selected);
+ gtk_tree_selection_selected_foreach (selection, on_each_get_data, &selected);
+
+ return g_list_reverse (selected);
+}
+
+static void
+on_each_get_iter (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ GList **selected = (GList **)user_data;
+ GbfTreeData *data;
+
+ /*if (GTK_IS_TREE_MODEL_FILTER (model))
+ {
+ GtkTreeIter child_iter;
+
+ gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, iter);
+ *iter = child_iter;
+ }*/
+
+ *selected = g_list_prepend (*selected, gtk_tree_iter_copy (iter));
+}
+
+GList *
+gbf_project_view_get_all_selected_iter (GbfProjectView *view)
+{
+ GtkTreeSelection *selection;
+ GList *selected = NULL;
+
+ g_return_val_if_fail (view != NULL, FALSE);
+ g_return_val_if_fail (GBF_IS_PROJECT_VIEW (view), FALSE);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+ gtk_tree_selection_selected_foreach (selection, on_each_get_iter, &selected);
return g_list_reverse (selected);
}
@@ -573,7 +608,7 @@ gbf_project_view_set_shortcut_list (GbfProjectView *view, GList *shortcuts)
for (node = g_list_first (shortcuts); node != NULL; node = g_list_next (node))
{
- GbfTreeData *data;
+ GFile *file;
GtkTreeIter shortcut;
gboolean expand = FALSE;
gchar *path = (gchar *)node->data;
@@ -588,12 +623,12 @@ gbf_project_view_set_shortcut_list (GbfProjectView *view, GList *shortcuts)
expand = FALSE;
path += 2;
}
- data = gbf_tree_data_new_for_path (path);
-
- if (gbf_project_model_find_tree_data (GBF_PROJECT_MODEL (model), &shortcut, data))
+ file = g_file_new_for_path (path);
+
+ if (gbf_project_model_find_tree_file (GBF_PROJECT_MODEL (model), &shortcut, NULL, ANJUTA_PROJECT_UNKNOWN, file))
{
GbfTreeData *data;
-
+
gtk_tree_model_get (GTK_TREE_MODEL (model), &shortcut,
GBF_PROJECT_MODEL_COLUMN_DATA, &data,
-1);
@@ -614,8 +649,7 @@ gbf_project_view_set_shortcut_list (GbfProjectView *view, GList *shortcuts)
/* Mark the shortcut as used */
*path = 'U';
}
-
- gbf_tree_data_free (data);
+ g_object_unref (file);
}
}
}
diff --git a/plugins/project-manager/gbf-project-view.h b/plugins/project-manager/gbf-project-view.h
index a36e2da..f97674d 100644
--- a/plugins/project-manager/gbf-project-view.h
+++ b/plugins/project-manager/gbf-project-view.h
@@ -66,6 +66,7 @@ AnjutaProjectNode *gbf_project_view_find_selected (GbfProjectView *
GbfTreeData *gbf_project_view_get_first_selected(GbfProjectView *view,
GtkTreeIter *selected);
GList *gbf_project_view_get_all_selected (GbfProjectView *view);
+GList *gbf_project_view_get_all_selected_iter (GbfProjectView *view);
GList *gbf_project_view_get_shortcut_list (GbfProjectView *view);
void gbf_project_view_set_shortcut_list (GbfProjectView *view,
diff --git a/plugins/project-manager/gbf-tree-data.c b/plugins/project-manager/gbf-tree-data.c
index 3748398..209660b 100644
--- a/plugins/project-manager/gbf-tree-data.c
+++ b/plugins/project-manager/gbf-tree-data.c
@@ -55,6 +55,7 @@
gchar *
gbf_tree_data_get_uri (GbfTreeData *data)
{
+ //return g_file_get_uri (anjuta_project_node_get_file (data->node));
if (data->source != NULL)
{
return g_file_get_uri (data->source);
@@ -81,6 +82,7 @@ gbf_tree_data_get_uri (GbfTreeData *data)
GFile *
gbf_tree_data_get_file (GbfTreeData *data)
{
+ //return g_object_ref (anjuta_project_node_get_file (data->node));
if (data->source != NULL)
{
return g_object_ref (g_file_get_uri (data->source));
@@ -104,23 +106,19 @@ gbf_tree_data_get_file (GbfTreeData *data)
gchar *
gbf_tree_data_get_path (GbfTreeData *data)
{
- gchar *path;
- gchar *guri;
- gchar *suri;
-
- guri = data->group != NULL ? g_file_get_uri (data->group) : NULL;
- suri = data->source != NULL ? g_file_get_uri (data->source) : NULL;
- path = g_strconcat (guri, " ", data->target, " ", suri, NULL);
- g_free (suri);
- g_free (guri);
-
- return path;
+ return data->node ? g_file_get_path (anjuta_project_node_get_file (data->node)) : NULL;
}
const gchar *
gbf_tree_data_get_name (GbfTreeData *data)
{
- return data->name;
+ return data->node != NULL ? anjuta_project_node_get_name (data->node) : data->name;
+}
+
+AnjutaProjectNode *
+gbf_tree_data_get_node (GbfTreeData *data)
+{
+ return data->node;
}
gboolean
@@ -191,144 +189,31 @@ gbf_tree_data_equal (GbfTreeData *data_a, GbfTreeData *data_b)
return equal;
}
-GbfTreeData *
-gbf_tree_data_new_for_path (const gchar *path)
+gboolean
+gbf_tree_data_equal_file (GbfTreeData *data, AnjutaProjectNodeType type, GFile *file)
{
- GbfTreeData *data = g_slice_new0 (GbfTreeData);
- gchar **uris;
+ gboolean equal = FALSE;
- uris = g_strsplit (path, " ", 3);
-
- if (uris != NULL)
+ if (data != NULL)
{
- if ((uris[0] != NULL) && (*uris[0] != '\0'))
- {
- data->group = g_file_new_for_uri (uris[0]);
+ AnjutaProjectNode *node = gbf_tree_data_get_node (data);
- if ((uris[1] != NULL) && (*uris[1] != '\0'))
+ if (node != NULL)
+ {
+ if ((type == ANJUTA_PROJECT_UNKNOWN) || (type == anjuta_project_node_get_type (node)))
{
- data->target = g_strdup (uris[1]);
-
- if ((uris[2] != NULL) && (*uris[2] != '\0'))
+ if (g_file_equal (anjuta_project_node_get_file (node), file))
{
- data->source = g_file_new_for_uri (uris[2]);
+ equal = TRUE;
}
}
}
}
-
- if (data->source != NULL)
- {
- GFileInfo *ginfo;
-
- data->type = GBF_TREE_NODE_SOURCE;
-
- ginfo = g_file_query_info (data->source,
- G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
- G_FILE_QUERY_INFO_NONE,
- NULL, NULL);
- if (ginfo)
- {
- data->name = g_strdup (g_file_info_get_display_name (ginfo));
- g_object_unref(ginfo);
- }
- else
- {
- data->name = g_file_get_basename (data->source);
- }
- }
- else if (data->target != NULL)
- {
- data->type = GBF_TREE_NODE_TARGET;
-
- data->name = g_strdup (data->target);
- }
- else if (data->group != NULL)
- {
- GFileInfo *ginfo;
-
- data->type = GBF_TREE_NODE_GROUP;
-
- ginfo = g_file_query_info (data->group,
- G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
- G_FILE_QUERY_INFO_NONE,
- NULL, NULL);
- if (ginfo)
- {
- data->name = g_strdup (g_file_info_get_display_name (ginfo));
- g_object_unref(ginfo);
- }
- else
- {
- data->name = g_file_get_basename (data->group);
- }
- }
- else
- {
- data->type = GBF_TREE_NODE_STRING;
- data->name = g_strdup ("?");
- }
- g_strfreev (uris);
-
- return data;
+ return equal;
}
GbfTreeData *
-gbf_tree_data_new_for_file (GFile *file, GbfTreeNodeType type)
-{
- GbfTreeData *data = g_slice_new0 (GbfTreeData);
- GFileInfo *ginfo;
-
- data->type = type;
-
- switch (type)
- {
- case GBF_TREE_NODE_UNKNOWN:
- case GBF_TREE_NODE_SHORTCUT:
- case GBF_TREE_NODE_GROUP:
- data->group = g_object_ref (file);
- break;
- case GBF_TREE_NODE_TARGET:
- data->group = g_file_get_parent (file);
- data->target = g_file_get_basename (file);
- file = NULL;
- data->name = g_strdup (data->target);
- break;
- case GBF_TREE_NODE_SOURCE:
- data->source = g_object_ref (file);
- break;
- case GBF_TREE_NODE_STRING:
- data->name = g_file_get_parse_name (file);
- file = NULL;
- break;
- case GBF_TREE_NODE_MODULE:
- case GBF_TREE_NODE_PACKAGE:
- g_slice_free (GbfTreeData, data);
- return NULL;
- }
-
- if (file != NULL)
- {
- ginfo = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
- G_FILE_QUERY_INFO_NONE,
- NULL, NULL);
- if (ginfo)
- {
- data->name = g_strdup (g_file_info_get_display_name (ginfo));
- g_object_unref(ginfo);
- }
- else
- {
- data->name = g_file_get_basename (data->group);
- }
- }
-
- return data;
-}
-
-GbfTreeData *
gbf_tree_data_new_string (const gchar *string)
{
GbfTreeData *data = g_slice_new0 (GbfTreeData);
@@ -345,6 +230,7 @@ gbf_tree_data_new_shortcut (GbfTreeData *src)
GbfTreeData *data = g_slice_new0 (GbfTreeData);
data->type = GBF_TREE_NODE_SHORTCUT;
+ data->node = src->node;
data->name = g_strdup (src->name);
data->group = src->group == NULL ? NULL : g_object_ref (src->group);
data->target = g_strdup (src->target);
@@ -363,6 +249,7 @@ gbf_tree_data_new_group (AnjutaProjectNode *group)
GFileInfo *ginfo;
data->type = GBF_TREE_NODE_GROUP;
+ data->node = group;
ginfo = g_file_query_info (anjuta_project_group_get_directory (group),
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
@@ -390,6 +277,7 @@ gbf_tree_data_new_target (AnjutaProjectNode *target)
AnjutaProjectNode *group;
data->type = GBF_TREE_NODE_TARGET;
+ data->node = target;
data->name = g_strdup (anjuta_project_target_get_name (target));
group = anjuta_project_node_parent (target);
@@ -407,6 +295,7 @@ gbf_tree_data_new_source (AnjutaProjectNode *source)
AnjutaProjectNode *parent;
data->type = GBF_TREE_NODE_SOURCE;
+ data->node = source;
data->source = g_object_ref (anjuta_project_source_get_file (source));
@@ -447,6 +336,7 @@ gbf_tree_data_new_module (AnjutaProjectNode *module)
GbfTreeData *data = g_slice_new0 (GbfTreeData);
data->type = GBF_TREE_NODE_MODULE;
+ data->node = module;
data->name = g_strdup (anjuta_project_node_get_name (module));
return data;
@@ -458,6 +348,7 @@ gbf_tree_data_new_package (AnjutaProjectNode *package)
GbfTreeData *data = g_slice_new0 (GbfTreeData);
data->type = GBF_TREE_NODE_PACKAGE;
+ data->node = package;
data->name = g_strdup (anjuta_project_node_get_name (package));
return data;
diff --git a/plugins/project-manager/gbf-tree-data.h b/plugins/project-manager/gbf-tree-data.h
index 46517a6..b9112f6 100644
--- a/plugins/project-manager/gbf-tree-data.h
+++ b/plugins/project-manager/gbf-tree-data.h
@@ -45,6 +45,7 @@ typedef enum {
struct _GbfTreeData
{
GbfTreeNodeType type;
+ AnjutaProjectNode *node;
gchar *name;
GFile *group;
gchar *target;
@@ -56,16 +57,17 @@ struct _GbfTreeData
gchar *gbf_tree_data_get_uri (GbfTreeData *data);
GFile *gbf_tree_data_get_file (GbfTreeData *data);
-const gchar *gdb_tree_data_get_name (GbfTreeData *data);
+const gchar *gbf_tree_data_get_name (GbfTreeData *data);
+AnjutaProjectNode *gbf_tree_data_get_node (GbfTreeData *data);
gchar *gbf_tree_data_get_path (GbfTreeData *data);
gboolean gbf_tree_data_equal (GbfTreeData *data_a,
GbfTreeData *data_b);
+gboolean gbf_tree_data_equal_file (GbfTreeData *data,
+ AnjutaProjectNodeType type,
+ GFile *file);
-GbfTreeData *gbf_tree_data_new_for_path (const gchar *data);
-GbfTreeData *gbf_tree_data_new_for_file (GFile *file,
- GbfTreeNodeType type);
GbfTreeData *gbf_tree_data_new_string (const gchar *string);
GbfTreeData *gbf_tree_data_new_shortcut (GbfTreeData *src);
GbfTreeData *gbf_tree_data_new_group (AnjutaProjectNode *group);
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index af9eae1..951cf89 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -1951,44 +1951,12 @@ get_element_file_from_node (ProjectManagerPlugin *plugin, AnjutaProjectNode *nod
return file;
}
-static AnjutaProjectNode*
-get_project_node_from_file (ProjectManagerPlugin *plugin, GFile *file, AnjutaProjectNodeType type)
-{
- GbfTreeData *data;
- AnjutaProjectNode *node;
-
- switch (type)
- {
- case ANJUTA_PROJECT_GROUP:
- data = gbf_tree_data_new_for_file (file, GBF_TREE_NODE_GROUP);
- break;
- case ANJUTA_PROJECT_TARGET:
- data = gbf_tree_data_new_for_file (file, GBF_TREE_NODE_TARGET);
- break;
- case ANJUTA_PROJECT_SOURCE:
- data = gbf_tree_data_new_for_file (file, GBF_TREE_NODE_SOURCE);
- break;
- case ANJUTA_PROJECT_UNKNOWN:
- default:
- data = gbf_tree_data_new_for_file (file, GBF_TREE_NODE_UNKNOWN);
- break;
- }
-
- node = anjuta_pm_project_get_node (plugin->project, data);
- gbf_tree_data_free (data);
-
- return node;
-}
-
static GtkTreeIter*
get_tree_iter_from_file (ProjectManagerPlugin *plugin, GtkTreeIter* iter, GFile *file, GbfTreeNodeType type)
{
- GbfTreeData *data;
gboolean found;
-
- data = gbf_tree_data_new_for_file (file, type);
- found = gbf_project_model_find_tree_data (anjuta_pm_project_get_model (plugin->project), iter, data);
- gbf_tree_data_free (data);
+
+ found = gbf_project_model_find_tree_file (anjuta_pm_project_get_model (plugin->project), iter, NULL, type, file);
return found ? iter : NULL;
}
@@ -1996,9 +1964,9 @@ get_tree_iter_from_file (ProjectManagerPlugin *plugin, GtkTreeIter* iter, GFile
static AnjutaProjectNodeType
get_element_type (ProjectManagerPlugin *plugin, GFile *element)
{
- AnjutaProjectNode *node = NULL;
+ AnjutaProjectNode *node;
- node = get_project_node_from_file (plugin, element, ANJUTA_PROJECT_UNKNOWN);
+ node = anjuta_pm_project_get_node_from_file (plugin->project, ANJUTA_PROJECT_UNKNOWN, element);
return node == NULL ? ANJUTA_PROJECT_UNKNOWN : anjuta_project_node_get_type (node);
}
@@ -2033,7 +2001,7 @@ iproject_manager_get_target_type (IAnjutaProjectManager *project_manager,
g_return_val_if_fail (file_is_inside_project (plugin, target_file),
ANJUTA_TARGET_UNKNOWN);
- target = get_project_node_from_file (plugin, target_file, ANJUTA_PROJECT_TARGET);
+ target = anjuta_pm_project_get_node_from_file (plugin->project, ANJUTA_PROJECT_TARGET, target_file);
if (target != NULL)
{
@@ -2216,7 +2184,7 @@ iproject_manager_add_source_quiet (IAnjutaProjectManager *project_manager,
plugin = ANJUTA_PLUGIN_PROJECT_MANAGER (G_OBJECT (project_manager));
- target = get_project_node_from_file (plugin, location_file, ANJUTA_PROJECT_TARGET);
+ target = anjuta_pm_project_get_node_from_file (plugin->project, ANJUTA_PROJECT_TARGET, location_file);
source_file = g_file_new_for_uri (source_uri_to_add);
update_operation_begin (plugin);
source_id = anjuta_pm_project_add_source (plugin->project,
diff --git a/plugins/project-manager/project.c b/plugins/project-manager/project.c
index 2a4db5d..8bd003b 100644
--- a/plugins/project-manager/project.c
+++ b/plugins/project-manager/project.c
@@ -31,6 +31,69 @@
#include "gbf-project-model.h"
#include "gbf-project-view.h"
+
+/*
+
+2 Threads: GUI and Work
+
+Add new source.
+
+1. Work add new node
+ + Obvious, because it has the parent node
+ - Not possible, if the GUI has to get all child of the same node
+
+2. Work add new node, GUI use tree data
+
+3. Work create new node only but doesn't add it
+
+4. GUI create a new node and call the save function later
+
+
+The GUI cannot change links, else the Work cannot follow links when getting a
+node. The Work can even need parent links.
+=> GUI cannot read links except in particular case
+
+The GUI can read and write common part
+=> We need to copy the properties anyway when changing them
+
+The GUI can only read common part
+=>
+
+Have a proxy node for setting properties, this proxy will copy add common data
+and keep a link with the original node and reference count. The GUI can still
+read all data in the proxy without disturbing the Work which can change the
+underlines node. The proxy address is returned immediatly when the
+set_properties function is used. If another set_properties is done on the same
+node the proxy is reused, incrementing reference count.
+
+There is no need to proxy after add or remove functions, because the links are
+already copied in the module.
+
+After changing a property should we reload automatically ?
+
+
+Reloading a node can change its property, so we need a proxy for the load too.
+
+Proxy has to be created in GUI, because we need to update tree data.
+
+Instead of using a Proxy, we can copy all data everytime, this will allow
+automatic reload.
+
+
+
+ Work has always a full access to link
+ GUI read a special GNode tree created by thread
+
+ Work can always read common data, and can write them before sending them to GUI
+ or in when modification are requested by the GUI (the GUI get a proxy)
+ GUI can only read common data
+
+ Work has always a full access to specific data.
+ GUI has no access to specific data
+
+
+*/
+
/* Types
*---------------------------------------------------------------------------*/
@@ -38,6 +101,7 @@ typedef enum
{
LOAD,
UNLOAD,
+ RELOAD,
EXIT
} PmCommand;
@@ -339,6 +403,26 @@ anjuta_pm_project_load (AnjutaPmProject *project, GFile *file, GError **error)
return TRUE;
}
+static void
+on_pm_project_reloaded (AnjutaPmProject *project, PmJob *job)
+{
+ if (job->error == NULL)
+ {
+ project->root = job->node;
+ g_object_set (G_OBJECT (project->model), "project", project, NULL);
+ }
+ g_signal_emit (G_OBJECT (project), signals[UPDATED], 0, job->error);
+}
+
+gboolean
+anjuta_pm_project_reload_node (AnjutaPmProject *project, AnjutaProjectNode *node, GError **error)
+{
+
+ pm_project_push_command (project, RELOAD, NULL, NULL, node, on_pm_project_reloaded);
+
+ return TRUE;
+}
+
gboolean
anjuta_pm_project_unload (AnjutaPmProject *project, GError **error)
{
@@ -514,6 +598,21 @@ anjuta_pm_project_get_node (AnjutaPmProject *project, GbfTreeData *data)
return node;
}
+AnjutaProjectNode *
+anjuta_pm_project_get_node_from_file (AnjutaPmProject *project, AnjutaProjectNodeType type, GFile *file)
+{
+ GtkTreeIter iter;
+ AnjutaProjectNode *node = NULL;
+
+ if (gbf_project_model_find_tree_file (project->model, &iter, NULL, type, file))
+ {
+
+ node = gbf_project_model_get_node (project->model, &iter);
+ }
+
+ return NULL;
+}
+
/* Implement GObject
*---------------------------------------------------------------------------*/
diff --git a/plugins/project-manager/project.h b/plugins/project-manager/project.h
index 2b4ca6b..8877916 100644
--- a/plugins/project-manager/project.h
+++ b/plugins/project-manager/project.h
@@ -97,6 +97,7 @@ IAnjutaProject *anjuta_pm_project_get_project (AnjutaPmProject *project);
GbfProjectModel *anjuta_pm_project_get_model (AnjutaPmProject *project);
AnjutaProjectNode *anjuta_pm_project_get_node (AnjutaPmProject *project, GbfTreeData *data);
+AnjutaProjectNode *anjuta_pm_project_get_node_from_file (AnjutaPmProject *project, AnjutaProjectNodeType type, GFile *file);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]