[anjuta] pm: Fix shortcut update
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [anjuta] pm: Fix shortcut update
- Date: Sat, 2 Jan 2010 15:06:37 +0000 (UTC)
commit d91cdd73bde907081f578be21c6e86d335b41d00
Author: Sébastien Granjoux <seb sfo free fr>
Date: Sat Jan 2 12:14:29 2010 +0100
pm: Fix shortcut update
plugins/gbf-am/gbf-am-project.c | 2 +-
plugins/project-manager/gbf-project-model.c | 239 ++++++++++-----------------
plugins/project-manager/gbf-project-util.c | 4 +-
plugins/project-manager/gbf-tree-data.c | 4 +
plugins/project-manager/plugin.c | 2 +-
5 files changed, 96 insertions(+), 155 deletions(-)
---
diff --git a/plugins/gbf-am/gbf-am-project.c b/plugins/gbf-am/gbf-am-project.c
index eb5a018..10516a2 100644
--- a/plugins/gbf-am/gbf-am-project.c
+++ b/plugins/gbf-am/gbf-am-project.c
@@ -3941,7 +3941,7 @@ iproject_get_root (IAnjutaProject *obj, GError **err)
static GList*
iproject_get_target_types (IAnjutaProject *obj, GError **err)
{
- GbfAmTargetInformation *targets = GbfAmTargetTypes;
+ GbfAmTargetInformation *targets = &GbfAmTargetTypes[1]; /* Skip unknown target */
GList *types = NULL;
g_message ("iproject_get_target_types");
diff --git a/plugins/project-manager/gbf-project-model.c b/plugins/project-manager/gbf-project-model.c
index 1a12e27..c42e56b 100644
--- a/plugins/project-manager/gbf-project-model.c
+++ b/plugins/project-manager/gbf-project-model.c
@@ -42,7 +42,6 @@ struct _GbfProjectModelPrivate {
GtkTreeRowReference *root_row;
GList *shortcuts;
- GbfTreeData *empty_node;
};
enum {
@@ -197,11 +196,6 @@ dispose (GObject *obj)
{
GbfProjectModel *model = GBF_PROJECT_MODEL (obj);
- if (model->priv->empty_node) {
- gbf_tree_data_free (model->priv->empty_node);
- model->priv->empty_node = NULL;
- }
-
if (model->priv->proj) {
unload_project (model);
}
@@ -250,7 +244,6 @@ gbf_project_model_instance_init (GbfProjectModel *model)
model->priv = g_new0 (GbfProjectModelPrivate, 1);
- model->priv->empty_node = gbf_tree_data_new_string (_("No project loaded"));
/* sorting function */
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (model),
default_sort_func,
@@ -401,6 +394,19 @@ remove_shortcut (GbfProjectModel *model, const AnjutaProjectTarget *target)
}
}
+static void
+update_shortcut (GbfProjectModel *model, const AnjutaProjectTarget *new_target, const AnjutaProjectTarget *old_target)
+{
+ GList *l;
+
+ for (l = model->priv->shortcuts; l; l = l->next) {
+ if (old_target == l->data) {
+ l->data = (gpointer)new_target;
+ break;
+ }
+ }
+}
+
static void
add_target_shortcut (GbfProjectModel *model,
AnjutaProjectTarget *target,
@@ -505,54 +511,6 @@ add_target (GbfProjectModel *model,
}
}
-static void
-update_target (GbfProjectModel *model, AnjutaProjectTarget *target, GtkTreeIter *iter)
-{
- GtkTreeModel *tree_model;
- GtkTreeIter child;
- GList *sources;
- GList *node;
-
- tree_model = GTK_TREE_MODEL (model);
- if ((!target) || (anjuta_project_node_get_type (target) != ANJUTA_PROJECT_TARGET))
- return;
-
- /* update target data here */
- sources = gbf_project_util_all_child (target, ANJUTA_PROJECT_SOURCE);
-
- /* walk the tree target */
- if (gtk_tree_model_iter_children (tree_model, &child, iter)) {
- gboolean valid = TRUE;
-
- while (valid) {
- AnjutaProjectNode *data;
-
- /* find the iterating id in the target's sources */
- data = gbf_project_model_get_node (model, &child);
-
- if (data) {
- node = g_list_find (sources, data);
- if (node) {
- sources = g_list_delete_link (sources, node);
- valid = gtk_tree_model_iter_next (tree_model, &child);
- } else {
- valid = gbf_project_model_remove (model, &child);
- }
- }
- else
- {
- valid = gbf_project_model_remove (model, &child);
- }
- }
- }
-
- /* add the remaining sources */
- for (node = sources; node; node = g_list_next (node))
- {
- add_source (model, (AnjutaProjectSource *)node->data, iter);
- }
-}
-
static void
add_target_group (GbfProjectModel *model,
AnjutaProjectGroup *group,
@@ -595,124 +553,91 @@ add_target_group (GbfProjectModel *model,
}
static void
-update_group (GbfProjectModel *model, AnjutaProjectGroup *group, GtkTreeIter *iter)
+update_tree (GbfProjectModel *model, AnjutaProjectNode *parent, GtkTreeIter *iter)
{
- GtkTreeModel *tree_model;
GtkTreeIter child;
- GtkTreePath *shortcut;
GList *node;
- GList *groups;
- GList *targets;
- GList *sources;
-
- if ((!group) || (anjuta_project_node_get_type (group) != ANJUTA_PROJECT_GROUP))
- return;
+ GList *nodes;
- tree_model = GTK_TREE_MODEL (model);
-
- /* update group data. nothing to do here */
- groups = gbf_project_util_all_child (group, ANJUTA_PROJECT_GROUP);
- targets = gbf_project_util_all_child (group, ANJUTA_PROJECT_TARGET);
- sources = gbf_project_util_all_child (group, ANJUTA_PROJECT_SOURCE);
-
- /* walk the tree group */
/* group can be NULL, but we iterate anyway to remove any
* shortcuts the old group could have had */
- if (gtk_tree_model_iter_children (tree_model, &child, iter)) {
+
+ /* Get all new nodes */
+ nodes = gbf_project_util_all_child (parent, ANJUTA_PROJECT_UNKNOWN);
+
+ /* walk the tree nodes */
+ if (gtk_tree_model_iter_children (GTK_TREE_MODEL (model), &child, iter)) {
gboolean valid = TRUE;
while (valid) {
- gboolean remove_child = FALSE;
AnjutaProjectNode* data;
+ GbfTreeData *tree_data = NULL;
+
+ /* Get tree data */
+ gtk_tree_model_get (GTK_TREE_MODEL (model), &child,
+ GBF_PROJECT_MODEL_COLUMN_DATA, &tree_data,
+ -1);
- /* find the iterating id in the group's children */
data = gbf_project_model_get_node (model, &child);
- switch (anjuta_project_node_get_type (data))
+ if (data != NULL)
{
- case ANJUTA_PROJECT_GROUP:
- /* update recursively */
- update_group (model, data, &child);
- if (group && (node = g_list_find (groups, data))) {
- groups = g_list_delete_link (groups, node);
- } else {
- remove_child = TRUE;
- }
- break;
- case ANJUTA_PROJECT_TARGET:
- if (group && (node = g_list_find (targets, data))) {
- targets = g_list_delete_link (targets, node);
- /* update recursively */
- update_target (model, data, &child);
- } else {
- remove_child = TRUE;
- }
+ tree_data->id = data;
- /* remove or update the shortcut if it previously existed */
- shortcut = find_shortcut (model, data);
- if (shortcut) {
- GtkTreeIter tmp;
-
- if (remove_child)
- remove_shortcut (model, data);
-
- if (gtk_tree_model_get_iter (tree_model, &tmp, shortcut)) {
- if (remove_child)
- gbf_project_model_remove (model, &tmp);
- else
- update_target (model, data, &tmp);
- }
- gtk_tree_path_free (shortcut);
- }
- break;
- case ANJUTA_PROJECT_SOURCE:
- if ((data) && (node = g_list_find (sources, data))) {
- sources = g_list_delete_link (sources, node);
- } else {
- remove_child = TRUE;
+ /* Remove from the new node list */
+ node = g_list_find (nodes, data);
+ if (node != NULL)
+ {
+ nodes = g_list_delete_link (nodes, node);
}
- break;
- case ANJUTA_PROJECT_UNKNOWN:
- remove_child = TRUE;
- break;
- default:
- g_return_if_reached ();
+
+ /* Update shortcut */
+ if (tree_data->is_shortcut)
+ update_shortcut (model, data, tree_data->id);
+
+ /* update recursively */
+ update_tree (model, data, &child);
+
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &child);
}
-
- if (remove_child)
- valid = gbf_project_model_remove (model, &child);
else
- valid = gtk_tree_model_iter_next (tree_model, &child);
- };
+ {
+ /* Remove shortcut */
+ if (tree_data->is_shortcut)
+ remove_shortcut (model, tree_data->id);
+
+ /* update recursively */
+ update_tree (model, data, &child);
+
+ valid = gbf_project_model_remove (model, &child);
+ }
+ }
}
- if (group) {
- /* add the remaining sources, targets and groups */
- for (node = groups; node; node = node->next)
+ /* add the remaining sources, targets and groups */
+ for (node = nodes; node; node = node->next)
+ {
+ switch (anjuta_project_node_get_type (node->data))
+ {
+ case ANJUTA_PROJECT_GROUP:
add_target_group (model, node->data, iter);
-
- for (node = targets; node; node = node->next)
+ break;
+ case ANJUTA_PROJECT_TARGET:
add_target (model, node->data, iter);
-
- for (node = sources; node; node = g_list_next (node))
+ break;
+ case ANJUTA_PROJECT_SOURCE:
add_source (model, node->data, iter);
+ break;
+ default:
+ break;
+ }
}
}
static void
project_updated_cb (IAnjutaProject *project, GbfProjectModel *model)
{
- GtkTreePath *path;
- GtkTreeIter iter;
-
- path = gtk_tree_row_reference_get_path (model->priv->root_row);
- if (path && gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
- update_group (model, ianjuta_project_get_root (project, NULL), &iter);
- else
- add_target_group (model, ianjuta_project_get_root (project, NULL), NULL);
-
- if (path)
- gtk_tree_path_free (path);
+ update_tree (model, NULL, NULL);
}
static void
@@ -735,10 +660,13 @@ static void
insert_empty_node (GbfProjectModel *model)
{
GtkTreeIter iter;
+ GbfTreeData *empty_node;
+
+ empty_node = gbf_tree_data_new_string (_("No project loaded"));
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
- GBF_PROJECT_MODEL_COLUMN_DATA, model->priv->empty_node,
+ GBF_PROJECT_MODEL_COLUMN_DATA, empty_node,
-1);
}
@@ -870,11 +798,11 @@ gbf_project_model_get_node (GbfProjectModel *model,
GtkTreeIter *iter)
{
GbfTreeData *data = NULL;
- AnjutaProjectNode *parent;
+ AnjutaProjectNode *parent = NULL;
AnjutaProjectNode *node = NULL;
GtkTreeIter piter;
GFile *file;
-
+
gtk_tree_model_get (GTK_TREE_MODEL (model), iter,
GBF_PROJECT_MODEL_COLUMN_DATA, &data,
-1);
@@ -884,13 +812,22 @@ gbf_project_model_get_node (GbfProjectModel *model,
{
case GBF_TREE_NODE_GROUP:
file = g_file_new_for_uri (data->uri);
- node = anjuta_project_group_get_node_from_file (ianjuta_project_get_root (model->priv->proj, NULL), file);
+ if (gtk_tree_model_iter_parent (GTK_TREE_MODEL (model), &piter, iter))
+ parent = gbf_project_model_get_node (model, &piter);
+ node = anjuta_project_group_get_node_from_file (parent == NULL ? ianjuta_project_get_root (model->priv->proj, NULL) : parent, file);
g_object_unref (file);
break;
case GBF_TREE_NODE_TARGET:
- if (!gtk_tree_model_iter_parent (GTK_TREE_MODEL (model), &piter, iter))
- break;
- parent = gbf_project_model_get_node (model, &piter);
+ if (gtk_tree_model_iter_parent (GTK_TREE_MODEL (model), &piter, iter))
+ {
+ parent = gbf_project_model_get_node (model, &piter);
+ }
+ else
+ {
+ file = g_file_new_for_uri (data->uri);
+ parent = anjuta_project_group_get_node_from_file (ianjuta_project_get_root (model->priv->proj, NULL), file);
+ g_object_unref (file);
+ }
if (parent) node = anjuta_project_target_get_node_from_name (parent, data->name);
break;
case GBF_TREE_NODE_SOURCE:
diff --git a/plugins/project-manager/gbf-project-util.c b/plugins/project-manager/gbf-project-util.c
index 0c7d695..0b6b1fc 100644
--- a/plugins/project-manager/gbf-project-util.c
+++ b/plugins/project-manager/gbf-project-util.c
@@ -96,7 +96,7 @@ setup_groups_treeview (GbfProjectModel *model,
if (select_group && gbf_project_model_find_id (model, &iter,
GBF_TREE_NODE_GROUP, select_group)) {
GtkTreeIter iter_filter;
-
+
gtk_tree_model_filter_convert_child_iter_to_iter (
GTK_TREE_MODEL_FILTER (filter), &iter_filter, &iter);
path = gtk_tree_model_get_path (filter, &iter_filter);
@@ -790,7 +790,7 @@ gbf_project_util_all_child (AnjutaProjectNode *parent, AnjutaProjectNodeType typ
for (node = anjuta_project_node_first_child (parent); node != NULL; node = anjuta_project_node_next_sibling (node))
{
- if (anjuta_project_node_get_type (node) == type)
+ if ((type == ANJUTA_PROJECT_UNKNOWN) || (anjuta_project_node_get_type (node) == type))
{
list = g_list_prepend (list, node);
}
diff --git a/plugins/project-manager/gbf-tree-data.c b/plugins/project-manager/gbf-tree-data.c
index 9b16f43..b13d2b0 100644
--- a/plugins/project-manager/gbf-tree-data.c
+++ b/plugins/project-manager/gbf-tree-data.c
@@ -72,9 +72,13 @@ GbfTreeData *
gbf_tree_data_new_target (IAnjutaProject *project, AnjutaProjectTarget *target)
{
GbfTreeData *node = g_new0 (GbfTreeData, 1);
+ AnjutaProjectGroup *group;
node->type = GBF_TREE_NODE_TARGET;
node->id = target;
+
+ group = (AnjutaProjectGroup *)anjuta_project_node_parent (target);
+ node->uri = g_file_get_uri (anjuta_project_group_get_directory (group));
node->name = g_strdup (anjuta_project_target_get_name (target));
node->mime_type = g_strdup (anjuta_project_target_type_mime (anjuta_project_target_get_type (target)));
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index a72c8ed..de5b764 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -609,7 +609,7 @@ on_popup_add_target (GtkAction *action, ProjectManagerPlugin *plugin)
update_operation_begin (plugin);
selected_group = gbf_project_view_find_selected (GBF_PROJECT_VIEW (plugin->view),
ANJUTA_PROJECT_GROUP);
-
+
new_target = gbf_project_util_new_target (plugin->model,
get_plugin_parent_window (plugin),
selected_group, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]