简体   繁体   English

如何为 vscode 扩展创建状态栏图标

[英]How to create a status bar icon for a vscode extension

Thanks for the help, I would like to create a status bar button with a custom icon for my vscode extension.感谢您的帮助,我想为我的 vscode 扩展创建一个带有自定义图标的状态栏按钮。 I have scoured documentation and code but none seems to work.我已经搜索了文档和代码,但似乎都没有。 The code so far.代码到此为止。

import * as vscode from 'vscode';
import "typescript";

let statusBar : vscode.StatusBarItem;

export function activate(context: vscode.ExtensionContext) {
    console.log("code-boilerplate is active!");
    
    const codeBoilerplate = vscode.commands.registerCommand('code-boilerplate.CodeBoilerPlate', () => {
    
        const documentFileType = vscode.window.activeTextEditor?.document.languageId;
        const documentFileName = vscode.window.activeTextEditor?.document.fileName;

        vscode.window.showInformationMessage("Generating your Code Boilerplate... ⌛")
        if (documentFileType === "javascript") {
            return null;
        }
        else if (documentFileType === "python") {
            return null;
        }
        else if (documentFileType === "typescript") {
            return null;
        }
        else if (documentFileType === "csharp") {
            return null;
        }
        else if (documentFileType === "c") {
            return null;
        }
        else if (documentFileType === "cpp") {
            return null;
        }
        else if (documentFileType === "java") {
            return null;
        }
    });

    statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
    statusBar.command = codeBoilerplate;

    context.subscriptions.push(codeBoilerplate);
}

// this method is called when your extension is deactivated
export function deactivate() {
    console.log("code-boilerplate is deactivated!");
}

The code is for a code boilerplate which generates a HelloWorld application when you click a button.该代码用于代码样板,当您单击按钮时会生成 HelloWorld 应用程序。

In general you can include an icon in a StatusBarItem with:通常,您可以在StatusBarItem中包含一个图标:

statusBarItem.text = "$(icon-name) some text";

See https://code.visualstudio.com/api/references/vscode-api#StatusBarItem请参阅https://code.visualstudio.com/api/references/vscode-api#StatusBarItem

Here are the available icons for use: Product Icon Reference .以下是可供使用的图标: 产品图标参考

The text to show for the entry.为条目显示的文本。 You can embed icons in the text by leveraging the syntax:您可以利用以下语法在文本中嵌入图标:

My text $(icon-name) contains icons like $(icon-name) this one.我的文本 $(icon-name) 包含像 $(icon-name) 这样的图标。

Where the icon-name is taken from the ThemeIcon icon set, eg light-bulb, thumbsup, zap etc.图标名称取自 ThemeIcon 图标集,例如灯泡、拇指向上、zap 等。

However, if you want a custom icon outside that ThemeIcon set, it doesn't look like that is supported: see Support Custom Icons in Status Bar .但是,如果您想要一个ThemeIcon集之外的自定义图标,它看起来不受支持:请参阅Support Custom Icons in Status Bar

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

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