Skip to content

Commit dd54e6e

Browse files
committed
add setting to show/hide or show last part of file and symbol path, #9418
1 parent 733c5d2 commit dd54e6e

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

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

+31-7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export abstract class BreadcrumbsConfig<T> {
6767

6868
static IsEnabled = BreadcrumbsConfig._stub<boolean>('breadcrumbs.enabled');
6969
static UseQuickPick = BreadcrumbsConfig._stub<boolean>('breadcrumbs.useQuickPick');
70+
static FilePath = BreadcrumbsConfig._stub<'on' | 'off' | 'last'>('breadcrumbs.filePath');
71+
static SymbolPath = BreadcrumbsConfig._stub<'on' | 'off' | 'last'>('breadcrumbs.symbolPath');
7072

7173
private static _stub<T>(name: string): { bindTo(service: IConfigurationService): BreadcrumbsConfig<T> } {
7274
return {
@@ -102,15 +104,37 @@ Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfigurat
102104
type: 'object',
103105
properties: {
104106
'breadcrumbs.enabled': {
105-
'description': localize('enabled', "Enable/disable navigation breadcrumbs"),
106-
'type': 'boolean',
107-
'default': false
107+
description: localize('enabled', "Enable/disable navigation breadcrumbs"),
108+
type: 'boolean',
109+
default: false
108110
},
109111
'breadcrumbs.useQuickPick': {
110-
'description': localize('useQuickPick', "Use quick pick instead of seperate pickers."),
111-
'type': 'boolean',
112-
'default': false
113-
}
112+
description: localize('useQuickPick', "Use quick pick instead of seperate pickers."),
113+
type: 'boolean',
114+
default: false
115+
},
116+
'breadcrumbs.filePath': {
117+
description: localize('filepath', "Controls if and how file paths are shown in the breadcrumbs view."),
118+
type: 'string',
119+
default: 'on',
120+
enum: ['on', 'off', 'last'],
121+
enumDescriptions: [
122+
localize('filepath.on', "Show the file path in the breadcrumbs view."),
123+
localize('filepath.off', "Do not show the file path in the breadcrumbs view."),
124+
localize('filepath.last', "Only show the last element of the file path in the breadcrumbs view."),
125+
]
126+
},
127+
'breadcrumbs.symbolPath': {
128+
description: localize('symbolpath', "Controls if and how symbols are shown in the breadcrumbs view."),
129+
type: 'string',
130+
default: 'on',
131+
enum: ['on', 'off', 'last'],
132+
enumDescriptions: [
133+
localize('symbolpath.on', "Show all symbols the breadcrumbs view."),
134+
localize('symbolpath.off', "Do not show symbols in the breadcrumbs view."),
135+
localize('symbolpath.last', "Only show the current symbol in the breadcrumbs view."),
136+
]
137+
},
114138
}
115139
});
116140

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ export class BreadcrumbsControl {
145145
@IInstantiationService private readonly _instantiationService: IInstantiationService,
146146
@IThemeService private readonly _themeService: IThemeService,
147147
@IQuickOpenService private readonly _quickOpenService: IQuickOpenService,
148+
@IConfigurationService private readonly _configurationService: IConfigurationService,
148149
@IBreadcrumbsService breadcrumbsService: IBreadcrumbsService,
149-
@IConfigurationService configurationService: IConfigurationService,
150150
) {
151151
this.domNode = document.createElement('div');
152152
dom.addClasses(this.domNode, 'breadcrumbs-control');
@@ -161,7 +161,7 @@ export class BreadcrumbsControl {
161161
this._ckBreadcrumbsVisible = BreadcrumbsControl.CK_BreadcrumbsVisible.bindTo(this._contextKeyService);
162162
this._ckBreadcrumbsActive = BreadcrumbsControl.CK_BreadcrumbsActive.bindTo(this._contextKeyService);
163163

164-
this._cfUseQuickPick = BreadcrumbsConfig.UseQuickPick.bindTo(configurationService);
164+
this._cfUseQuickPick = BreadcrumbsConfig.UseQuickPick.bindTo(_configurationService);
165165

166166
this._disposables.push(breadcrumbsService.register(this._editorGroup.id, this._widget));
167167
}
@@ -209,7 +209,7 @@ export class BreadcrumbsControl {
209209
this._ckBreadcrumbsVisible.set(true);
210210

211211
let control = this._editorGroup.activeControl.getControl() as ICodeEditor;
212-
let model = new EditorBreadcrumbsModel(input.getResource(), isCodeEditor(control) ? control : undefined, this._workspaceService);
212+
let model = new EditorBreadcrumbsModel(input.getResource(), isCodeEditor(control) ? control : undefined, this._workspaceService, this._configurationService);
213213
dom.toggleClass(this.domNode, 'relative-path', model.isRelative());
214214

215215
let updateBreadcrumbs = () => {

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

+32-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { DocumentSymbolProviderRegistry } from 'vs/editor/common/modes';
2121
import { OutlineElement, OutlineGroup, OutlineModel } from 'vs/editor/contrib/documentSymbols/outlineModel';
2222
import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from 'vs/platform/workspace/common/workspace';
2323
import { Schemas } from 'vs/base/common/network';
24+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
25+
import { BreadcrumbsConfig } from 'vs/workbench/browser/parts/editor/breadcrumbs';
2426

2527
export class FileElement {
2628
constructor(
@@ -38,6 +40,9 @@ export class EditorBreadcrumbsModel {
3840
private readonly _disposables: IDisposable[] = [];
3941
private readonly _fileInfo: FileInfo;
4042

43+
private readonly _cfgFilePath: BreadcrumbsConfig<'on' | 'off' | 'last'>;
44+
private readonly _cfgSymbolPath: BreadcrumbsConfig<'on' | 'off' | 'last'>;
45+
4146
private _outlineElements: (OutlineGroup | OutlineElement)[] = [];
4247
private _outlineDisposables: IDisposable[] = [];
4348

@@ -48,13 +53,23 @@ export class EditorBreadcrumbsModel {
4853
private readonly _uri: URI,
4954
private readonly _editor: ICodeEditor | undefined,
5055
@IWorkspaceContextService workspaceService: IWorkspaceContextService,
56+
@IConfigurationService configurationService: IConfigurationService,
5157
) {
58+
59+
this._cfgFilePath = BreadcrumbsConfig.FilePath.bindTo(configurationService);
60+
this._cfgSymbolPath = BreadcrumbsConfig.SymbolPath.bindTo(configurationService);
61+
62+
this._disposables.push(this._cfgFilePath.onDidChange(_ => this._onDidUpdate.fire(this)));
63+
this._disposables.push(this._cfgSymbolPath.onDidChange(_ => this._onDidUpdate.fire(this)));
64+
5265
this._fileInfo = EditorBreadcrumbsModel._initFilePathInfo(this._uri, workspaceService);
5366
this._bindToEditor();
5467
this._onDidUpdate.fire(this);
5568
}
5669

5770
dispose(): void {
71+
this._cfgFilePath.dispose();
72+
this._cfgSymbolPath.dispose();
5873
dispose(this._disposables);
5974
}
6075

@@ -63,7 +78,23 @@ export class EditorBreadcrumbsModel {
6378
}
6479

6580
getElements(): ReadonlyArray<BreadcrumbElement> {
66-
return [].concat(this._fileInfo.path, this._outlineElements);
81+
let result: BreadcrumbElement[] = [];
82+
83+
// file path elements
84+
if (this._cfgFilePath.value === 'on') {
85+
result = result.concat(this._fileInfo.path);
86+
} else if (this._cfgFilePath.value === 'last' && this._fileInfo.path.length > 0) {
87+
result = result.concat(this._fileInfo.path.slice(-1));
88+
}
89+
90+
// symbol path elements
91+
if (this._cfgSymbolPath.value === 'on') {
92+
result = result.concat(this._outlineElements);
93+
} else if (this._cfgSymbolPath.value === 'last' && this._outlineElements.length > 0) {
94+
result = result.concat(this._outlineElements.slice(-1));
95+
}
96+
97+
return result;
6798
}
6899

69100
private static _initFilePathInfo(uri: URI, workspaceService: IWorkspaceContextService): FileInfo {

0 commit comments

Comments
 (0)