Skip to content

Commit 304b0ab

Browse files
committed
Settings editor as tree - hook up "show configured only" checkbox
1 parent c7ee0f8 commit 304b0ab

2 files changed

Lines changed: 125 additions & 109 deletions

File tree

src/vs/workbench/parts/preferences/browser/settingsEditor2.ts

Lines changed: 17 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as arrays from 'vs/base/common/arrays';
1010
import { Delayer, ThrottledDelayer } from 'vs/base/common/async';
1111
import { Color } from 'vs/base/common/color';
1212
import { getErrorMessage, isPromiseCanceledError } from 'vs/base/common/errors';
13-
import * as objects from 'vs/base/common/objects';
1413
import { TPromise } from 'vs/base/common/winjs.base';
1514
import 'vs/css!./media/settingsEditor2';
1615
import { localize } from 'vs/nls';
@@ -33,13 +32,7 @@ import { SettingsEditor2Input } from 'vs/workbench/services/preferences/common/p
3332
import { DefaultSettingsEditorModel } from 'vs/workbench/services/preferences/common/preferencesModels';
3433
import { IPreferencesSearchService, ISearchProvider } from 'vs/workbench/parts/preferences/common/preferences';
3534
import { KeyCode } from 'vs/base/common/keyCodes';
36-
import { SettingsRenderer, SettingsDataSource, SettingsTreeController, SettingsAccessibilityProvider, TreeElement, TreeItemType, ISettingsEditorViewState } from 'vs/workbench/parts/preferences/browser/settingsTree';
37-
38-
39-
enum SearchResultIdx {
40-
Local = 0,
41-
Remote = 1
42-
}
35+
import { SettingsRenderer, SettingsDataSource, SettingsTreeController, SettingsAccessibilityProvider, TreeElement, TreeItemType, ISettingsEditorViewState, SearchResultModel, SearchResultIdx, SettingsTreeFilter } from 'vs/workbench/parts/preferences/browser/settingsTree';
4336

4437
const $ = DOM.$;
4538

