mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Settings editor - remove some 'modified' handling code, use 'tags'
This commit is contained in:
parent
5b3e00e68f
commit
7e421ef110
|
@ -32,7 +32,7 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
|
|||
import { EditorOptions, IEditor } from 'vs/workbench/common/editor';
|
||||
import { SearchWidget, SettingsTarget, SettingsTargetsWidget } from 'vs/workbench/parts/preferences/browser/preferencesWidgets';
|
||||
import { commonlyUsedData, tocData } from 'vs/workbench/parts/preferences/browser/settingsLayout';
|
||||
import { ISettingsEditorViewState, resolveExtensionsSettings, resolveSettingsTree, SearchResultIdx, SearchResultModel, SettingsRenderer, SettingsTree, SettingsTreeElement, SettingsTreeFilter, SettingsTreeGroupElement, SettingsTreeModel, SettingsTreeSettingElement } from 'vs/workbench/parts/preferences/browser/settingsTree';
|
||||
import { ISettingsEditorViewState, resolveExtensionsSettings, resolveSettingsTree, SearchResultIdx, SearchResultModel, SettingsRenderer, SettingsTree, SettingsTreeElement, SettingsTreeFilter, SettingsTreeGroupElement, SettingsTreeModel, SettingsTreeSettingElement, MODIFIED_SETTING_TAG } from 'vs/workbench/parts/preferences/browser/settingsTree';
|
||||
import { TOCDataSource, TOCRenderer, TOCTreeModel } from 'vs/workbench/parts/preferences/browser/tocTree';
|
||||
import { CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_FIRST_ROW_FOCUS, CONTEXT_SETTINGS_ROW_FOCUS, CONTEXT_SETTINGS_SEARCH_FOCUS, CONTEXT_TOC_ROW_FOCUS, IPreferencesSearchService, ISearchProvider } from 'vs/workbench/parts/preferences/common/preferences';
|
||||
import { IPreferencesService, ISearchResult, ISettingsEditorModel } from 'vs/workbench/services/preferences/common/preferences';
|
||||
|
@ -223,10 +223,14 @@ export class SettingsEditor2 extends BaseEditor {
|
|||
});
|
||||
|
||||
const actions = [
|
||||
this.instantiationService.createInstance(ToggleShowModifiedOnlyAction, this, this.viewState),
|
||||
this.instantiationService.createInstance(ToggleFilterByTagAction,
|
||||
localize('filterModifiedLabel', "Show modified settings only"),
|
||||
MODIFIED_SETTING_TAG,
|
||||
this,
|
||||
this.viewState),
|
||||
this.instantiationService.createInstance(
|
||||
ToggleFilterByTagAction,
|
||||
localize('filterBackgroundOnlineLabel', "Show background online settings only"),
|
||||
localize('filterBackgroundOnlineLabel', "Control background online features"),
|
||||
'backgroundOnlineFeature',
|
||||
this,
|
||||
this.viewState),
|
||||
|
@ -405,22 +409,11 @@ export class SettingsEditor2 extends BaseEditor {
|
|||
}));
|
||||
}
|
||||
|
||||
toggleShowModifiedOnly(): TPromise<void> {
|
||||
this.viewState.showConfiguredOnly = !this.viewState.showConfiguredOnly;
|
||||
DOM.toggleClass(this.rootElement, 'showing-modified-only', this.viewState.showConfiguredOnly);
|
||||
return this.refreshTreeAndMaintainFocus().then(() => {
|
||||
this.settingsTree.setScrollPosition(0);
|
||||
this.expandAll(this.settingsTree);
|
||||
});
|
||||
}
|
||||
|
||||
toggleFilterByTag(tag: string): TPromise<void> {
|
||||
// Clear other filters
|
||||
this.viewState.showConfiguredOnly = false;
|
||||
|
||||
this.viewState.tagFilters = this.viewState.tagFilters || new Set<string>();
|
||||
const wasFiltered = this.viewState.tagFilters.delete(tag);
|
||||
// Reset other tags, toggle this tag
|
||||
const wasFiltered = this.viewState.tagFilters && this.viewState.tagFilters.has(tag);
|
||||
const isFiltered = !wasFiltered;
|
||||
this.viewState.tagFilters = new Set<string>();
|
||||
if (isFiltered) {
|
||||
this.viewState.tagFilters.add(tag);
|
||||
}
|
||||
|
@ -498,7 +491,7 @@ export class SettingsEditor2 extends BaseEditor {
|
|||
query: this.searchWidget.getValue(),
|
||||
searchResults: this.searchResultModel && this.searchResultModel.getUniqueResults(),
|
||||
rawResults: this.searchResultModel && this.searchResultModel.getRawResults(),
|
||||
showConfiguredOnly: this.viewState.showConfiguredOnly,
|
||||
showConfiguredOnly: this.viewState.tagFilters && this.viewState.tagFilters.has(MODIFIED_SETTING_TAG),
|
||||
isReset: typeof value === 'undefined',
|
||||
settingsTarget: this.settingsTargetsWidget.settingsTarget as SettingsTarget
|
||||
};
|
||||
|
@ -851,26 +844,6 @@ class OpenSettingsAction extends Action {
|
|||
}
|
||||
}
|
||||
|
||||
class ToggleShowModifiedOnlyAction extends Action {
|
||||
static readonly ID = 'settings.toggleShowModifiedOnly';
|
||||
static readonly LABEL = localize('showModifiedOnlyLabel', "Show modified settings only");
|
||||
|
||||
get checked(): boolean {
|
||||
return this.viewState.showConfiguredOnly;
|
||||
}
|
||||
|
||||
constructor(
|
||||
private settingsEditor: SettingsEditor2,
|
||||
private viewState: ISettingsEditorViewState
|
||||
) {
|
||||
super(ToggleShowModifiedOnlyAction.ID, ToggleShowModifiedOnlyAction.LABEL, 'show-modified-only');
|
||||
}
|
||||
|
||||
run(): TPromise<void> {
|
||||
return this.settingsEditor.toggleShowModifiedOnly();
|
||||
}
|
||||
}
|
||||
|
||||
class ToggleFilterByTagAction extends Action {
|
||||
static readonly ID = 'settings.toggleFilterByTag';
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ import { ISearchResult, ISetting, ISettingsGroup } from 'vs/workbench/services/p
|
|||
|
||||
const $ = DOM.$;
|
||||
|
||||
export const MODIFIED_SETTING_TAG = 'modified';
|
||||
|
||||
export abstract class SettingsTreeElement {
|
||||
id: string;
|
||||
parent: any; // SearchResultModel or group element... TODO search should be more similar to the normal case
|
||||
|
@ -78,6 +80,7 @@ export class SettingsTreeSettingElement extends SettingsTreeElement {
|
|||
*/
|
||||
isConfigured: boolean;
|
||||
|
||||
tags?: Set<string>;
|
||||
overriddenScopeList: string[];
|
||||
description: string;
|
||||
valueType: 'enum' | 'string' | 'integer' | 'number' | 'boolean' | 'exclude' | 'complex';
|
||||
|
@ -191,6 +194,17 @@ function createSettingsTreeSettingElement(setting: ISetting, parent: any, settin
|
|||
element.defaultValue = inspected.default;
|
||||
|
||||
element.isConfigured = isConfigured;
|
||||
if (isConfigured || setting.tags) {
|
||||
element.tags = new Set<string>();
|
||||
if (isConfigured) {
|
||||
element.tags.add(MODIFIED_SETTING_TAG);
|
||||
}
|
||||
|
||||
if (setting.tags) {
|
||||
setting.tags.forEach(tag => element.tags.add(tag));
|
||||
}
|
||||
}
|
||||
|
||||
element.overriddenScopeList = overriddenScopeList;
|
||||
element.description = setting.description.join('\n');
|
||||
|
||||
|
@ -436,7 +450,6 @@ function trimCategoryForGroup(category: string, groupId: string): string {
|
|||
|
||||
export interface ISettingsEditorViewState {
|
||||
settingsTarget: SettingsTarget;
|
||||
showConfiguredOnly?: boolean;
|
||||
tagFilters?: Set<string>;
|
||||
filterToCategory?: SettingsTreeGroupElement;
|
||||
}
|
||||
|
@ -1107,17 +1120,15 @@ export class SettingsTreeFilter implements IFilter {
|
|||
}
|
||||
}
|
||||
|
||||
if (element instanceof SettingsTreeSettingElement && this.viewState.showConfiguredOnly) {
|
||||
return element.isConfigured;
|
||||
}
|
||||
|
||||
if (element instanceof SettingsTreeGroupElement && this.viewState.showConfiguredOnly) {
|
||||
return this.groupHasConfiguredSetting(element);
|
||||
}
|
||||
|
||||
if (element instanceof SettingsTreeSettingElement && this.viewState.tagFilters && this.viewState.tagFilters.size) {
|
||||
if (element.setting.tags) {
|
||||
return element.setting.tags.some(tag => this.viewState.tagFilters.has(tag));
|
||||
if (element.tags) {
|
||||
let hasFilteredTag = false;
|
||||
element.tags.forEach(tag => {
|
||||
if (this.viewState.tagFilters.has(tag)) {
|
||||
hasFilteredTag = true;
|
||||
}
|
||||
});
|
||||
return hasFilteredTag;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -1141,22 +1152,6 @@ export class SettingsTreeFilter implements IFilter {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private groupHasConfiguredSetting(element: SettingsTreeGroupElement): boolean {
|
||||
for (let child of element.children) {
|
||||
if (child instanceof SettingsTreeSettingElement) {
|
||||
if (child.isConfigured) {
|
||||
return true;
|
||||
}
|
||||
} else if (child instanceof SettingsTreeGroupElement) {
|
||||
if (this.groupHasConfiguredSetting(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export class SettingsTreeController extends WorkbenchTreeController {
|
||||
|
|
Loading…
Reference in a new issue