Skip to content

Commit

Permalink
add setting to show/hide or show last part of file and symbol path, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jul 16, 2018
1 parent 733c5d2 commit dd54e6e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
38 changes: 31 additions & 7 deletions src/vs/workbench/browser/parts/editor/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export abstract class BreadcrumbsConfig<T> {

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

private static _stub<T>(name: string): { bindTo(service: IConfigurationService): BreadcrumbsConfig<T> } {
return {
Expand Down Expand Up @@ -102,15 +104,37 @@ Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfigurat
type: 'object',
properties: {
'breadcrumbs.enabled': {
'description': localize('enabled', "Enable/disable navigation breadcrumbs"),
'type': 'boolean',
'default': false
description: localize('enabled', "Enable/disable navigation breadcrumbs"),
type: 'boolean',
default: false
},
'breadcrumbs.useQuickPick': {
'description': localize('useQuickPick', "Use quick pick instead of seperate pickers."),
'type': 'boolean',
'default': false
}
description: localize('useQuickPick', "Use quick pick instead of seperate pickers."),

This comment has been minimized.

Copy link
@KamasamaK

KamasamaK Jul 16, 2018

@jrieken Misspelling of "separate" here.

This comment has been minimized.

Copy link
@jrieken

jrieken Jul 16, 2018

Author Member

thx

type: 'boolean',
default: false
},
'breadcrumbs.filePath': {
description: localize('filepath', "Controls if and how file paths are shown in the breadcrumbs view."),
type: 'string',
default: 'on',
enum: ['on', 'off', 'last'],
enumDescriptions: [
localize('filepath.on', "Show the file path in the breadcrumbs view."),
localize('filepath.off', "Do not show the file path in the breadcrumbs view."),
localize('filepath.last', "Only show the last element of the file path in the breadcrumbs view."),
]
},
'breadcrumbs.symbolPath': {
description: localize('symbolpath', "Controls if and how symbols are shown in the breadcrumbs view."),
type: 'string',
default: 'on',
enum: ['on', 'off', 'last'],
enumDescriptions: [
localize('symbolpath.on', "Show all symbols the breadcrumbs view."),
localize('symbolpath.off', "Do not show symbols in the breadcrumbs view."),
localize('symbolpath.last', "Only show the current symbol in the breadcrumbs view."),
]
},
}
});

Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export class BreadcrumbsControl {
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IThemeService private readonly _themeService: IThemeService,
@IQuickOpenService private readonly _quickOpenService: IQuickOpenService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IBreadcrumbsService breadcrumbsService: IBreadcrumbsService,
@IConfigurationService configurationService: IConfigurationService,
) {
this.domNode = document.createElement('div');
dom.addClasses(this.domNode, 'breadcrumbs-control');
Expand All @@ -161,7 +161,7 @@ export class BreadcrumbsControl {
this._ckBreadcrumbsVisible = BreadcrumbsControl.CK_BreadcrumbsVisible.bindTo(this._contextKeyService);
this._ckBreadcrumbsActive = BreadcrumbsControl.CK_BreadcrumbsActive.bindTo(this._contextKeyService);

this._cfUseQuickPick = BreadcrumbsConfig.UseQuickPick.bindTo(configurationService);
this._cfUseQuickPick = BreadcrumbsConfig.UseQuickPick.bindTo(_configurationService);

this._disposables.push(breadcrumbsService.register(this._editorGroup.id, this._widget));
}
Expand Down Expand Up @@ -209,7 +209,7 @@ export class BreadcrumbsControl {
this._ckBreadcrumbsVisible.set(true);

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

let updateBreadcrumbs = () => {
Expand Down
33 changes: 32 additions & 1 deletion src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { DocumentSymbolProviderRegistry } from 'vs/editor/common/modes';
import { OutlineElement, OutlineGroup, OutlineModel } from 'vs/editor/contrib/documentSymbols/outlineModel';
import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { Schemas } from 'vs/base/common/network';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { BreadcrumbsConfig } from 'vs/workbench/browser/parts/editor/breadcrumbs';

export class FileElement {
constructor(
Expand All @@ -38,6 +40,9 @@ export class EditorBreadcrumbsModel {
private readonly _disposables: IDisposable[] = [];
private readonly _fileInfo: FileInfo;

private readonly _cfgFilePath: BreadcrumbsConfig<'on' | 'off' | 'last'>;
private readonly _cfgSymbolPath: BreadcrumbsConfig<'on' | 'off' | 'last'>;

private _outlineElements: (OutlineGroup | OutlineElement)[] = [];
private _outlineDisposables: IDisposable[] = [];

Expand All @@ -48,13 +53,23 @@ export class EditorBreadcrumbsModel {
private readonly _uri: URI,
private readonly _editor: ICodeEditor | undefined,
@IWorkspaceContextService workspaceService: IWorkspaceContextService,
@IConfigurationService configurationService: IConfigurationService,
) {

this._cfgFilePath = BreadcrumbsConfig.FilePath.bindTo(configurationService);
this._cfgSymbolPath = BreadcrumbsConfig.SymbolPath.bindTo(configurationService);

this._disposables.push(this._cfgFilePath.onDidChange(_ => this._onDidUpdate.fire(this)));
this._disposables.push(this._cfgSymbolPath.onDidChange(_ => this._onDidUpdate.fire(this)));

this._fileInfo = EditorBreadcrumbsModel._initFilePathInfo(this._uri, workspaceService);
this._bindToEditor();
this._onDidUpdate.fire(this);
}

dispose(): void {
this._cfgFilePath.dispose();
this._cfgSymbolPath.dispose();
dispose(this._disposables);
}

Expand All @@ -63,7 +78,23 @@ export class EditorBreadcrumbsModel {
}

getElements(): ReadonlyArray<BreadcrumbElement> {
return [].concat(this._fileInfo.path, this._outlineElements);
let result: BreadcrumbElement[] = [];

// file path elements
if (this._cfgFilePath.value === 'on') {
result = result.concat(this._fileInfo.path);
} else if (this._cfgFilePath.value === 'last' && this._fileInfo.path.length > 0) {
result = result.concat(this._fileInfo.path.slice(-1));
}

// symbol path elements
if (this._cfgSymbolPath.value === 'on') {
result = result.concat(this._outlineElements);
} else if (this._cfgSymbolPath.value === 'last' && this._outlineElements.length > 0) {
result = result.concat(this._outlineElements.slice(-1));
}

return result;
}

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

0 comments on commit dd54e6e

Please sign in to comment.