From 2f192072d79984f1cbdfae5a8ce075f38e991870 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sat, 14 Nov 2020 06:02:40 +1000 Subject: [PATCH] Filter symbols in the Symbol List (new feature) --- data/geany.glade | 43 +++++++++++++++++++++++++++++++++++++------ src/callbacks.c | 16 +++++++++++++++- src/callbacks.h | 4 ++++ src/symbols.c | 28 ++++++++++++++++++++++++++-- 4 files changed, 82 insertions(+), 9 deletions(-) diff --git a/data/geany.glade b/data/geany.glade index 71327353c4..acca2e8499 100644 --- a/data/geany.glade +++ b/data/geany.glade @@ -8245,17 +8245,48 @@ - + True - True - automatic - automatic + False + + + True + True + Filter the Symbol List + + gtk-clear + False + True + True + True + + + + + False + True + 0 + + - + True True - False + automatic + automatic + + + True + True + False + + + + True + True + 1 + diff --git a/src/callbacks.c b/src/callbacks.c index 75d087098c..9490bc9d45 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -401,6 +401,20 @@ void on_toolbutton_search_clicked(GtkAction *action, gpointer user_data) } +void on_entry_tagfilter_changed(GtkAction *action, gpointer user_data) +{ + GeanyDocument *doc = document_get_current(); + sidebar_update_tag_list(doc, TRUE); +} + + +void on_entry_tagfilter_icon_press(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, gpointer user_data) +{ + if (event->button.button == 1) + gtk_entry_set_text(entry, ""); +} + + /* hides toolbar from toolbar popup menu */ static void on_hide_toolbar1_activate(GtkMenuItem *menuitem, gpointer user_data) { @@ -462,7 +476,7 @@ static void on_notebook1_switch_page_after(GtkNotebook *notebook, gpointer page, ui_update_popup_reundo_items(doc); ui_document_show_hide(doc); /* update the document menu */ build_menu_update(doc); - sidebar_update_tag_list(doc, FALSE); + sidebar_update_tag_list(doc, TRUE); document_highlight_tags(doc); document_check_disk_status(doc, TRUE); diff --git a/src/callbacks.h b/src/callbacks.h index 3cd4ac0455..52c1c8de80 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -72,6 +72,10 @@ void on_toolbar_search_entry_changed(GtkAction *action, const gchar *text, gpoin void on_toolbar_search_entry_activate(GtkAction *action, const gchar *text, gpointer user_data); +void on_entry_tagfilter_changed(GtkAction *action, gpointer user_data); + +void on_entry_tagfilter_icon_press(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, gpointer user_data); + void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data); void on_find_usage1_activate(GtkMenuItem *menuitem, gpointer user_data); diff --git a/src/symbols.c b/src/symbols.c index a54b6ef4c2..1e1d132ddc 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -308,13 +308,22 @@ static gint compare_symbol_lines(gconstpointer a, gconstpointer b) static GList *get_tag_list(GeanyDocument *doc, TMTagType tag_types) { GList *tag_names = NULL; - guint i; + guint i, j; + + GtkEntry *tfentry = NULL; // entry_tagfilter + gchar **tfarray = NULL; // Array of the Tag Filter + guint tfarlen = 0; // Length of the tfarray + gboolean tfapres = TRUE; // Result of the Tag Filter Applying g_return_val_if_fail(doc, NULL); if (! doc->tm_file || ! doc->tm_file->tags_array) return NULL; + tfentry = GTK_ENTRY(ui_lookup_widget(main_widgets.window, "entry_tagfilter")); + tfarray = g_strsplit_set(gtk_entry_get_text(tfentry), " ", -1); + tfarlen = g_strv_length(tfarray); + for (i = 0; i < doc->tm_file->tags_array->len; ++i) { TMTag *tag = TM_TAG(doc->tm_file->tags_array->pdata[i]); @@ -324,10 +333,25 @@ static GList *get_tag_list(GeanyDocument *doc, TMTagType tag_types) if (tag->type & tag_types) { - tag_names = g_list_prepend(tag_names, tag); + tfapres = TRUE; + for (j = 0; j < tfarlen; j++) + { + if (tfarray[j][0] != '\0') + { + if (g_strrstr(tag->name, tfarray[j]) == NULL) + { + tfapres = FALSE; + break; + } + } + } + if (tfapres) tag_names = g_list_prepend(tag_names, tag); } } tag_names = g_list_sort(tag_names, compare_symbol_lines); + + g_strfreev(tfarray); + return tag_names; }