[anjuta] project-manager: Store shortcut using new format and make them faster to load
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] project-manager: Store shortcut using new format and make them faster to load
- Date: Sat, 18 Dec 2010 18:36:30 +0000 (UTC)
commit 909ce255613f052f32327d12f769fc9dc42e315f
Author: Sébastien Granjoux <seb sfo free fr>
Date: Wed Dec 15 21:45:33 2010 +0100
project-manager: Store shortcut using new format and make them faster to load
plugins/project-manager/plugin.c | 45 +---------
plugins/project-manager/project-view.c | 145 ++++++++++++++++++--------------
plugins/project-manager/tree-data.h | 1 +
3 files changed, 86 insertions(+), 105 deletions(-)
---
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index 0500f2a..998e59f 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -208,9 +208,10 @@ on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase, AnjutaSession *se
if (phase != ANJUTA_SESSION_PHASE_NORMAL)
return;
- g_list_foreach (plugin->shortcuts, (GFunc)g_free, NULL);
- g_list_free (plugin->shortcuts);
- plugin->shortcuts = anjuta_session_get_string_list (session, "Project Manager", "Shortcut");
+ list = anjuta_session_get_string_list (session, "Project Manager", "Shortcut");
+ gbf_project_view_set_shortcut_list (GBF_PROJECT_VIEW (plugin->view), list);
+ g_list_foreach (list, (GFunc)g_free, NULL);
+ g_list_free (list);
list = anjuta_session_get_string_list (session, "Project Manager", "Expand");
gbf_project_view_set_expanded_list (GBF_PROJECT_VIEW (plugin->view), list);
@@ -1319,44 +1320,6 @@ on_project_loaded (AnjutaPmProject *project, GtkTreeIter *parent, gboolean compl
dirname, error->message);
}
}
- else
- {
- /* Restore existing shortcut */
- if (plugin->shortcuts != NULL)
- {
- GList *item;
-
- gbf_project_view_set_shortcut_list (plugin->view, plugin->shortcuts);
- /* Remove used or all shortcuts if loading is completed*/
- for (item = g_list_first (plugin->shortcuts); item != NULL;)
- {
- GList *next = g_list_next (item);
-
- if (complete || (*((char *)item->data) == 'U'))
- {
-
- g_free (item->data);
- plugin->shortcuts = g_list_remove_link (plugin->shortcuts, item);
- }
- item = next;
- }
- }
- else
- {
- GList *list = NULL;
-
- /* Add new shortcut for PRIMARY target */
- anjuta_project_node_foreach (node, G_POST_ORDER, add_primary_target, &list);
-
- if (list != NULL)
- {
- list = g_list_reverse (list);
- gbf_project_view_set_shortcut_list (plugin->view, list);
- g_list_foreach (list, (GFunc)g_free, NULL);
- g_list_free (list);
- }
- }
- }
g_free (dirname);
if (complete)
diff --git a/plugins/project-manager/project-view.c b/plugins/project-manager/project-view.c
index fdc7fe7..79c5499 100644
--- a/plugins/project-manager/project-view.c
+++ b/plugins/project-manager/project-view.c
@@ -667,7 +667,10 @@ gbf_project_view_update_tree (GbfProjectView *view, AnjutaProjectNode *parent, G
GtkTreePath *child_path;
GtkTreeModelFilter *filter;
gboolean expanded;
+ gboolean shortcut;
+ expanded = data->expanded;
+ shortcut = data->has_shortcut;
data_node = (AnjutaProjectNode *)node->data;
gbf_tree_data_free (data);
data = gbf_tree_data_new_node (data_node);
@@ -684,13 +687,20 @@ gbf_project_view_update_tree (GbfProjectView *view, AnjutaProjectNode *parent, G
/* update recursively */
gbf_project_view_update_tree (view, data_node, &child);
- filter = GTK_TREE_MODEL_FILTER (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (view->model), &child);
- child_path = gtk_tree_model_filter_convert_child_path_to_path (filter, path);
- gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), child_path);
- expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), child_path);
- gtk_tree_path_free (child_path);
- gtk_tree_path_free (path);
+ if (shortcut)
+ {
+ gbf_project_model_add_target_shortcut (view->model, NULL, data, NULL);
+ }
+ if (expanded)
+ {
+ filter = GTK_TREE_MODEL_FILTER (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (view->model), &child);
+ child_path = gtk_tree_model_filter_convert_child_path_to_path (filter, path);
+ gtk_tree_view_expand_to_path (GTK_TREE_VIEW (view), child_path);
+ expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), child_path);
+ gtk_tree_path_free (child_path);
+ gtk_tree_path_free (path);
+ }
}
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (view->model), &child);
}
@@ -759,7 +769,7 @@ gbf_project_view_get_shortcut_list (GbfProjectView *view)
gboolean valid;
GtkTreeIter iter;
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
+ model = GTK_TREE_MODEL (view->model);
if (model != NULL)
{
for (valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (model), &iter, NULL);
@@ -773,18 +783,32 @@ gbf_project_view_get_shortcut_list (GbfProjectView *view)
if ((data->type == GBF_TREE_NODE_SHORTCUT) && (data->shortcut != NULL))
{
- gchar *uri;
- GtkTreePath *path;
- gboolean expand;
+ GtkTreeIter iter;
+
+ if (gbf_project_model_find_tree_data (view->model, &iter, data->shortcut))
+ {
+ GString *str;
+ GtkTreeIter child;
+
+ str = g_string_new (NULL);
+ do
+ {
+ GbfTreeData *data;
- uri = gbf_tree_data_get_uri (data);
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
- expand = gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path);
- gtk_tree_path_free (path);
+ child = iter;
+ gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
+ GBF_PROJECT_MODEL_COLUMN_DATA, &data,
+ -1);
- if (uri != NULL)
- {
- list = g_list_prepend (list, g_strconcat (expand ? "E " : "C ", uri, NULL));
+ if (data->node != NULL)
+ {
+ if (str->len != 0) g_string_prepend (str, "//");
+ g_string_prepend (str, anjuta_project_node_get_name (data->node));
+ }
+ }
+ while (gtk_tree_model_iter_parent (model, &iter, &child));
+ list = g_list_prepend (list, str->str);
+ g_string_free (str, FALSE);
}
}
}
@@ -876,67 +900,51 @@ gbf_project_view_remove_all_shortcut (GbfProjectView* view)
void
gbf_project_view_set_shortcut_list (GbfProjectView *view, GList *shortcuts)
{
- if (shortcuts != NULL)
+ GList *item;
+
+ for (item = g_list_first (shortcuts); item != NULL; item = g_list_next (item))
{
- gboolean valid;
+ gchar *name = (gchar *)item->data;
+ gchar *end;
GtkTreeIter iter;
-
- valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (view->model), &iter, NULL);
+ GtkTreeIter *parent = NULL;
- if (valid)
+ do
{
- GList *node;
-
- for (node = g_list_first (shortcuts); node != NULL; node = g_list_next (node))
+ end = strstr (name, "/" "/"); /* Avoid troubles with auto indent */
+ if (end != NULL) *end = '\0';
+ if (*name != '\0')
{
- GFile *file;
- GtkTreeIter shortcut;
- gboolean expand = FALSE;
- gchar *uri = (gchar *)node->data;
-
- if (strncmp (uri, "E ", 2) == 0)
- {
- expand = TRUE;
- uri += 2;
- }
- else if (strncmp (uri, "C ", 2) == 0)
+ if (!gbf_project_model_find_child_name (view->model, &iter, parent, name))
{
- expand = FALSE;
- uri += 2;
+ GbfTreeData *data;
+
+ /* Create proxy node */
+ data = gbf_tree_data_new_proxy (name, FALSE);
+ gtk_tree_store_append (GTK_TREE_STORE (view->model), &iter, parent);
+ gtk_tree_store_set (GTK_TREE_STORE (view->model), &iter,
+ GBF_PROJECT_MODEL_COLUMN_DATA, data,
+ -1);
+ if (end == NULL) data->has_shortcut = TRUE;
}
- file = g_file_new_for_uri (uri);
-
- if (gbf_project_model_find_file (GBF_PROJECT_MODEL (view->model), &shortcut, NULL, ANJUTA_PROJECT_UNKNOWN, file))
+ else
{
GbfTreeData *data;
- gtk_tree_model_get (GTK_TREE_MODEL (view->model), &shortcut,
+ gtk_tree_model_get (GTK_TREE_MODEL (view->model), &iter,
GBF_PROJECT_MODEL_COLUMN_DATA, &data,
-1);
-
- /* Avoid duplicated shortcuts */
- if (data->type != GBF_TREE_NODE_SHORTCUT)
- {
- gbf_project_model_add_shortcut (GBF_PROJECT_MODEL (view->model),
- &shortcut,
- &iter,
- data);
-
- if (expand)
- {
- GtkTreePath *path;
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (view->model), &shortcut);
- gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE);
- gtk_tree_path_free (path);
- }
- /* Mark the shortcut as used */
- *uri = 'U';
- }
+ if (end == NULL) data->has_shortcut = TRUE;
}
- g_object_unref (file);
+ parent = &iter;
+ }
+ if (end != NULL)
+ {
+ *end = '/';
+ name = end + 2;
}
}
+ while (end != NULL);
}
return;
@@ -971,6 +979,15 @@ gbf_project_view_set_expanded_list (GbfProjectView *view, GList *expand)
GBF_PROJECT_MODEL_COLUMN_DATA, data,
-1);
}
+ else
+ {
+ GbfTreeData *data;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (view->model), &iter,
+ GBF_PROJECT_MODEL_COLUMN_DATA, &data,
+ -1);
+ data->expanded = TRUE;
+ }
parent = &iter;
}
if (end != NULL)
diff --git a/plugins/project-manager/tree-data.h b/plugins/project-manager/tree-data.h
index 79cb548..8aa20fb 100644
--- a/plugins/project-manager/tree-data.h
+++ b/plugins/project-manager/tree-data.h
@@ -53,6 +53,7 @@ struct _GbfTreeData
GFile *source;
gboolean is_shortcut;
gboolean expanded;
+ gboolean has_shortcut;
GbfTreeData *shortcut;
GtkWidget *properties_dialog;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]