如何在编辑器操作工具栏中添加自定义图标
我想在编辑器操作工具栏上添加一个自定义图标,这将是指命令的链接。当在VSCODE上打开任何文件时,应与文件旁边可见图标。如何添加自定义图标?任何线索都会有用
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想在编辑器操作工具栏上添加一个自定义图标,这将是指命令的链接。当在VSCODE上打开任何文件时,应与文件旁边可见图标。如何添加自定义图标?任何线索都会有用
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
在package.json中添加您的自定义命令。有关更多详细信息,请查看以下链接:
Add your custom command inside package.json under "editor/title" and "command". For more details check the following links:
要在此处添加图标,您需要编辑
package.json
文件。只需添加一个命令和菜单贡献点,该点可以说明VSCODE在哪里放置菜单项,这里有一个答案,该答案具有链接到VS Code API文档,但是该文档已被抽出很大您将放入
package.json
文件中。因此,我将举一个简单的现实世界代码软件包。JSON
需要两个项目。
下的命令贡献.commands
。该命令应具有图标(请参阅产品图标参考)convortes.menus.editor/title
菜单下添加命令。如果您希望它显示为顶级项目,请将组
设置为navigation
。您还可以(并且可能应该)设置子句时设置,以便图标仅在满足某些条件时显示。 (请参阅wher strage reference )
子句时省略在示例中,图标将仅在JavaScript文件上显示。如果您在
,它将始终显示
,当用户单击图标上时,除非您在扩展激活功能中为命令设置处理程序功能,否则它将无能为力。这也意味着您还必须在
package.json.json
文件中设置正确的activationEvents
,否则将无法设置处理程序。这是一个简单的扩展程序的完整示例,它可以执行您的要求:
package.json(完整示例),
并且由于我在我的
main 设置为
extension.js
> package.json 文件,您还需要一个名为extension.js
的文件。这是一个简单的示例,可以让您启动Extension.js
To add an icon there, you'll need to edit your
package.json
file. Simply add a command and a menu contribution point that tells VSCode where to place the menu itemThere is an answer here that has links to the VS code API documentation, but that documentation is very drawn out and doesn't give any good examples on exactly what you would put into your
package.json
file. So, I'll give a simple example of some real world codepackage.json
There are two items that are needed.
contributes.commands
. That command should have an icon (see the product icons reference)contributes.menus.editor/title
menu. If you want it to display as a top level item, set thegroup
tonavigation
. You can also (and probably should) set awhen
clause so that the icon only shows when certain conditions are met. (See the when clause reference)In the example, the icon will only show on JavaScript files. If you omit the
when
clause, it will always showNote that when the user clicks on the icon, it will do nothing unless you set a handler function for the command in your extension activation function. Which also means that you have to set the correct
activationEvents
in yourpackage.json
file as well or the handler won't be set.Here is a full example of a simple extension that does what you are asking:
package.json (full example)
And since I set
main
toextension.js
in mypackage.json
file, you'll need a file namedextension.js
as well. Here is a simple example that will get you startedextension.js