是不是可能为资源管理器开发一个文件标签扩展?

huangapple go评论44阅读模式
英文:

Is it possible to develop a file label extension for EXPLORER?

问题

我想为 VSCode 的 EXPLORER 开发一个扩展,用于为文件/目录设置标签(或标记),以便我可以区分它们。

是不是可能为资源管理器开发一个文件标签扩展?

但我在 VSCode 文档中搜索时,并没有找到介绍这个实现的地方。是否可能实现这个功能?

英文:

I want to develop a VSCode Extension for EXPLORER to set label (or tag) for files/directories, so that I can distinguish out them.

是不是可能为资源管理器开发一个文件标签扩展?

but I searched the Document of VSCode Docs, didn't find a place to introduce this implementation. Is it possible to do it?

答案1

得分: 0

你应该查找FileDecoration API

它允许你为文件和文件夹定义badgecolortooltip

根据你的模拟,我猜这个API应该可以正常工作。除非你需要为badge属性使用超过2个字符,但这是不可能的,至少目前是这样的。

更新/示例

这是一个小示例。它会在每个文件/文件夹的右侧添加一个笑脸表情(因为我忽略了Uri),并将文件/文件夹着色为problemsWarningIcon.foreground

我认为可能对你来说API的_color_可能并不完全符合你的需求,因为它会应用于文件/文件夹本身,而不仅仅是badge。如果这不符合你的需求,你需要在VS Code存储库中提出一个功能请求来进行更改。

class EmojiFileDecorationProvider implements vscode.FileDecorationProvider{
    onDidChangeFileDecorations?: vscode.Event<vscode.Uri | vscode.Uri[] | undefined> | undefined;
    provideFileDecoration(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult<vscode.FileDecoration> {
        return new vscode.FileDecoration("&#128512;", "tooltip smile", new vscode.ThemeColor("problemsWarningIcon.foreground"));
    }
}

export function activate(context: vscode.ExtensionContext) {
    ...
    vscode.window.registerFileDecorationProvider(new EmojiFileDecorationProvider());
}

希望对你有所帮助。

英文:

You should look for the FileDecoration API.

It allows you to define badge, color and tooltip for files and folders.

Based on your mockup, I guess this API would work just fine. Unless you need to have more than 2 characters for the badge attribute, which is not possible, today.

Update / Sample

Here is a small sample. It will add a smile emoji at the right side of every file/folder (because I'm ignoring Uri) and make the file/folder to be colored as problemsWarningIcon.foreground.

The color is where I think the API maybe doesn't work perfect for you, because it will be applied to the file/folder too, not only the badge. If this doesn't fit your needs, you need to open a feature request in VS Code repo asking for changes

class EmojiFileDecorationProvider implements vscode.FileDecorationProvider{
    onDidChangeFileDecorations?: vscode.Event&lt;vscode.Uri | vscode.Uri[] | undefined&gt; | undefined;
    provideFileDecoration(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult&lt;vscode.FileDecoration&gt; {
        return new vscode.FileDecoration(&quot;&#128512;&quot;, &quot;tooltip smile&quot;, new vscode.ThemeColor(&quot;problemsWarningIcon.foreground&quot;));
    }
}


export function activate(context: vscode.ExtensionContext) {
    ...
    vscode.window.registerFileDecorationProvider(new EmojiFileDecorationProvider());
}

Hope this helps

huangapple
  • 本文由 发表于 2023年2月24日 11:09:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75552284.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定