简体   繁体   English

自定义按钮未显示在 VS 代码编辑器标题菜单栏中

[英]Custom button is not showing in the VS code editor title menu bar

In an extension I want to add a button to display in the VS code editor title menu bar when it opens a synapse XML document.In order to that, I added the following command in commands of package.json file,在一个扩展中,我想添加一个按钮,当它打开一个突触 XML 文档时,在 VS 代码编辑器标题菜单栏中显示。为此,我在 package.json 文件的命令中添加了以下命令,

{
    "command": "webview.show",
    "title": "Show Diagram",
    "category": "Webview",
    "icon": {
        "light": "./resources/images/icons/design-view.svg",
        "dark": "./resources/images/icons/design-view-inverse.svg"
    }
}

and in the package.json file I added the following editor/title,在 package.json 文件中,我添加了以下编辑器/标题,

"menus": {
    "editor/title": [
        {
            "when": "resourceLangId == SynapseXml",
            "command": "webview.show",
            "group": "navigation"
        }
    ],
}

But when I run the extension and opens a synapse XML document, it will not showing the button in the editor title menu bar.但是当我运行扩展并打开一个突触 XML 文档时,它不会在编辑器标题菜单栏中显示该按钮。

Further I followed following documentation also, https://code.visualstudio.com/api/references/contribution-points#contributes.menus此外,我还遵循以下文档, https://code.visualstudio.com/api/references/contribution-points#contributes.menus

How can I display the button in VS code editor title menu bar?如何在 VS 代码编辑器标题菜单栏中显示按钮?

I added your command and menu entry to an extension I'm making and the button appears where it should (all be it without an image in my screenshot as I don't have the icon).我将您的命令和菜单条目添加到我正在制作的扩展程序中,并且按钮出现在它应该出现的位置(因为我没有图标,所以我的屏幕截图中没有图像)。 In my screenshot it is the empty space on the left of the ying-yang button - the tooltip is visible though on mouse over.在我的屏幕截图中,它是阴阳按钮左侧的空白区域 - 尽管鼠标悬停,工具提示仍然可见。 I just removed the "where" test so I would guess that resourceLangId is not what you think it is or maybe the icons path is wrong so it looks like it isn't there as in my screenshot我刚刚删除了“where”测试,所以我猜测 resourceLangId 不是你认为的那样,或者图标路径可能是错误的,所以它看起来不像我的截图那样存在

在此处输入图片说明

For anyone still having the same issue:对于仍然有相同问题的任何人:

In my case, using the correct context name field ( editorLangId ) to match the language ID in the when clause of the command fixed the issue.在我的情况下,使用正确的上下文名称字段 ( editorLangId ) 匹配命令的when子句中的语言 ID 修复了该问题。

https://code.visualstudio.com/api/references/when-clause-contexts#available-contexts https://code.visualstudio.com/api/references/when-clause-contexts#available-contexts

"menus": {
    "editor/title": [
        {
            "when": "editorLangId == SynapseXml",
            "command": "webview.show",
            "group": "navigation"
        }
    ]
}

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

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