You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pass selected tree item context to view/title commands #42903
I would like to have the selected context passed to view commands so that I can act on the selected node in the tree. for example, let's say I want to have a command in the Docker explorer Navigation area (next to where it says "DOCKER" on the sash) that runs the selected image in the tree.
And then in my command I can get the selected node(s) from the tree
build(context?: any): void{if(selectedContext.length>0){// work on multi selected images}...if(context){// work on selected image}else{// pop a quick pick to list images}// ...}
Reacted by Eric Amodio, Dakara, bogobogo, Nigel Scott, Alexander Galushka, Alex Weininger, heartacker, Matt Hernandez and Florentijn Cornet
I would expand on this to also provide the treeview instance as well as the selected node. I have some generic commands (refresh, close, etc) that I use across a few views, and right now I am required to create new commands for each view (causing a command explosion in package.json and a maintenance issue). It the view was also provided all of that duplication could be eliminated.
I would also love if the treeview was also returned on itself even when executing a command on a node (so that way the node doesn't have to carry around its parent if access is needed).
Overall I keep coming back to this request: #25716 having more/structured context for how commands were invoked makes them much easier to deal with
Eric Amodio (@eamodio) Could you do something like this? I use an internal command to proxy to functions I want to invoke so I don't have to register every action as a command.
Register a view/title command (takes 2 arguments) in a panel which has a tree view
set breakpoint in command function
Select tree item(s) and run command from view/title
First argument should always be the focused tree item (type T).
Second argument should be (all) selected tree items as long as the focused tree item is one of the selected tree items.
The arguments should behave the same as for commands in the context menu.
Make sure you register the view/title command to a contributed TreeView (for example in Sample Tree Views extension or Pull Requests extension).
Then select an element in the tree (or multiple if multiselect) and press the action. The arguments should then print the focused item and the selected items
Activity
eamodio commentedon Apr 30, 2018
I would expand on this to also provide the treeview instance as well as the selected node. I have some generic commands (refresh, close, etc) that I use across a few views, and right now I am required to create new commands for each view (causing a command explosion in
package.jsonand a maintenance issue). It the view was also provided all of that duplication could be eliminated.I would also love if the treeview was also returned on itself even when executing a command on a node (so that way the node doesn't have to carry around its parent if access is needed).
Overall I keep coming back to this request: #25716 having more/structured context for how commands were invoked makes them much easier to deal with
d-akara commentedon May 5, 2018
Eric Amodio (@eamodio) Could you do something like this? I use an internal command to proxy to functions I want to invoke so I don't have to register every action as a command.
Here is an example snippet of something I use...
28 remaining items
alexr00 commentedon Sep 21, 2022
Great to hear! Closing this issue so that it gets added to our testing for September.
benibenj commentedon Sep 27, 2022
Verifying:
Second argument should be (all) selected tree items as long as the focused tree item is one of the selected tree items.
The arguments should behave the same as for commands in the context menu.
irvnriir commentedon Sep 28, 2022
How to get them ?
doesn't work:
gjsjohnmurray commentedon Sep 28, 2022
irvnriir are you using Insiders for this? If not you'll need to wait until 1.72 ships, probably by the end of next week,
roblourens commentedon Sep 29, 2022
Am I doing it wrong?
All I get is
undefined undefined. Registered it in all view/title, and clicked it everywhere I see it, for example, Explorer and Outlinebenibenj commentedon Sep 29, 2022
Make sure you register the view/title command to a contributed
TreeView(for example in Sample Tree Views extension or Pull Requests extension).Then select an element in the tree (or multiple if multiselect) and press the action. The arguments should then print the focused item and the selected items
roblourens commentedon Sep 29, 2022
Oh, I see it, thanks