add scm sort to storage

add scm default sort setting
This commit is contained in:
Nick Rayburn 2021-05-06 22:27:25 -05:00
parent f6996f9962
commit 1ce9fe281e
2 changed files with 38 additions and 3 deletions

View file

@ -183,6 +183,17 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
description: localize('scm.defaultViewMode', "Controls the default Source Control repository view mode."),
default: 'list'
},
'scm.defaultViewSortKey': {
type: 'string',
enum: ['path', 'name', 'status'],
enumDescriptions: [
localize('scm.defaultViewSortKey.path', "Sort the repository changes by path."),
localize('scm.defaultViewSortKey.name', "Sort the repository changes by file name."),
localize('scm.defaultViewSortKey.status', "Sort the reposiory changes by scm status.")
],
description: localize('scm.defaultViewSortKey', "Controls the default Source Control repository sort mode."),
default: 'path'
},
'scm.autoReveal': {
type: 'boolean',
description: localize('autoReveal', "Controls whether the SCM view should automatically reveal and select files when opening them."),

View file

@ -925,6 +925,9 @@ class ViewModel {
private readonly _onDidChangeMode = new Emitter<ViewModelMode>();
readonly onDidChangeMode = this._onDidChangeMode.event;
private readonly _onDidChangeSortKey = new Emitter<ViewModelSortKey>();
readonly onDidChangeSortKey = this._onDidChangeSortKey.event;
private visible: boolean = false;
get mode(): ViewModelMode { return this._mode; }
@ -952,12 +955,12 @@ class ViewModel {
this.modeContextKey.set(mode);
}
private _sortKey: ViewModelSortKey = ViewModelSortKey.Path;
get sortKey(): ViewModelSortKey { return this._sortKey; }
set sortKey(sortKey: ViewModelSortKey) {
if (sortKey !== this._sortKey) {
this._sortKey = sortKey;
this.refresh();
this._onDidChangeSortKey.fire(sortKey);
}
this.sortKeyContextKey.set(sortKey);
}
@ -991,6 +994,7 @@ class ViewModel {
private tree: WorkbenchCompressibleObjectTree<TreeElement, FuzzyScore>,
private inputRenderer: InputRenderer,
private _mode: ViewModelMode,
private _sortKey: ViewModelSortKey,
private _treeViewState: ITreeViewState | undefined,
@IInstantiationService protected instantiationService: IInstantiationService,
@IEditorService protected editorService: IEditorService,
@ -1002,7 +1006,7 @@ class ViewModel {
this.modeContextKey = ContextKeys.ViewModelMode.bindTo(contextKeyService);
this.modeContextKey.set(_mode);
this.sortKeyContextKey = ContextKeys.ViewModelSortKey.bindTo(contextKeyService);
this.sortKeyContextKey.set(this._sortKey);
this.sortKeyContextKey.set(_sortKey);
this.areAllRepositoriesCollapsedContextKey = ContextKeys.ViewModelAreAllRepositoriesCollapsed.bindTo(contextKeyService);
this.isAnyRepositoryCollapsibleContextKey = ContextKeys.ViewModelIsAnyRepositoryCollapsible.bindTo(contextKeyService);
this.scmProviderContextKey = ContextKeys.SCMProvider.bindTo(contextKeyService);
@ -1949,6 +1953,21 @@ export class SCMViewPane extends ViewPane {
viewMode = storageMode;
}
let viewSortKey: ViewModelSortKey;
let viewSortKeyString = this.configurationService.getValue<'path' | 'name' | 'status'>('scm.defaultViewSortKey');
if (viewSortKeyString === 'name') {
viewSortKey = ViewModelSortKey.Name;
} else if (viewSortKeyString === 'status') {
viewSortKey = ViewModelSortKey.Status;
} else {
viewSortKey = ViewModelSortKey.Path;
}
const storageSortKey = this.storageService.get(`scm.viewSortKey`, StorageScope.WORKSPACE) as ViewModelSortKey;
if (typeof storageSortKey === 'string') {
viewSortKey = storageSortKey;
}
let viewState: ITreeViewState | undefined;
const storageViewState = this.storageService.get(`scm.viewState`, StorageScope.WORKSPACE);
@ -1960,7 +1979,7 @@ export class SCMViewPane extends ViewPane {
this._register(this.instantiationService.createInstance(RepositoryVisibilityActionController));
this._viewModel = this.instantiationService.createInstance(ViewModel, this.tree, this.inputRenderer, viewMode, viewState);
this._viewModel = this.instantiationService.createInstance(ViewModel, this.tree, this.inputRenderer, viewMode, viewSortKey, viewState);
this._register(this._viewModel);
this.listContainer.classList.add('file-icon-themable-tree');
@ -1969,6 +1988,7 @@ export class SCMViewPane extends ViewPane {
this.updateIndentStyles(this.themeService.getFileIconTheme());
this._register(this.themeService.onDidFileIconThemeChange(this.updateIndentStyles, this));
this._register(this._viewModel.onDidChangeMode(this.onDidChangeMode, this));
this._register(this._viewModel.onDidChangeSortKey(this.onDidChangeSortKey, this));
this._register(this.onDidChangeBodyVisibility(this._viewModel.setVisible, this._viewModel));
@ -1994,6 +2014,10 @@ export class SCMViewPane extends ViewPane {
this.storageService.store(`scm.viewMode`, this._viewModel.mode, StorageScope.WORKSPACE, StorageTarget.USER);
}
private onDidChangeSortKey(): void {
this.storageService.store(`scm.viewSortKey`, this._viewModel.sortKey, StorageScope.WORKSPACE, StorageTarget.USER);
}
override layoutBody(height: number | undefined = this.layoutCache.height, width: number | undefined = this.layoutCache.width): void {
if (height === undefined) {
return;