Skip to content

Commit

Permalink
Use per-document filter for symbol tree
Browse files Browse the repository at this point in the history
  • Loading branch information
techee committed Jan 23, 2022
1 parent f15f5a5 commit 0c311c0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/callbacks.c
Expand Up @@ -440,10 +440,15 @@ 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();
GtkEntry *filter_entry;

if (!doc)
return;

filter_entry = GTK_ENTRY(ui_lookup_widget(main_widgets.window, "entry_tagfilter"));
g_free(doc->priv->tag_filter);
doc->priv->tag_filter = g_strdup(gtk_entry_get_text(filter_entry));

/* make sure the tree is fully re-created so it appears correctly
* after applying filter */
if (doc->priv->tag_store)
Expand Down Expand Up @@ -524,14 +529,23 @@ static void on_notebook1_switch_page_after(GtkNotebook *notebook, gpointer page,

if (doc != NULL)
{
GtkEntry *filter_entry = GTK_ENTRY(ui_lookup_widget(main_widgets.window, "entry_tagfilter"));
const gchar *entry_text = gtk_entry_get_text(filter_entry);

sidebar_select_openfiles_item(doc);
ui_save_buttons_toggle(doc->changed);
ui_set_window_title(doc);
ui_update_statusbar(doc, -1);
ui_update_popup_reundo_items(doc);
ui_document_show_hide(doc); /* update the document menu */
build_menu_update(doc);
sidebar_update_tag_list(doc, TRUE);
if (g_strcmp0(entry_text, doc->priv->tag_filter) != 0)
{
/* calls sidebar_update_tag_list() in on_entry_tagfilter_changed() */
gtk_entry_set_text(filter_entry, doc->priv->tag_filter);
}
else
sidebar_update_tag_list(doc, TRUE);
document_highlight_tags(doc);

document_check_disk_status(doc, TRUE);
Expand Down
2 changes: 2 additions & 0 deletions src/document.c
Expand Up @@ -647,6 +647,7 @@ static GeanyDocument *document_create(const gchar *utf8_filename)

/* initialize default document settings */
doc->priv = g_new0(GeanyDocumentPrivate, 1);
doc->priv->tag_filter = g_strdup("");
doc->id = ++doc_id_counter;
doc->index = new_idx;
doc->file_name = g_strdup(utf8_filename);
Expand Down Expand Up @@ -734,6 +735,7 @@ static gboolean remove_page(guint page_num)
}
g_free(doc->encoding);
g_free(doc->priv->saved_encoding.encoding);
g_free(doc->priv->tag_filter);
g_free(doc->file_name);
g_free(doc->real_path);
if (doc->tm_file)
Expand Down
2 changes: 2 additions & 0 deletions src/documentprivate.h
Expand Up @@ -112,6 +112,8 @@ typedef struct GeanyDocumentPrivate
GtkWidget *info_bars[NUM_MSG_TYPES];
/* Keyed Data List to attach arbitrary data to the document */
GData *data;
/* Text used for filtering symbol tree. */
gchar *tag_filter;
}
GeanyDocumentPrivate;

Expand Down
4 changes: 1 addition & 3 deletions src/symbols.c
Expand Up @@ -320,16 +320,14 @@ static GList *get_tag_list(GeanyDocument *doc, TMTagType tag_types)
{
GList *tag_names = NULL;
guint i, j;
GtkEntry *tf_entry;
gchar **tf_strv;

g_return_val_if_fail(doc, NULL);

if (! doc->tm_file || ! doc->tm_file->tags_array)
return NULL;

tf_entry = GTK_ENTRY(ui_lookup_widget(main_widgets.window, "entry_tagfilter"));
tf_strv = g_strsplit_set(gtk_entry_get_text(tf_entry), " ", -1);
tf_strv = g_strsplit_set(doc->priv->tag_filter, " ", -1);

for (i = 0; i < doc->tm_file->tags_array->len; ++i)
{
Expand Down

0 comments on commit 0c311c0

Please sign in to comment.