Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: GitHub noreply@github.com Date: Sun, 07 May 2023 21:38:38 UTC Commit: 64a68aff27e9df388389ba8e0c7fb0d42be20de1 https://github.com/geany/geany-plugins/commit/64a68aff27e9df388389ba8e0c7fb0...
Log Message: ----------- Merge pull request #1144 from techee/expand_remember
projectorganizer: Restore tree state in the sidebar
Modified Paths: -------------- projectorganizer/src/prjorg-main.c projectorganizer/src/prjorg-project.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-sidebar.h
Modified: projectorganizer/src/prjorg-main.c 4 lines changed, 3 insertions(+), 1 deletions(-) =================================================================== @@ -130,8 +130,10 @@ static void on_project_open(G_GNUC_UNUSED GObject * obj, GKeyFile * config, { if (!prj_org) { + gchar **arr = prjorg_project_load_expanded_paths(config); + prjorg_project_open(config); - prjorg_sidebar_update(TRUE); + prjorg_sidebar_update_full(TRUE, arr); prjorg_sidebar_activate(TRUE); prjorg_menu_activate_menu_items(TRUE); }
Modified: projectorganizer/src/prjorg-project.c 19 lines changed, 19 insertions(+), 0 deletions(-) =================================================================== @@ -27,6 +27,7 @@
#include "prjorg-utils.h" #include "prjorg-project.h" +#include "prjorg-sidebar.h"
extern GeanyPlugin *geany_plugin; extern GeanyData *geany_data; @@ -377,6 +378,16 @@ static void update_project( }
+static void save_expanded_paths(GKeyFile * key_file) +{ + gchar **expanded_paths = prjorg_sidebar_get_expanded_paths(); + + g_key_file_set_string_list(key_file, "prjorg", "expanded_paths", + (const gchar**) expanded_paths, g_strv_length(expanded_paths)); + g_strfreev(expanded_paths); +} + + void prjorg_project_save(GKeyFile * key_file) { GPtrArray *array; @@ -385,6 +396,8 @@ void prjorg_project_save(GKeyFile * key_file) if (!prj_org) return;
+ save_expanded_paths(key_file); + g_key_file_set_string_list(key_file, "prjorg", "source_patterns", (const gchar**) prj_org->source_patterns, g_strv_length(prj_org->source_patterns)); g_key_file_set_string_list(key_file, "prjorg", "header_patterns", @@ -478,6 +491,12 @@ void prjorg_project_remove_external_dir(const gchar *utf8_dirname) }
+gchar **prjorg_project_load_expanded_paths(GKeyFile * key_file) +{ + return g_key_file_get_string_list(key_file, "prjorg", "expanded_paths", NULL, NULL); +} + + void prjorg_project_open(GKeyFile * key_file) { gchar **source_patterns, **header_patterns, **ignored_dirs_patterns, **ignored_file_patterns, **external_dirs, **dir_ptr, *last_name;
Modified: projectorganizer/src/prjorg-project.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -52,6 +52,7 @@ typedef struct extern PrjOrg *prj_org;
void prjorg_project_open(GKeyFile * key_file); +gchar **prjorg_project_load_expanded_paths(GKeyFile * key_file);
GtkWidget *prjorg_project_add_properties_tab(GtkWidget *notebook);
Modified: projectorganizer/src/prjorg-sidebar.c 56 lines changed, 44 insertions(+), 12 deletions(-) =================================================================== @@ -51,7 +51,8 @@ typedef enum typedef struct { GeanyProject *project; - GPtrArray *expanded_paths; + gchar **expanded_paths; + gchar *selected_path; } ExpandData;
@@ -1487,24 +1488,30 @@ static gboolean expand_path(gchar *utf8_expanded_path, gboolean select) static gboolean expand_on_idle(ExpandData *expand_data) { GeanyDocument *doc = document_get_current(); + gboolean selected = FALSE;
if (!prj_org) return FALSE;
if (geany_data->app->project == expand_data->project && expand_data->expanded_paths) { - gchar *item; - guint i; + gchar **item; + foreach_strv(item, expand_data->expanded_paths) + expand_path(*item, FALSE); + g_strfreev(expand_data->expanded_paths); + }
- foreach_ptr_array(item, i, expand_data->expanded_paths) - expand_path(item, FALSE); - g_ptr_array_free(expand_data->expanded_paths, TRUE); + if (expand_data->selected_path) + { + expand_path(expand_data->selected_path, TRUE); + g_free(expand_data->selected_path); + selected = TRUE; }
g_free(expand_data);
- if (!s_follow_editor || !doc || !doc->file_name) + if (selected || !s_follow_editor || !doc || !doc->file_name) return FALSE;
expand_path(doc->file_name, TRUE); @@ -1547,26 +1554,45 @@ static void on_map_expanded(GtkTreeView *tree_view, GtkTreePath *tree_path, GPtr }
-static GPtrArray *get_expanded_paths(void) +gchar **prjorg_sidebar_get_expanded_paths(void) { - GPtrArray *expanded_paths = g_ptr_array_new_with_free_func(g_free); + GPtrArray *expanded_paths = g_ptr_array_new();
gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(s_file_view), (GtkTreeViewMappingFunc)on_map_expanded, expanded_paths); + g_ptr_array_add(expanded_paths, NULL);
- return expanded_paths; + return g_ptr_array_free(expanded_paths, FALSE); }
-void prjorg_sidebar_update(gboolean reload) +static gchar *get_selected_path(void) +{ + GtkTreeSelection *treesel; + GtkTreeIter iter; + GtkTreeModel *model; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (gtk_tree_selection_get_selected(treesel, &model, &iter)) + return build_path(&iter); + return NULL; +} + + +void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths) { ExpandData *expand_data = g_new0(ExpandData, 1);
expand_data->project = geany_data->app->project;
if (reload) { - expand_data->expanded_paths = get_expanded_paths(); + GtkTreeSelection *treesel; + GtkTreeIter iter; + GtkTreeModel *model; + + expand_data->expanded_paths = expanded_paths != NULL ? expanded_paths : prjorg_sidebar_get_expanded_paths(); + expand_data->selected_path = get_selected_path();
load_project(); /* we get color information only after the sidebar is realized - @@ -1580,6 +1606,12 @@ void prjorg_sidebar_update(gboolean reload) }
+void prjorg_sidebar_update(gboolean reload) +{ + prjorg_sidebar_update_full(reload, NULL); +} + + void prjorg_sidebar_find_file_in_active(void) { find_file(NULL);
Modified: projectorganizer/src/prjorg-sidebar.h 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -28,9 +28,12 @@ void prjorg_sidebar_find_file_in_active(void); void prjorg_sidebar_find_tag_in_active(void);
void prjorg_sidebar_update(gboolean reload); +void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths);
void prjorg_sidebar_focus_project_tab(void);
+gchar **prjorg_sidebar_get_expanded_paths(void); + void on_open_file_manager(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); void on_open_terminal(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).