Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: GitHub noreply@github.com Date: Wed, 21 Sep 2022 21:32:58 UTC Commit: 0bc92b0f54423f376f49fb5dcbd8dcfa5c30d618 https://github.com/geany/geany/commit/0bc92b0f54423f376f49fb5dcbd8dcfa5c30d6...
Log Message: ----------- Merge pull request #3172 from techee/flat_tree
Add option to show symbols in symbol tree without root groups
Modified Paths: -------------- doc/geany.txt src/document.c src/documentprivate.h src/keyfile.c src/symbols.c src/tagmanager/tm_parser.c src/ui_utils.h
Modified: doc/geany.txt 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -264,6 +264,7 @@ described by that plugin documentation):
* expand/collapse the tree * control sorting order + * control whether to group symbols by their type * locate the symbol in documents
The symbols tab can also be filtered by typing a string into
Modified: src/document.c 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -648,6 +648,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->priv->symbols_group_by_type = TRUE; doc->id = ++doc_id_counter; doc->index = new_idx; doc->file_name = g_strdup(utf8_filename);
Modified: src/documentprivate.h 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -114,6 +114,8 @@ typedef struct GeanyDocumentPrivate GData *data; /* Text used for filtering symbol tree. */ gchar *tag_filter; + /* Group symbols in symbol tree by their type. */ + gboolean symbols_group_by_type; } GeanyDocumentPrivate;
Modified: src/keyfile.c 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -653,6 +653,7 @@ static void save_ui_prefs(GKeyFile *config) g_key_file_set_boolean(config, PACKAGE, "statusbar_visible", interface_prefs.statusbar_visible); g_key_file_set_boolean(config, PACKAGE, "msgwindow_visible", ui_prefs.msgwindow_visible); g_key_file_set_boolean(config, PACKAGE, "fullscreen", ui_prefs.fullscreen); + g_key_file_set_boolean(config, PACKAGE, "symbols_group_by_type", ui_prefs.symbols_group_by_type); g_key_file_set_string(config, PACKAGE, "color_picker_palette", ui_prefs.color_picker_palette);
/* get the text from the scribble textview */ @@ -1083,6 +1084,7 @@ static void load_ui_prefs(GKeyFile *config) ui_prefs.sidebar_visible = utils_get_setting_boolean(config, PACKAGE, "sidebar_visible", TRUE); ui_prefs.msgwindow_visible = utils_get_setting_boolean(config, PACKAGE, "msgwindow_visible", TRUE); ui_prefs.fullscreen = utils_get_setting_boolean(config, PACKAGE, "fullscreen", FALSE); + ui_prefs.symbols_group_by_type = utils_get_setting_boolean(config, PACKAGE, "symbols_group_by_type", TRUE); ui_prefs.custom_date_format = utils_get_setting_string(config, PACKAGE, "custom_date_format", ""); ui_prefs.custom_commands = g_key_file_get_string_list(config, PACKAGE, "custom_commands", NULL, NULL); ui_prefs.custom_commands_labels = g_key_file_get_string_list(config, PACKAGE, "custom_commands_labels", NULL, NULL);
Modified: src/symbols.c 40 lines changed, 36 insertions(+), 4 deletions(-) =================================================================== @@ -100,6 +100,7 @@ static struct GtkWidget *find_usage; GtkWidget *find_doc_usage; GtkWidget *find_in_files; + GtkWidget *group_by_type; } symbol_menu;
@@ -975,16 +976,18 @@ static void update_tree_tags(GeanyDocument *doc, GList **tags) foreach_list (item, *tags) { TMTag *tag = item->data; - GtkTreeIter *parent; + GtkTreeIter *parent, *parent_group;
- parent = get_tag_type_iter(tag->lang, tag->type); - if (parent) + parent_group = get_tag_type_iter(tag->lang, tag->type); + /* tv_iters[0] is reserved for the "Symbols" group */ + parent = ui_prefs.symbols_group_by_type ? parent_group : &tv_iters[0]; + if (parent_group) { gboolean expand; const gchar *name; const gchar *parent_name; gchar *tooltip; - GdkPixbuf *icon = get_child_icon(store, parent); + GdkPixbuf *icon = get_child_icon(store, parent_group);
parent_name = get_parent_name(tag); if (parent_name) @@ -1137,6 +1140,11 @@ gboolean symbols_recreate_tag_list(GeanyDocument *doc, gint sort_mode) if (tags == NULL) return FALSE;
+ if (doc->priv->symbols_group_by_type != ui_prefs.symbols_group_by_type) + gtk_tree_store_clear(doc->priv->tag_store); + + doc->priv->symbols_group_by_type = ui_prefs.symbols_group_by_type; + /* FIXME: Not sure why we detached the model here? */
/* disable sorting during update because the code doesn't support correctly @@ -2053,6 +2061,17 @@ static void on_symbol_tree_sort_clicked(GtkMenuItem *menuitem, gpointer user_dat doc->has_tags = symbols_recreate_tag_list(doc, sort_mode); }
+static void on_symbol_tree_group_by_type_clicked(GtkMenuItem *menuitem, gpointer user_data) +{ + GeanyDocument *doc = document_get_current(); + + if (ignore_callback) + return; + + ui_prefs.symbols_group_by_type = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem)); + if (doc != NULL) + doc->has_tags = symbols_recreate_tag_list(doc, SYMBOLS_SORT_USE_PREVIOUS); +}
static void on_symbol_tree_menu_show(GtkWidget *widget, gpointer user_data) @@ -2063,6 +2082,7 @@ static void on_symbol_tree_menu_show(GtkWidget *widget, enable = doc && doc->has_tags; gtk_widget_set_sensitive(symbol_menu.sort_by_name, enable); gtk_widget_set_sensitive(symbol_menu.sort_by_appearance, enable); + gtk_widget_set_sensitive(symbol_menu.group_by_type, enable); gtk_widget_set_sensitive(symbol_menu.expand_all, enable); gtk_widget_set_sensitive(symbol_menu.collapse_all, enable); gtk_widget_set_sensitive(symbol_menu.find_usage, enable); @@ -2078,6 +2098,9 @@ static void on_symbol_tree_menu_show(GtkWidget *widget, else gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(symbol_menu.sort_by_appearance), TRUE);
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(symbol_menu.group_by_type), + ui_prefs.symbols_group_by_type); + ignore_callback = FALSE; }
@@ -2165,6 +2188,15 @@ static void create_taglist_popup_menu(void) gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(menu), item);
+ symbol_menu.group_by_type = item = gtk_check_menu_item_new_with_mnemonic(_("_Group by Type")); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(menu), item); + g_signal_connect(item, "activate", G_CALLBACK(on_symbol_tree_group_by_type_clicked), NULL); + + item = gtk_separator_menu_item_new(); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(menu), item); + symbol_menu.find_usage = item = ui_image_menu_item_new(GTK_STOCK_FIND, _("Find _Usage")); gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(menu), item);
Modified: src/tagmanager/tm_parser.c 26 lines changed, 18 insertions(+), 8 deletions(-) =================================================================== @@ -1186,30 +1186,40 @@ gint tm_parser_get_sidebar_group(TMParserType lang, TMTagType type) for (i = 0; i < map->group_num; i++) { if (map->groups[i].types & type) - return i; + return i + 1; // "Symbols" group is always first } return -1; }
const gchar *tm_parser_get_sidebar_info(TMParserType lang, gint group, guint *icon) { + const gchar *name; TMParserMap *map; TMParserMapGroup *grp;
if (lang >= TM_PARSER_COUNT) return NULL;
- map = &parser_map[lang]; - if (group >= (gint)map->group_num) - return NULL; + if (group == 0) + { + name = _("Symbols"); + *icon = TM_ICON_NAMESPACE; + } + else + { + map = &parser_map[lang]; + if (group > (gint)map->group_num) + return NULL;
- grp = &map->groups[group]; - *icon = grp->icon; + grp = &map->groups[group - 1]; + name = grp->name; + *icon = grp->icon; + } #ifdef GETTEXT_PACKAGE - return g_dgettext(GETTEXT_PACKAGE, grp->name); + return g_dgettext(GETTEXT_PACKAGE, name); #else - return grp->name; + return name; #endif }
Modified: src/ui_utils.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -168,6 +168,7 @@ typedef struct UIPrefs gboolean allow_always_save; /* if set, files can always be saved, even if unchanged */ gchar *statusbar_template; gboolean new_document_after_close; + gboolean symbols_group_by_type;
/* Menu-item related data */ GQueue *recent_queue;
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).