diff options
Diffstat (limited to 'src/vs/workbench/browser/labels.ts')
-rw-r--r-- | src/vs/workbench/browser/labels.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/vs/workbench/browser/labels.ts b/src/vs/workbench/browser/labels.ts index 3e47d3df06a..34679828f66 100644 --- a/src/vs/workbench/browser/labels.ts +++ b/src/vs/workbench/browser/labels.ts @@ -114,6 +114,7 @@ export class ResourceLabels extends Disposable { @IInstantiationService private readonly instantiationService: IInstantiationService, @IConfigurationService private readonly configurationService: IConfigurationService, @IModelService private readonly modelService: IModelService, + @IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService, @ILanguageService private readonly languageService: ILanguageService, @IDecorationsService private readonly decorationsService: IDecorationsService, @IThemeService private readonly themeService: IThemeService, @@ -153,6 +154,11 @@ export class ResourceLabels extends Disposable { this.widgets.forEach(widget => widget.notifyModelAdded(model)); })); + // notify when workspace folders changes + this._register(this.workspaceService.onDidChangeWorkspaceFolders(() => { + this.widgets.forEach(widget => widget.notifyWorkspaceFoldersChange()); + })); + // notify when file decoration changes this._register(this.decorationsService.onDidChangeDecorations(e => { let notifyDidChangeDecorations = false; @@ -250,13 +256,14 @@ export class ResourceLabel extends ResourceLabels { @IInstantiationService instantiationService: IInstantiationService, @IConfigurationService configurationService: IConfigurationService, @IModelService modelService: IModelService, + @IWorkspaceContextService workspaceService: IWorkspaceContextService, @ILanguageService languageService: ILanguageService, @IDecorationsService decorationsService: IDecorationsService, @IThemeService themeService: IThemeService, @ILabelService labelService: ILabelService, @ITextFileService textFileService: ITextFileService ) { - super(DEFAULT_LABELS_CONTAINER, instantiationService, configurationService, modelService, languageService, decorationsService, themeService, labelService, textFileService); + super(DEFAULT_LABELS_CONTAINER, instantiationService, configurationService, modelService, workspaceService, languageService, decorationsService, themeService, labelService, textFileService); this.label = this._register(this.create(container, options)); } @@ -279,6 +286,7 @@ class ResourceLabelWidget extends IconLabel { private computedIconClasses: string[] | undefined = undefined; private computedLanguageId: string | undefined = undefined; private computedPathLabel: string | undefined = undefined; + private computedWorkspaceFolderLabel: string | undefined = undefined; private needsRedraw: Redraw | undefined = undefined; private isHidden: boolean = false; @@ -374,6 +382,15 @@ class ResourceLabelWidget extends IconLabel { } } + notifyWorkspaceFoldersChange(): void { + if (typeof this.computedWorkspaceFolderLabel === 'string') { + const resource = toResource(this.label); + if (URI.isUri(resource) && this.label?.name === this.computedWorkspaceFolderLabel) { + this.setFile(resource, this.options); + } + } + } + setFile(resource: URI, options?: IFileLabelOptions): void { const hideLabel = options?.hideLabel; let name: string | undefined; @@ -382,6 +399,7 @@ class ResourceLabelWidget extends IconLabel { const workspaceFolder = this.contextService.getWorkspaceFolder(resource); if (workspaceFolder) { name = workspaceFolder.name; + this.computedWorkspaceFolderLabel = name; } } @@ -602,5 +620,6 @@ class ResourceLabelWidget extends IconLabel { this.computedLanguageId = undefined; this.computedIconClasses = undefined; this.computedPathLabel = undefined; + this.computedWorkspaceFolderLabel = undefined; } } |