KEMBAR78
pass selected tree item context to view/title commands · Issue #42903 · microsoft/vscode · GitHub
Skip to content

pass selected tree item context to view/title commands #42903

@chrisdias

Description

@chrisdias

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.

      "view/title": [
        {
          "command": "vscode-docker.explorer.run",
          "when": "view == dockerExplorer",
          "group": "navigation"
        }
      ],

I would register my command:

vscode.commands.registerCommand('vscode-docker.explorer.run', (context?: any, selectedContext?: any[]) => dockerExplorerProvider.run(context, selectedContext));

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
   }
   // ...
}

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions