Skip to content

Commit ed81603

Browse files
authored
Update breadcrumbs when workspace folders update (microsoft#154616)
1 parent 955991d commit ed81603

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/vs/workbench/browser/labels.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export class ResourceLabels extends Disposable {
114114
@IInstantiationService private readonly instantiationService: IInstantiationService,
115115
@IConfigurationService private readonly configurationService: IConfigurationService,
116116
@IModelService private readonly modelService: IModelService,
117+
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
117118
@ILanguageService private readonly languageService: ILanguageService,
118119
@IDecorationsService private readonly decorationsService: IDecorationsService,
119120
@IThemeService private readonly themeService: IThemeService,
@@ -153,6 +154,11 @@ export class ResourceLabels extends Disposable {
153154
this.widgets.forEach(widget => widget.notifyModelAdded(model));
154155
}));
155156

157+
// notify when workspace folders changes
158+
this._register(this.workspaceService.onDidChangeWorkspaceFolders(() => {
159+
this.widgets.forEach(widget => widget.notifyWorkspaceFoldersChange());
160+
}));
161+
156162
// notify when file decoration changes
157163
this._register(this.decorationsService.onDidChangeDecorations(e => {
158164
let notifyDidChangeDecorations = false;
@@ -250,13 +256,14 @@ export class ResourceLabel extends ResourceLabels {
250256
@IInstantiationService instantiationService: IInstantiationService,
251257
@IConfigurationService configurationService: IConfigurationService,
252258
@IModelService modelService: IModelService,
259+
@IWorkspaceContextService workspaceService: IWorkspaceContextService,
253260
@ILanguageService languageService: ILanguageService,
254261
@IDecorationsService decorationsService: IDecorationsService,
255262
@IThemeService themeService: IThemeService,
256263
@ILabelService labelService: ILabelService,
257264
@ITextFileService textFileService: ITextFileService
258265
) {
259-
super(DEFAULT_LABELS_CONTAINER, instantiationService, configurationService, modelService, languageService, decorationsService, themeService, labelService, textFileService);
266+
super(DEFAULT_LABELS_CONTAINER, instantiationService, configurationService, modelService, workspaceService, languageService, decorationsService, themeService, labelService, textFileService);
260267

261268
this.label = this._register(this.create(container, options));
262269
}
@@ -279,6 +286,7 @@ class ResourceLabelWidget extends IconLabel {
279286
private computedIconClasses: string[] | undefined = undefined;
280287
private computedLanguageId: string | undefined = undefined;
281288
private computedPathLabel: string | undefined = undefined;
289+
private computedWorkspaceFolderLabel: string | undefined = undefined;
282290

283291
private needsRedraw: Redraw | undefined = undefined;
284292
private isHidden: boolean = false;
@@ -374,6 +382,15 @@ class ResourceLabelWidget extends IconLabel {
374382
}
375383
}
376384

385+
notifyWorkspaceFoldersChange(): void {
386+
if (typeof this.computedWorkspaceFolderLabel === 'string') {
387+
const resource = toResource(this.label);
388+
if (URI.isUri(resource) && this.label?.name === this.computedWorkspaceFolderLabel) {
389+
this.setFile(resource, this.options);
390+
}
391+
}
392+
}
393+
377394
setFile(resource: URI, options?: IFileLabelOptions): void {
378395
const hideLabel = options?.hideLabel;
379396
let name: string | undefined;
@@ -382,6 +399,7 @@ class ResourceLabelWidget extends IconLabel {
382399
const workspaceFolder = this.contextService.getWorkspaceFolder(resource);
383400
if (workspaceFolder) {
384401
name = workspaceFolder.name;
402+
this.computedWorkspaceFolderLabel = name;
385403
}
386404
}
387405

@@ -602,5 +620,6 @@ class ResourceLabelWidget extends IconLabel {
602620
this.computedLanguageId = undefined;
603621
this.computedIconClasses = undefined;
604622
this.computedPathLabel = undefined;
623+
this.computedWorkspaceFolderLabel = undefined;
605624
}
606625
}

src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,10 @@ export class BreadcrumbsControl {
280280
this._editorGroup.activeEditorPane
281281
);
282282

283-
this.domNode.classList.toggle('relative-path', model.isRelative());
284283
this.domNode.classList.toggle('backslash-path', this._labelService.getSeparator(uri.scheme, uri.authority) === '\\');
285284

286285
const updateBreadcrumbs = () => {
286+
this.domNode.classList.toggle('relative-path', model.isRelative());
287287
const showIcons = this._cfShowIcons.getValue();
288288
const options: IBreadcrumbsControlOptions = {
289289
...this._options,

src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class OutlineElement2 {
3737
export class BreadcrumbsModel {
3838

3939
private readonly _disposables = new DisposableStore();
40-
private readonly _fileInfo: FileInfo;
40+
private _fileInfo: FileInfo;
4141

4242
private readonly _cfgFilePath: BreadcrumbsConfig<'on' | 'off' | 'last'>;
4343
private readonly _cfgSymbolPath: BreadcrumbsConfig<'on' | 'off' | 'last'>;
@@ -60,6 +60,7 @@ export class BreadcrumbsModel {
6060

6161
this._disposables.add(this._cfgFilePath.onDidChange(_ => this._onDidUpdate.fire(this)));
6262
this._disposables.add(this._cfgSymbolPath.onDidChange(_ => this._onDidUpdate.fire(this)));
63+
this._workspaceService.onDidChangeWorkspaceFolders(this._onDidChangeWorkspaceFolders, this, this._disposables);
6364
this._fileInfo = this._initFilePathInfo(resource);
6465

6566
if (editor) {
@@ -146,6 +147,11 @@ export class BreadcrumbsModel {
146147
return info;
147148
}
148149

150+
private _onDidChangeWorkspaceFolders() {
151+
this._fileInfo = this._initFilePathInfo(this.resource);
152+
this._onDidUpdate.fire(this);
153+
}
154+
149155
private _bindToEditor(editor: IEditorPane): void {
150156
const newCts = new CancellationTokenSource();
151157
this._currentOutline.clear();

0 commit comments

Comments
 (0)