Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update breadcrumbs when workspace folders update #154616

Merged
merged 1 commit into from Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/vs/workbench/browser/labels.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -382,6 +399,7 @@ class ResourceLabelWidget extends IconLabel {
const workspaceFolder = this.contextService.getWorkspaceFolder(resource);
if (workspaceFolder) {
name = workspaceFolder.name;
this.computedWorkspaceFolderLabel = name;
}
}

Expand Down Expand Up @@ -602,5 +620,6 @@ class ResourceLabelWidget extends IconLabel {
this.computedLanguageId = undefined;
this.computedIconClasses = undefined;
this.computedPathLabel = undefined;
this.computedWorkspaceFolderLabel = undefined;
}
}
Expand Up @@ -280,10 +280,10 @@ export class BreadcrumbsControl {
this._editorGroup.activeEditorPane
);

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

const updateBreadcrumbs = () => {
this.domNode.classList.toggle('relative-path', model.isRelative());
const showIcons = this._cfShowIcons.getValue();
const options: IBreadcrumbsControlOptions = {
...this._options,
Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts
Expand Up @@ -37,7 +37,7 @@ export class OutlineElement2 {
export class BreadcrumbsModel {

private readonly _disposables = new DisposableStore();
private readonly _fileInfo: FileInfo;
private _fileInfo: FileInfo;

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

this._disposables.add(this._cfgFilePath.onDidChange(_ => this._onDidUpdate.fire(this)));
this._disposables.add(this._cfgSymbolPath.onDidChange(_ => this._onDidUpdate.fire(this)));
this._workspaceService.onDidChangeWorkspaceFolders(this._onDidChangeWorkspaceFolders, this, this._disposables);
this._fileInfo = this._initFilePathInfo(resource);

if (editor) {
Expand Down Expand Up @@ -146,6 +147,11 @@ export class BreadcrumbsModel {
return info;
}

private _onDidChangeWorkspaceFolders() {
this._fileInfo = this._initFilePathInfo(this.resource);
this._onDidUpdate.fire(this);
}

private _bindToEditor(editor: IEditorPane): void {
const newCts = new CancellationTokenSource();
this._currentOutline.clear();
Expand Down