FileDecoration 模块主要用来注册/管理/分发跟文件名相关 Decoration 服务
Decoration 的详情
interface IDecorationData {
/**
* 权重
*/
readonly weight?: number;
/**
* Decoration 颜色
*/
readonly color?: ColorIdentifier;
/**
* Decoration 字符
*/
readonly letter?: string;
/**
* Decoration tooltip
*/
readonly tooltip?: string;
/**
* Decoration 是否冒泡,类似文件的 Decoration 是否传给文件夹
*/
readonly bubble?: boolean;
}
DI token: IDecorationsService
提供基于文件名的修饰服务
readonly onDidChangeDecorations: Event<IResourceDecorationChangeEvent>;
针对文件名的 Decoration 变更事件进行事件分发
this.decorationsService.onDidChangeDecorations(() => {
// some listener
})
registerDecorationsProvider(provider: IDecorationsProvider): IDisposable;
注册 DecorationsProvider
class SampleDecorationsProvider implements IDecorationsProvider {
readonly label = 'sample';
readonly onDidChangeEmitter: Emitter<Uri[]> = new Emitter();
get onDidChange() {
return this.onDidChangeEmitter.event;
}
provideDecorations(resource: Uri): IDecorationData | undefined {
if (file.scheme !== 'file') {
return undefined;
}
return {
letter: '😸',
color: 'cat.smileForeground',
tooltip: localize('cat.smile'),
weight: -1,
bubble: false,
} as IDecorationData;
}
}
getDecoration(uri: Uri, includeChildren: boolean, overwrite?: IDecorationData): IDecoration | undefined;
获取 uri 的方式获取当前文件的 Decoration 结果,如果没有获取到则返回 undefined
this.decorationsService.getDecoration(uri, true);