@@ -75,11 +68,7 @@ export class SettingsEditor2 extends BaseEditor {
7568
private focusedElement: TreeElement;
7669

7770
private viewState: ISettingsEditorViewState;
78-
// <TODO@roblou> factor out tree/list viewmodel to somewhere outside this class
7971
private searchResultModel: SearchResultModel;
80-
private showConfiguredSettingsOnly = false;
81-
private inRender = false;
82-
// </TODO>
8372

8473
constructor(
8574
@ITelemetryService telemetryService: ITelemetryService,
@@ -96,7 +85,6 @@ export class SettingsEditor2 extends BaseEditor {
9685
this.delayedFilterLogging = new Delayer<void>(1000);
9786
this.localSearchDelayer = new Delayer(100);
9887
this.remoteSearchThrottle = new ThrottledDelayer(200);
99-
this.searchResultModel = new SearchResultModel();
10088
this.viewState = { settingsTarget: ConfigurationTarget.USER };
10189

10290
this._register(configurationService.onDidChangeConfiguration(() => this.settingsTree.refresh()));
@@ -128,7 +116,6 @@ export class SettingsEditor2 extends BaseEditor {
128116
this.searchWidget.layout(dimension);
129117

130118
this.layoutSettingsList();
131-
this.render();
132119
}
133120

134121
focus(): void {
@@ -240,6 +227,7 @@ export class SettingsEditor2 extends BaseEditor {
240227
renderer: renderer,
241228
controller: this.instantiationService.createInstance(SettingsTreeController),
242229
accessibilityProvider: this.instantiationService.createInstance(SettingsAccessibilityProvider),
230+
filter: this.instantiationService.createInstance(SettingsTreeFilter, this.viewState)
243231
},
244232
{
245233
ariaLabel: localize('treeAriaLabel', "Settings"),
@@ -276,8 +264,8 @@ export class SettingsEditor2 extends BaseEditor {
276264
}
277265

278266
private onShowConfiguredOnlyClicked(): void {
279-
this.showConfiguredSettingsOnly = this.showConfiguredSettingsOnlyCheckbox.checked;
280-
this.render();
267+
this.viewState.showConfiguredOnly = this.showConfiguredSettingsOnlyCheckbox.checked;
268+
this.refreshTree();
281269
}
282270

283271
private onDidChangeSetting(key: string, value: any): void {
@@ -291,7 +279,7 @@ export class SettingsEditor2 extends BaseEditor {
291279
query: this.searchWidget.getValue(),
292280
searchResults: this.searchResultModel && this.searchResultModel.getUniqueResults(),
293281
rawResults: this.searchResultModel && this.searchResultModel.getRawResults(),
294-
showConfiguredOnly: this.showConfiguredSettingsOnly,
282+
showConfiguredOnly: this.viewState.showConfiguredOnly,
295283
isReset: typeof value === 'undefined',
296284
settingsTarget: this.settingsTargetsWidget.settingsTarget as SettingsTarget
297285
};
@@ -380,6 +368,10 @@ export class SettingsEditor2 extends BaseEditor {
380368
return TPromise.as(null);
381369
}
382370

371+
private refreshTree(): TPromise<any> {
372+
return this.settingsTree.refresh();
373+
}
374+
383375
private onSearchInputChanged(): void {
384376
const query = this.searchWidget.getValue().trim();
385377
this.delayedFilterLogging.cancel();
@@ -395,9 +387,7 @@ export class SettingsEditor2 extends BaseEditor {
395387
return TPromise.join([
396388
this.localSearchDelayer.trigger(() => this.localFilterPreferences(query)),
397389
this.remoteSearchThrottle.trigger(() => this.remoteSearchPreferences(query), 500)
398-
]).then(() => {
399-
this.settingsTree.setInput(this.searchResultModel.resultsAsGroup());
400-
});
390+
]) as TPromise;
401391
} else {
402392
// When clearing the input, update immediately to clear it
403393
this.localSearchDelayer.cancel();
@@ -413,7 +403,7 @@ export class SettingsEditor2 extends BaseEditor {
413403

414404
private expandCommonlyUsedSettings(): void {
415405
const commonlyUsedGroup = this.defaultSettingsEditorModel.settingsGroups[0];
416-
this.settingsTree.expand(this.treeDataSource.getGroupElement(commonlyUsedGroup));
406+
this.settingsTree.expand(this.treeDataSource.getGroupElement(commonlyUsedGroup, 0));
417407
}
418408

419409
private reportFilteringUsed(query: string, results: ISearchResult[]): void {
@@ -467,8 +457,13 @@ export class SettingsEditor2 extends BaseEditor {
467457

468458
return TPromise.join(filterPs).then(results => {
469459
const [result] = results;
460+
if (!this.searchResultModel) {
461+
this.searchResultModel = new SearchResultModel();
462+
this.settingsTree.setInput(this.searchResultModel);
463+
}
464+
470465
this.searchResultModel.setResult(type, result);
471-
return this.render();
466+
return this.refreshTree();
472467
});
473468
}
474469

@@ -556,63 +551,3 @@ function setTabindexes(element: HTMLElement, tabIndex: number): void {
556551
// measureContainer.removeChild(measureHelper);
557552
// return height;
558553
// }
559-
560-
561-
class SearchResultModel {
562-
private rawSearchResults: ISearchResult[];
563-
private cachedUniqueSearchResults: ISearchResult[];
564-
565-
getUniqueResults(): ISearchResult[] {
566-
if (this.cachedUniqueSearchResults) {
567-
return this.cachedUniqueSearchResults;
568-
}
569-
570-
if (!this.rawSearchResults) {
571-
return null;
572-
}
573-
574-
const localMatchKeys = new Set();
575-
const localResult = objects.deepClone(this.rawSearchResults[SearchResultIdx.Local]);
576-
if (localResult) {
577-
localResult.filterMatches.forEach(m => localMatchKeys.add(m.setting.key));
578-
}
579-
580-
const remoteResult = objects.deepClone(this.rawSearchResults[SearchResultIdx.Remote]);
581-
if (remoteResult) {
582-
remoteResult.filterMatches = remoteResult.filterMatches.filter(m => !localMatchKeys.has(m.setting.key));
583-
}
584-
585-
this.cachedUniqueSearchResults = [localResult, remoteResult];
586-
return this.cachedUniqueSearchResults;
587-
}
588-
589-
getRawResults(): ISearchResult[] {
590-
return this.rawSearchResults;
591-
}
592-
593-
setResult(type: SearchResultIdx, result: ISearchResult): void {
594-
this.cachedUniqueSearchResults = null;
595-
this.rawSearchResults = this.rawSearchResults || [];
596-
this.rawSearchResults[type] = result;
597-
}
598-
599-
resultsAsGroup(): ISettingsGroup {
600-
const flatSettings: ISetting[] = [];
601-
this.getUniqueResults()
602-
.filter(r => !!r)
603-
.forEach(r => {
604-
flatSettings.push(
605-
...r.filterMatches.map(m => m.setting));
606-
});
607-
608-
return <ISettingsGroup>{
609-
id: 'settingsSearchResultGroup',
610-
range: null,
611-
sections: [
612-
{ settings: flatSettings }
613-
],
614-
title: 'searchResults',
615-
titleRange: null
616-
};
617-
}
618-
}

0 commit comments

Comments
 (0)