[英]VSCode extension with a tree view and custom context menu
我正在实现一个提供自定义树视图的 Visual Studio Code 扩展,在树视图中,我使用以下contributes
设置在上下文菜单中显示自定义命令:
"contributes": {
...
"menus": {
"view/item/context": [
{
"command": "myExtension.uploadFile",
"when": "view == myBucketExplorer"
}
]
}
...
}
现在,有没有办法只在树视图中为根节点显示此命令? 是否有一个when
子句可以帮助解决这个问题,或者我是否需要在实际调用菜单时以编程方式禁用该命令?
您可以为TreeItem
设置contextValue
。
export class Something extends vscode.TreeItem {
// ...
constructor(
isRoot: boolean
) {
this.contextValue = isRoot ? 'YOUR_CONTEXT' : undefined;
}
}
async getChildren(element?: Something): Promise<Something[]> {
if (element) {
// NOT root
} else {
// ROOT -- Use different context for items
}
}
然后使用
"when": "view == myBucketExplorer && viewItem == YOUR_CONTEXT"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.