9

VSCode 1.3 增加了对向上下文菜单添加命令的支持。有没有办法确定是否单击文件或文件夹以打开资源管理器上下文菜单?

"menus": {
    "explorer/context": [
        {
            "when": "????",
            "command": "extension.myCommand",
            "group": "myGroup"
        }
    ]
}

此外,是否有一个全面的(ish)表达式列表,可以在此处的 when 子句中检查?

4

5 回答 5

14

您可以使用"when": "explorerResourceIsFolder".

我必须深入研究代码才能找到它(我实际上是在写一个回复说它不存在,并在我看到它时列举可能的子句值)。

从 v1.10.1 开始:

config.<any_config_path_here>
editorIsOpen
explorerResourceIsFolder
explorerViewletFocus
explorerViewletVisible
filesExplorerFocus
globalMessageVisible
inDebugMode
inQuickOpen
inZenMode
listFocus
openEditorsFocus
resource (Uri information: path, query, scheme, etc)
resourceFilename
resourceLangId
resourceScheme
scmProvider
textCompareEditorVisible

我已经提交了一个问题来改进文档。

于 2017-03-12T19:10:40.663 回答
8

关于获取上下文键的完整列表:在最近的 VSCode 版本中,有一个Developer: Inspect Context Keys命令。执行命令后,您可以选择一个 UI 元素:

之后,开发控制台打开,您可以在此“范围”中展开包含上下文键及其当前值的完整列表的记录对象:

于 2019-07-28T21:22:01.323 回答
4

https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts

是文件:"when": "!explorerResourceIsFolder"

是目录:"when": "explorerResourceIsFolder"

于 2018-06-30T16:55:45.710 回答
1

您可以像这样获取语言ID列表...

vscode.languages.getLanguages().then(l => console.log('languages', l));

我还没有弄清楚如何确定右键单击的项目是否是目录。如果有人弄清楚了,请告诉我。

于 2017-03-03T07:39:24.787 回答
0

关于该功能的文章在这里。但基本上:

  • when 和 keybindings 一样——when 和可以使用相同的键
  • 何时可以使用两个新键 resourceScheme 和 resourceLangId 无需编辑器即可使用 - 想想资源管理器上下文菜单
  • when 可以是一个布尔配置值,例如 config.editor.lineNumbers

我的菜单:

"menus":{
    "explorer/context": [
        {
            "when": "resourceLangId == sql",
            "command": "extension.myCmd"
        }
    ]
于 2016-07-09T04:35:14.677 回答