[anjuta] project-manager: Allow hidden node in the tree view (for object node)
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] project-manager: Allow hidden node in the tree view (for object node)
- Date: Sat, 4 Jun 2011 15:06:39 +0000 (UTC)
commit 0f786f04c6e46322e027375a87abf855d4321b7f
Author: Sébastien Granjoux <seb sfo free fr>
Date: Sat Jun 4 11:39:41 2011 +0200
project-manager: Allow hidden node in the tree view (for object node)
plugins/project-manager/plugin.c | 73 +++++++++++++++++++++++-------
plugins/project-manager/project-model.c | 64 +++++++++++++++++----------
plugins/project-manager/project-model.h | 3 +-
plugins/project-manager/project-util.c | 19 --------
plugins/project-manager/project-util.h | 3 -
plugins/project-manager/project-view.c | 32 ++++++++++++-
plugins/project-manager/project.c | 2 +-
plugins/project-manager/tree-data.c | 46 +++++++++++++++++++
plugins/project-manager/tree-data.h | 2 +
9 files changed, 177 insertions(+), 67 deletions(-)
---
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index 3357bd0..fb67293 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -38,10 +38,10 @@
#include "plugin.h"
-#define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-project-manager.xml"
-#define PREFS_GLADE PACKAGE_DATA_DIR"/glade/anjuta-project-manager-plugin.ui"
+#define UI_FILE PACKAGE_DATA_DIR "/ui/anjuta-project-manager.xml"
+#define PREFS_GLADE PACKAGE_DATA_DIR "/glade/anjuta-project-manager-plugin.ui"
#define ICON_FILE "anjuta-project-manager-plugin-48.png"
-#define DEFAULT_PROFILE "file://"PACKAGE_DATA_DIR"/profiles/default.profile"
+#define DEFAULT_PROFILE "file://"PACKAGE_DATA_DIR "/profiles/default.profile"
#define PROJECT_PROFILE_NAME "project"
#define INT_TO_GBOOLEAN(i) ((i) ? TRUE : FALSE)
@@ -1845,6 +1845,33 @@ get_tree_iter_from_file (ProjectManagerPlugin *plugin, GtkTreeIter* iter, GFile
return found ? iter : NULL;
}
+static gboolean
+project_node_compare (AnjutaProjectNode *node, gpointer data)
+{
+ GFile *file = (GFile *)data;
+
+ switch (anjuta_project_node_get_node_type (node))
+ {
+ case ANJUTA_PROJECT_GROUP:
+ case ANJUTA_PROJECT_SOURCE:
+ case ANJUTA_PROJECT_OBJECT:
+ case ANJUTA_PROJECT_TARGET:
+ return g_file_equal (anjuta_project_node_get_file (node), file);
+ default:
+ return FALSE;
+ }
+}
+
+static AnjutaProjectNode *
+get_node_from_file (const AnjutaProjectNode *root, GFile *file)
+{
+ AnjutaProjectNode *node;
+
+ node = anjuta_project_node_traverse ((AnjutaProjectNode *)root, G_PRE_ORDER, project_node_compare, file);
+
+ return node;
+}
+
static AnjutaProjectNodeType
get_element_type (ProjectManagerPlugin *plugin, GFile *element)
{
@@ -1893,7 +1920,6 @@ iproject_manager_get_target_type (IAnjutaProjectManager *project_manager,
GError **err)
{
ProjectManagerPlugin *plugin;
- AnjutaProjectNode *target;
g_return_val_if_fail (ANJUTA_IS_PLUGIN (project_manager),
ANJUTA_PROJECT_UNKNOWN);
@@ -1902,17 +1928,20 @@ iproject_manager_get_target_type (IAnjutaProjectManager *project_manager,
g_return_val_if_fail (file_is_inside_project (plugin, target_file),
ANJUTA_PROJECT_UNKNOWN);
-
- target = gbf_project_view_get_node_from_file (plugin->view, ANJUTA_PROJECT_TARGET, target_file);
- if (target != NULL)
- {
- return anjuta_project_node_get_node_type (target);
- }
- else
+ if (plugin->project != NULL)
{
- return ANJUTA_PROJECT_UNKNOWN;
+ AnjutaProjectNode *node;
+
+ node = anjuta_pm_project_get_root (plugin->project);
+ if (node != NULL)
+ {
+ node = get_node_from_file (node, target_file);
+ if (node != NULL) return anjuta_project_node_get_node_type (node);
+ }
}
+
+ return ANJUTA_PROJECT_UNKNOWN;
}
static GList*
iproject_manager_get_targets (IAnjutaProjectManager *project_manager,
@@ -1943,16 +1972,26 @@ iproject_manager_get_parent (IAnjutaProjectManager *project_manager,
GFile *element,
GError **err)
{
- AnjutaProjectNodeType type;
ProjectManagerPlugin *plugin;
+ GFile *file = NULL;
g_return_val_if_fail (ANJUTA_IS_PLUGIN (project_manager), NULL);
plugin = ANJUTA_PLUGIN_PROJECT_MANAGER (G_OBJECT (project_manager));
-
- type = get_element_type (plugin, element);
- /* FIXME: */
- return NULL;
+ if (plugin->project != NULL)
+ {
+ AnjutaProjectNode *node;
+
+ node = anjuta_pm_project_get_root (plugin->project);
+ if (node != NULL)
+ {
+ node = get_node_from_file (node, element);
+ if (node != NULL) node = anjuta_project_node_parent (node);
+ if (node != NULL) file = g_object_ref (anjuta_project_node_get_file (node));
+ }
+ }
+
+ return file;
}
static GList*
diff --git a/plugins/project-manager/project-model.c b/plugins/project-manager/project-model.c
index 88f35bc..fb6d963 100644
--- a/plugins/project-manager/project-model.c
+++ b/plugins/project-manager/project-model.c
@@ -596,7 +596,7 @@ gbf_project_model_add_target_shortcut (GbfProjectModel *model,
/* add sources */
parent = gbf_tree_data_get_node (target);
for (node = anjuta_project_node_first_child (parent); node; node = anjuta_project_node_next_sibling (node))
- gbf_project_model_add_node (model, node, &iter);
+ gbf_project_model_add_node (model, node, &iter, 0);
gtk_tree_path_free (root_path);
@@ -654,7 +654,7 @@ gbf_project_model_move_target_shortcut (GbfProjectModel *model,
/* add sources */
parent = gbf_tree_data_get_node (shortcut->shortcut);
for (node = anjuta_project_node_first_child (parent); node; node = anjuta_project_node_next_sibling (node))
- gbf_project_model_add_node (model, node, iter);
+ gbf_project_model_add_node (model, node, iter, 0);
}
@@ -666,10 +666,11 @@ gbf_project_model_move_target_shortcut (GbfProjectModel *model,
void
gbf_project_model_add_node (GbfProjectModel *model,
AnjutaProjectNode *node,
- GtkTreeIter *parent)
+ GtkTreeIter *parent,
+ AnjutaProjectNodeType only_type)
{
GtkTreeIter iter;
- GbfTreeData *data;
+ GbfTreeData *data = NULL;
AnjutaProjectNode *child;
AnjutaProjectNodeType child_types[] = {ANJUTA_PROJECT_GROUP,
ANJUTA_PROJECT_TARGET,
@@ -680,32 +681,49 @@ gbf_project_model_add_node (GbfProjectModel *model,
AnjutaProjectNodeType *type;
if (node == NULL) return;
-
- data = gbf_tree_data_new_node (node);
- gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent);
- gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
- GBF_PROJECT_MODEL_COLUMN_DATA, data,
- -1);
- /* add children */
- for (type = child_types; *type != 0; type++)
+
+ if ((only_type == 0) || (anjuta_project_node_get_node_type (node) == only_type))
{
- for (child = anjuta_project_node_first_child (node); child != NULL; child = anjuta_project_node_next_sibling (child))
+ if (anjuta_project_node_get_node_type (node) != ANJUTA_PROJECT_OBJECT)
{
- if (anjuta_project_node_get_node_type (child) == *type)
+ data = gbf_tree_data_new_node (node);
+ gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent);
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
+ GBF_PROJECT_MODEL_COLUMN_DATA, data,
+ -1);
+ }
+ else
+ {
+ /* Hidden node */
+ iter = *parent;
+ }
+
+ /* add children */
+ for (type = child_types; *type != 0; type++)
+ {
+ for (child = anjuta_project_node_first_child (node); child != NULL; child = anjuta_project_node_next_sibling (child))
{
- gbf_project_model_add_node (model, child, &iter);
+ gbf_project_model_add_node (model, child, &iter, *type);
}
}
- }
- /* Add shortcut if needed */
- if ((data != NULL) &&
- model->priv->default_shortcut &&
- (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_TARGET) &&
- (anjuta_project_node_get_full_type (node) & ANJUTA_PROJECT_PRIMARY))
+ /* Add shortcut if needed */
+ if ((data != NULL) &&
+ model->priv->default_shortcut &&
+ (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_TARGET) &&
+ (anjuta_project_node_get_full_type (node) & ANJUTA_PROJECT_PRIMARY))
+ {
+ gbf_project_model_add_target_shortcut (model, NULL, data, NULL, NULL);
+ }
+ }
+ else if (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_OBJECT)
{
- gbf_project_model_add_target_shortcut (model, NULL, data, NULL, NULL);
+ /* Add only children */
+ for (child = anjuta_project_node_first_child (node); child != NULL; child = anjuta_project_node_next_sibling (child))
+ {
+ gbf_project_model_add_node (model, child, parent, only_type);
+ }
}
}
@@ -715,7 +733,7 @@ load_project (GbfProjectModel *model, AnjutaPmProject *proj)
model->priv->proj = proj;
g_object_ref (proj);
- gbf_project_model_add_node (model, anjuta_pm_project_get_root (proj), NULL);
+ gbf_project_model_add_node (model, anjuta_pm_project_get_root (proj), NULL, 0);
}
static void
diff --git a/plugins/project-manager/project-model.h b/plugins/project-manager/project-model.h
index c425ae6..371044a 100644
--- a/plugins/project-manager/project-model.h
+++ b/plugins/project-manager/project-model.h
@@ -86,7 +86,8 @@ AnjutaProjectNode *gbf_project_model_get_node (GbfProjectModel *model,
void gbf_project_model_add_node (GbfProjectModel *model,
AnjutaProjectNode *package,
- GtkTreeIter *parent);
+ GtkTreeIter *parent,
+ AnjutaProjectNodeType only_type);
void gbf_project_model_add_target_shortcut (GbfProjectModel *model,
GtkTreeIter *shortcut,
diff --git a/plugins/project-manager/project-util.c b/plugins/project-manager/project-util.c
index 963a2b5..ed8ac9a 100644
--- a/plugins/project-manager/project-util.c
+++ b/plugins/project-manager/project-util.c
@@ -33,25 +33,6 @@
#include "project-util.h"
GList *
-gbf_project_util_all_child (AnjutaProjectNode *parent, AnjutaProjectNodeType type)
-{
- AnjutaProjectNode *node;
- GList *list = NULL;
-
- for (node = anjuta_project_node_first_child (parent); node != NULL; node = anjuta_project_node_next_sibling (node))
- {
- if ((type == ANJUTA_PROJECT_UNKNOWN) || (anjuta_project_node_get_node_type (node) == type))
- {
- list = g_list_prepend (list, node);
- }
- }
-
- list = g_list_reverse (list);
-
- return list;
-}
-
-GList *
gbf_project_util_node_all (AnjutaProjectNode *parent, AnjutaProjectNodeType type)
{
AnjutaProjectNode *node;
diff --git a/plugins/project-manager/project-util.h b/plugins/project-manager/project-util.h
index 090570e..fce88f2 100644
--- a/plugins/project-manager/project-util.h
+++ b/plugins/project-manager/project-util.h
@@ -30,9 +30,6 @@
G_BEGIN_DECLS
-GList * gbf_project_util_all_child (AnjutaProjectNode *parent,
- AnjutaProjectNodeType type);
-
GList * gbf_project_util_node_all (AnjutaProjectNode *parent,
AnjutaProjectNodeType type);
diff --git a/plugins/project-manager/project-view.c b/plugins/project-manager/project-view.c
index 932c809..0002e3d 100644
--- a/plugins/project-manager/project-view.c
+++ b/plugins/project-manager/project-view.c
@@ -942,6 +942,32 @@ compare_node_name (gconstpointer a, gconstpointer b)
return g_strcmp0 (anjuta_project_node_get_name (node), name);
}
+static GList *
+list_visible_children (AnjutaProjectNode *parent)
+{
+ AnjutaProjectNode *node;
+ GList *list = NULL;
+
+ for (node = anjuta_project_node_first_child (parent); node != NULL; node = anjuta_project_node_next_sibling (node))
+ {
+ if (anjuta_project_node_get_node_type (node) != ANJUTA_PROJECT_OBJECT)
+ {
+ list = g_list_prepend (list, node);
+ }
+ else
+ {
+ /* object node are hidden, get their children instead */
+ GList *children = list_visible_children (node);
+
+ children = g_list_reverse (children);
+ list = g_list_concat (children, list);
+ }
+ }
+ list = g_list_reverse (list);
+
+ return list;
+}
+
void
gbf_project_view_update_tree (GbfProjectView *view, AnjutaProjectNode *parent, GtkTreeIter *iter)
{
@@ -951,7 +977,7 @@ gbf_project_view_update_tree (GbfProjectView *view, AnjutaProjectNode *parent, G
GbfTreeData *data = NULL;
/* Get all new nodes */
- nodes = gbf_project_util_all_child (parent, ANJUTA_PROJECT_UNKNOWN);
+ nodes = list_visible_children (parent);
/* walk the tree nodes */
if (gtk_tree_model_iter_children (GTK_TREE_MODEL (view->model), &child, iter))
@@ -1064,7 +1090,7 @@ gbf_project_view_update_tree (GbfProjectView *view, AnjutaProjectNode *parent, G
/* add the remaining sources, targets and groups */
for (node = nodes; node; node = node->next)
{
- gbf_project_model_add_node (view->model, node->data, iter);
+ gbf_project_model_add_node (view->model, node->data, iter, 0);
}
/* Expand parent, needed if the parent hasn't any children when it was created */
@@ -1430,7 +1456,7 @@ on_node_loaded (AnjutaPmProject *sender, AnjutaProjectNode *node, gboolean compl
if (!gbf_project_model_find_child_name (view->model, &iter, NULL, anjuta_project_node_get_name (node)))
{
- gbf_project_model_add_node (view->model, node, NULL);
+ gbf_project_model_add_node (view->model, node, NULL, 0);
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (view->model), &iter);
}
else
diff --git a/plugins/project-manager/project.c b/plugins/project-manager/project.c
index b3f56a0..35b15e4 100644
--- a/plugins/project-manager/project.c
+++ b/plugins/project-manager/project.c
@@ -242,7 +242,7 @@ anjuta_pm_project_unload (AnjutaPmProject *project, GError **error)
/* Remove project properties dialogs */
if (project->properties_dialog != NULL) gtk_widget_destroy (project->properties_dialog);
project->properties_dialog = NULL;
-
+
return TRUE;
}
diff --git a/plugins/project-manager/tree-data.c b/plugins/project-manager/tree-data.c
index 2be80ca..87e1d65 100644
--- a/plugins/project-manager/tree-data.c
+++ b/plugins/project-manager/tree-data.c
@@ -265,6 +265,49 @@ gbf_tree_data_new_target (AnjutaProjectNode *target)
}
GbfTreeData *
+gbf_tree_data_new_object (AnjutaProjectNode *node)
+{
+ GbfTreeData *data = g_slice_new0 (GbfTreeData);
+ GFileInfo *ginfo;
+ AnjutaProjectNode *parent;
+
+ data->type = GBF_TREE_NODE_OBJECT;
+ data->node = node;
+
+ data->source = g_object_ref (anjuta_project_node_get_file (node));
+
+ 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);
+ }
+
+ parent = anjuta_project_node_parent (node);
+ if (anjuta_project_node_get_node_type (parent) == ANJUTA_PROJECT_GROUP)
+ {
+ data->group = g_object_ref (anjuta_project_node_get_file (parent));
+ }
+ else if (anjuta_project_node_get_node_type (parent) == ANJUTA_PROJECT_TARGET)
+ {
+ AnjutaProjectNode *group;
+
+ group = anjuta_project_node_parent (parent);
+ data->group = g_object_ref (anjuta_project_node_get_file (group));
+ data->target = g_strdup (anjuta_project_node_get_name (parent));
+ }
+
+ return data;
+}
+
+GbfTreeData *
gbf_tree_data_new_source (AnjutaProjectNode *source)
{
GbfTreeData *data = g_slice_new0 (GbfTreeData);
@@ -356,6 +399,9 @@ gbf_tree_data_new_node (AnjutaProjectNode *node)
case ANJUTA_PROJECT_TARGET:
data = gbf_tree_data_new_target(node);
break;
+ case ANJUTA_PROJECT_OBJECT:
+ data = gbf_tree_data_new_object (node);
+ break;
case ANJUTA_PROJECT_SOURCE:
data = gbf_tree_data_new_source (node);
break;
diff --git a/plugins/project-manager/tree-data.h b/plugins/project-manager/tree-data.h
index 44dd408..091da06 100644
--- a/plugins/project-manager/tree-data.h
+++ b/plugins/project-manager/tree-data.h
@@ -37,6 +37,7 @@ typedef enum {
GBF_TREE_NODE_TARGET,
GBF_TREE_NODE_MODULE,
GBF_TREE_NODE_PACKAGE,
+ GBF_TREE_NODE_OBJECT,
GBF_TREE_NODE_SOURCE,
GBF_TREE_NODE_ROOT,
GBF_TREE_NODE_SHORTCUT,
@@ -78,6 +79,7 @@ GbfTreeData *gbf_tree_data_new_shortcut (GbfTreeData *src);
GbfTreeData *gbf_tree_data_new_proxy (const gchar *name, gboolean expanded);
GbfTreeData *gbf_tree_data_new_group (AnjutaProjectNode *group);
GbfTreeData *gbf_tree_data_new_target (AnjutaProjectNode *target);
+GbfTreeData *gbf_tree_data_new_object (AnjutaProjectNode *object);
GbfTreeData *gbf_tree_data_new_source (AnjutaProjectNode *source);
GbfTreeData *gbf_tree_data_new_module (AnjutaProjectNode *module);
GbfTreeData *gbf_tree_data_new_root (AnjutaProjectNode *root);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]