gpt4 book ai didi

visual-studio-code - 带有 TreeView 和自定义上下文菜单的 VSCode 扩展

转载 作者:行者123 更新时间:2023-12-04 01:43:05 27 4
gpt4 key购买 nike

我正在实现一个提供自定义树 View 的 Visual Studio Code 扩展,在树 View 中我使用以下 contributes 在上下文菜单中显示自定义命令设置:

"contributes": {
...
"menus": {
"view/item/context": [
{
"command": "myExtension.uploadFile",
"when": "view == myBucketExplorer"
}
]
}
...
}

现在,有没有办法只在树 View 中为根节点显示此命令?也许有 when可以帮助解决这个问题的子句,或者我是否需要在实际调用菜单时以编程方式禁用该命令?

最佳答案

您可以设置 contextValue为您 TreeItem .

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"

关于visual-studio-code - 带有 TreeView 和自定义上下文菜单的 VSCode 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56576482/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com