godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Improve Tree's multiselect signals #1490

Open mnemoli opened 4 years ago

mnemoli commented 4 years ago

Describe the project you are working on: Editor plugin which triggers an event as a result of FileSystem selections.

Describe the problem or limitation you are having in your project: Multi-select trees (i.e. what the filesystem dock uses) currently emit a multi_selected signal for each item which has changed. That is:

Anyone who wishes to trigger something as a result of the user's selection must therefore understand the following unintuitive things:

Describe the feature / enhancement and how it helps to overcome the problem or limitation: I propose a "multi_select_complete" signal which is emitted only when selection is complete. This signal will only raise for multi-select trees, and will contain a list of the TreeItems selected. This provides a much simpler and more intuitive way for users writing GUIs to process such events.

The FileSystem dock can connect to this and raise a "files_selected" event (since the tree is not easily accessible from the filesystem itself) with an array of selected paths. Possibly similar for the scene tree dock.

Additionally, it seems that getting the tree selection currently involves partially traversing the tree multiple times via get_next_selected. Can this be cached at selection time instead, and provided via a new function returning a full list?

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

Draft here: https://github.com/godotengine/godot/compare/master...mnemoli:tree-enhance-master

(A bit inefficient at the moment, since it traverses the tree to get the selection right after we've just calculated the selection!)

If this enhancement will not be used often, can it be worked around with a few lines of script?: I see no way to work around it if you want to trigger at the point the selection is actually complete.

Is there a reason why this should be core and not an add-on in the asset library?: Involves the inner workings of a core gui node.

mnemoli commented 4 years ago

Is there any way to write tests for the logic of CanvasItem components? Seems difficult since the logic and rendering are combined, and the RenderingServer isn't available in unit tests. Don't feel comfortable moving to selection caching without unit tests, there's a lot of spaghetti in that class.

Calinou commented 4 years ago

@mnemoli You'd need to create a test project that takes screenshots automatically when run, and compare the screenshots to check for differences across revisions.

See this plugin for an example of taking screenshots. It can be adapted to take screenshots in a programmatic manner as a project is running.

JACKADUX commented 6 months ago

The current (godot 4.3 -dev5)tree multi-selection cannot determine whether the selection is completed.,Has this issue been resolved? Or is there any other way to know if the multi-select is complete?