简体   繁体   English

如何在VSCode扩展的资源管理器视图中指定图标的顺序?

[英]How to specify the order of icons in an explorer view in a VSCode extension?

In my extension I have some buttons on the bar of an explorer view: 在我的扩展程序中,浏览器视图栏上有一些按钮:

在此处输入图片说明

How can I specify the order in which the buttons will appear? 如何指定按钮的显示顺序?

I tried changing in the package.json the order of the commands in the commands property: 我尝试在package.json更改commands属性中命令的顺序:

"commands": [
  {
    "command": "codeFragments.exportFragments",
    "title": "Export all fragments to Json",
    "icon": {
      "light": "images/icon-export-light.png",
      "dark": "images/icon-export-dark.png"
    }
  },
  {
    "command": "codeFragments.importFragments",
    "title": "Import fragments from Json",
    "icon": {
      "light": "images/icon-import-light.png",
      "dark": "images/icon-import-dark.png"
    }
  },
  {
    "command": "codeFragments.deleteAllFragments",
    "title": "Delete all fragments",
    "icon": {
      "light": "images/icon-delete-light.png",
      "dark": "images/icon-delete-dark.png"
    }
  }
],

Also tried reordering in the part where I specify the UI, in the view/title property: 还尝试在我指定UI的部分的view/title属性中重新排序:

"view/title": [
  {
    "command": "codeFragments.exportFragments",
    "when": "view == codeFragments",
    "group": "navigation"
  },
  {
    "command": "codeFragments.importFragments",
    "when": "view == codeFragments",
    "group": "navigation"
  },
  {
    "command": "codeFragments.deleteAllFragments",
    "when": "view == codeFragments",
    "group": "navigation"
  }
],

And also tried to change the order in the part when I'm pushing the command subscriptions: 当我推送命令订阅时,还尝试更改零件的顺序:

context.subscriptions.push(
  vscode.commands.registerCommand('codeFragments.exportFragments', exportFragments));
context.subscriptions.push(
  vscode.commands.registerCommand('codeFragments.importFragments', importFragments));
context.subscriptions.push(
  vscode.commands.registerCommand('codeFragments.deleteAllFragments', deleteAllFragments));

But none of these approaches seem to affect the order, the buttons always appear in a seemingly incidental order. 但是这些方法似乎都不影响顺序,按钮总是以看似偶然的顺序出现。

What's the proper way to specify the order? 指定顺序的正确方法是什么?

After debugging the vscode source for a while, I found the solution, the sorting is happening here: https://github.com/Microsoft/vscode/blob/master/src/vs/platform/actions/electron-browser/menusExtensionPoint.ts#L365 在调试了一段时间后,我找到了解决方案,排序在这里进行: https : //github.com/Microsoft/vscode/blob/master/src/vs/platform/actions/electron-browser/menusExtensionPoint。 TS#L365

Basically the order number can be appended to the group name of the command after an @ symbol, so I had to do the following. 基本上,订单号可以附加在@符号后的命令组名称中,因此我必须执行以下操作。

"view/title": [
  {
    "command": "codeFragments.exportFragments",
    "when": "view == codeFragments",
    "group": "navigation@0"
  },
  {
    "command": "codeFragments.importFragments",
    "when": "view == codeFragments",
    "group": "navigation@1"
  },
  {
    "command": "codeFragments.deleteAllFragments",
    "when": "view == codeFragments",
    "group": "navigation@2"
  }
],

And after finding this, I tried to google again, and it turns out this was properly documented already, but somehow I missed it when searching for it the first time: https://code.visualstudio.com/docs/extensionAPI/extension-points#_sorting-inside-groups 找到这个之后,我再次尝试使用Google进行搜索,结果证明它已经被正确记录了,但是第一次以某种方式我错过了它: https : //code.visualstudio.com/docs/extensionAPI/extension-点#_sorting -内基

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM