While the current way of grouping symbols under various categories like "Functions", "Structures", "Macros" etc. may be useful in some situations, it doesn't allow true sorting by name or sorting by line number because this sorting is only valid within the group and not globally which makes it sometimes hard to find some symbol.
This patch adds the option to switch between two views of the symbol tree using the context menu:
- Categorized - the original view used by Geany - Uncategorized - view with a single root element "Symbols" in which all symbols are rooted and all of them either sorted by line number or alphabetically
<img width="294" alt="Screen Shot 2022-04-17 at 16 17 38" src="https://user-images.githubusercontent.com/713965/163718570-0beb2998-c646-48b...;
<img width="286" alt="Screen Shot 2022-04-17 at 16 18 33" src="https://user-images.githubusercontent.com/713965/163718574-84ba4857-7674-40a...;
The core of the implementation is rather simple - there's always the "Symbols" root present at position 0 in tv_iters and when categorized view is selected, this root is used for all the tags. (We still need to keep the category roots in this situation to copy the icons for the tags from them but they are always empty and hidden).
The rest is some UI stuff for creating entries in the context menu, I also added a config preference so this settings is remembered across Geany re-launches. I made this option global for all open files because I would find it annoying to apply this setting manually for every open file. So the code also checks whether the view type changed for the given file when switching tabs and re-creates the tree with the new setting. You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/3172
-- Commit Summary --
* Add option to show symbols in symbol tree without root groups
-- File Changes --
M src/document.c (1) M src/documentprivate.h (2) M src/keyfile.c (2) M src/symbols.c (54) M src/tagmanager/tm_parser.c (26) M src/ui_utils.h (1)
-- Patch Links --
https://github.com/geany/geany/pull/3172.patch https://github.com/geany/geany/pull/3172.diff
I wanted this feature for a long time and it turned out to be very easy to implement with the new way of getting symbol root names. This feature is also good for debugging ctags parsers because when sorted by line number, one can easily see at what line the parser stopped or started producing wrong output.
The names "Categorized" and "Uncategorized" are the best I could come up with but I'm sure there is some better name for these so suggestions are welcome.
I wonder why the single "Symbols" root row is needed? It seems superfluous and adds a level of indentation.
The document tab with "Documents only" option avoids this and I think it's preferable.
Neat.
Categorised and Uncategorised seems fine to me, but (as I just showed :-) it needs to be translatable so British vs US spelling can be selected. Or "Category View" and "Single View".
I wonder why the single "Symbols" root row is needed? It seems superfluous and adds a level of indentation.
It's not needed but it greatly simplifies the implementation - the code constructing the tree is basically the same as before (only 1 extra line of code), there's just a single top-level category instead of several. So yeah, I agree it's unnecessary but the tree construction code is really complicated already and I don't want to make it worse by adding many more `if (categorized) do_stuff; else do_stuff2;`
Categorised and Uncategorised seems fine to me, but (as I just showed :-) it needs to be translatable so British vs US spelling can be selected.
Yeah, it's translatable. I guess default is US, right? Haven't found any "colours" and "founts" in Geany strings ;-).
Or "Category View" and "Single View".
Or maybe "Flat View" instead of "Single View" (though it's not completely flat as tags with scopes are nested in their parents). But from these I probably prefer the "Categorized" names.
So yeah, I agree it's unnecessary but the tree construction code is really complicated already and I don't want to make it worse by adding many more if (categorized) do_stuff; else do_stuff2;
Knowing the (semi-related) code for the documents list pretty good by now (courtesy of #1812) I don't think it's that bad. But if you truly don't have the desire to look into this now maybe that can be left to a future PR if it's itchy enough for that guy.
Knowing the (semi-related) code for the documents list pretty good by now (courtesy of https://github.com/geany/geany/issues/1812) I don't think it's that bad
That code is for babies really ;-).
The symbol tree code spans from line 260 to line 1260 in symbols.c. It doesn't re-create the tree when something changes like the documents list - it really updates the tree by first removing invalid entries and then adding new entries, otherwise the tree would scroll all the time when you add or remove something that generates a tag. Multiple hash tables are involved in constructing it to detect the changes. If there's one piece of code to fear in Geany, it's the symbol tree code (followed by scope autocompletion). I already did some things in the past with the symbol tree to optimize it and developed quite a bit of respect to it - it works, it's very fragile because even small changes tend to break it, and better not to touch it much.
In any case, anyone brave enough is encouraged to improve it :-).
The code looks mostly good. My only concern is with the UI. In my view a checkbox `[ ] Show categories` (or maybe categories -> groups) is preferable and saves a line in the menu. What do you think?
Yeah, can do, either is fine with me.
@techee pushed 1 commit.
77d3b9e350881185cbd3c171a9fd48293137d351 Use single checkbox for enabling/disabling grouping
OK, I made the proposed change and I also like this single checkbox better. I was just thinking about the name a bit more and found `[ ] Group by Type` more fitting so I used it. What do you think?
I like it
@kugel- approved this pull request.
@techee pushed 1 commit.
de9fd96ff0cc2b43da3c57172a8381cc78815f99 Add simple documentation regarding symbol grouping toggle
@elextr I just added a commit mentioning this feature in the documentation. Is it sufficient this way?
@techee, docs are fine for current UI
Just a comment, wanna bet somebody interprets "by type" as by int float string etc ;-) Technically it should be "by kind" but then beginners won't know what that means, so might as well leave it.
Just a comment, wanna bet somebody interprets "by type" as by int float string etc ;-) Technically it should be "by kind" but then beginners won't know what that means, so might as well leave it.
Yeah, I was thinking the same - better not to leak ctags terminology to end users. Also, technically, it's not even kinds - several different kinds can be grouped into the same root in the tree by our mappings in `tm_parser.c`.
I think type is good, but category might work too.
I just squashed the patches and reworded the original commit message with the new "Group by Type" checkbox.
Unless there are any objections, I'd merge this PR in about a week.
Merged #3172 into master.
github-comments@lists.geany.org