preferencesEditor.ts 58.3 KB
Newer Older
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { TPromise } from 'vs/base/common/winjs.base';
import * as nls from 'vs/nls';
import URI from 'vs/base/common/uri';
S
Sandeep Somavarapu 已提交
9
import * as DOM from 'vs/base/browser/dom';
10
import { Delayer } from 'vs/base/common/async';
S
Sandeep Somavarapu 已提交
11
import { Dimension, Builder } from 'vs/base/browser/builder';
S
Sandeep Somavarapu 已提交
12
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
13 14
import { flatten, distinct } from 'vs/base/common/arrays';
import { ArrayNavigator, IIterator } from 'vs/base/common/iterator';
S
Sandeep Somavarapu 已提交
15 16
import { IAction } from 'vs/base/common/actions';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
17
import Event, { Emitter } from 'vs/base/common/event';
18 19
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor';
S
Sandeep Somavarapu 已提交
20
import { Registry } from 'vs/platform/platform';
21 22
import { toResource, SideBySideEditorInput, EditorOptions, EditorInput, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/common/editor';
import { BaseEditor, EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor';
23
import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel';
24
import { IEditorControl, IEditor } from 'vs/platform/editor/common/editor';
25
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
S
Sandeep Somavarapu 已提交
26 27
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import * as editorCommon from 'vs/editor/common/editorCommon';
S
Sandeep Somavarapu 已提交
28
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
S
Sandeep Somavarapu 已提交
29
import { CodeEditor } from 'vs/editor/browser/codeEditor';
S
Sandeep Somavarapu 已提交
30
import { Range } from 'vs/editor/common/core/range';
31
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
S
Sandeep Somavarapu 已提交
32
import {
S
Sandeep Somavarapu 已提交
33
	IPreferencesService, ISettingsGroup, ISetting, IPreferencesEditorModel, IFilterResult, CONTEXT_DEFAULT_SETTINGS_EDITOR,
S
Sandeep Somavarapu 已提交
34
	DEFAULT_EDITOR_COMMAND_COLLAPSE_ALL, DEFAULT_EDITOR_COMMAND_FOCUS_SEARCH, ISettingsEditorModel
S
Sandeep Somavarapu 已提交
35
} from 'vs/workbench/parts/preferences/common/preferences';
36
import { SettingsEditorModel, DefaultSettingsEditorModel } from 'vs/workbench/parts/preferences/common/preferencesModels';
S
Sandeep Somavarapu 已提交
37
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
S
Sandeep Somavarapu 已提交
38
import { ICodeEditor, IEditorMouseEvent, IEditorContributionCtor } from 'vs/editor/browser/editorBrowser';
39
import { IContextMenuService, ContextSubMenu } from 'vs/platform/contextview/browser/contextView';
40
import { SearchWidget, SettingsTabsWidget, SettingsGroupTitleWidget, EditPreferenceWidget } from 'vs/workbench/parts/preferences/browser/preferencesWidgets';
S
Sandeep Somavarapu 已提交
41
import { IContextKeyService, IContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
42
import { CommonEditorRegistry, EditorCommand, Command } from 'vs/editor/common/editorCommonExtensions';
S
Sandeep Somavarapu 已提交
43 44 45 46
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
S
Sandeep Somavarapu 已提交
47 48
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
49
import { IMessageService, Severity } from 'vs/platform/message/common/message';
S
Sandeep Somavarapu 已提交
50 51
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
52
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
53
import { RangeHighlightDecorations } from 'vs/workbench/common/editor/rangeDecorations';
54 55 56 57
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { VSash } from 'vs/base/browser/ui/sash/sash';
import { Widget } from 'vs/base/browser/ui/widget';
58
import { overrideIdentifierFromKey } from 'vs/platform/configuration/common/model';
59 60
import { IMarkerService, IMarkerData } from 'vs/platform/markers/common/markers';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
61 62

// Ignore following contributions
S
Sandeep Somavarapu 已提交
63
import { FoldingController } from 'vs/editor/contrib/folding/browser/folding';
S
Sandeep Somavarapu 已提交
64 65
import { FindController } from 'vs/editor/contrib/find/browser/find';
import { SelectionHighlighter } from 'vs/editor/contrib/find/common/findController';
S
Sandeep Somavarapu 已提交
66

67 68
export class PreferencesEditorInput extends SideBySideEditorInput {
	public static ID: string = 'workbench.editorinputs.preferencesEditorInput';
S
Sandeep Somavarapu 已提交
69

70 71 72 73
	getTypeId(): string {
		return PreferencesEditorInput.ID;
	}
}
74

75
export class DefaultPreferencesEditorInput extends ResourceEditorInput {
76
	public static ID = 'workbench.editorinputs.defaultpreferences';
77 78 79 80
	constructor(defaultSettingsResource: URI,
		@ITextModelResolverService textModelResolverService: ITextModelResolverService
	) {
		super(nls.localize('settingsEditorName', "Default Settings"), '', defaultSettingsResource, textModelResolverService);
81 82
	}

S
Sandeep Somavarapu 已提交
83
	getTypeId(): string {
84
		return DefaultPreferencesEditorInput.ID;
S
Sandeep Somavarapu 已提交
85
	}
86

S
Sandeep Somavarapu 已提交
87
	matches(other: any): boolean {
88
		if (!super.matches(other)) {
S
Sandeep Somavarapu 已提交
89
			return false;
90
		}
91
		if (!(other instanceof DefaultPreferencesEditorInput)) {
S
Sandeep Somavarapu 已提交
92 93
			return false;
		}
S
Sandeep Somavarapu 已提交
94 95
		return true;
	}
96
}
97

98 99 100 101 102 103 104 105 106 107 108 109
export class PreferencesEditor extends BaseEditor {

	public static ID: string = 'workbench.editor.preferencesEditor';

	private headerContainer: HTMLElement;
	private searchWidget: SearchWidget;
	private settingsTabsWidget: SettingsTabsWidget;
	private sideBySidePreferencesWidget: SideBySidePreferencesWidget;

	private delayedFilterLogging: Delayer<void>;
	private disposablesByInput: IDisposable[] = [];

110 111
	private latestEmptyFilters: string[] = [];

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
	constructor(
		@IPreferencesService private preferencesService: IPreferencesService,
		@IEnvironmentService private environmentService: IEnvironmentService,
		@ITelemetryService telemetryService: ITelemetryService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IInstantiationService private instantiationService: IInstantiationService
	) {
		super(PreferencesEditor.ID, telemetryService);
		this.delayedFilterLogging = new Delayer<void>(1000);
	}

	public createEditor(parent: Builder): void {
		const parentElement = parent.getHTMLElement();
		DOM.addClass(parentElement, 'preferences-editor');

		this.headerContainer = DOM.append(parentElement, DOM.$('.preferences-header'));

		this.searchWidget = this._register(this.instantiationService.createInstance(SearchWidget, this.headerContainer));
		this._register(this.searchWidget.onDidChange(value => this.filterPreferences(value.trim())));
		this._register(this.searchWidget.onEnter(value => this.focusNextPreference()));

		this.settingsTabsWidget = this._register(this.instantiationService.createInstance(SettingsTabsWidget, this.headerContainer));
		this._register(this.settingsTabsWidget.onSwitch(() => this.switchSettings()));

		const editorsContainer = DOM.append(parentElement, DOM.$('.preferences-editors-container'));
		this.sideBySidePreferencesWidget = this._register(this.instantiationService.createInstance(SideBySidePreferencesWidget, editorsContainer));
	}

	public setInput(newInput: PreferencesEditorInput, options?: EditorOptions): TPromise<void> {
		const oldInput = <PreferencesEditorInput>this.input;
		return super.setInput(newInput, options)
			.then(() => this.updateInput(oldInput, newInput, options));
	}

	public layout(dimension: Dimension): void {
S
Sandeep Somavarapu 已提交
147 148
		DOM.toggleClass(this.headerContainer, 'vertical-layout', dimension.width < 700);
		this.searchWidget.layout(dimension);
149 150 151 152 153 154 155 156 157 158
		const headerHeight = DOM.getTotalHeight(this.headerContainer);
		this.sideBySidePreferencesWidget.layout(new Dimension(dimension.width, dimension.height - headerHeight));
	}

	public getControl(): IEditorControl {
		const editablePreferencesEditor = this.sideBySidePreferencesWidget.getEditablePreferencesEditor();
		return editablePreferencesEditor ? editablePreferencesEditor.getControl() : null;
	}

	public focus(): void {
S
Sandeep Somavarapu 已提交
159
		this.sideBySidePreferencesWidget.focus();
160 161
	}

162 163 164 165 166
	public clearInput(): void {
		this.sideBySidePreferencesWidget.clearInput();
		super.clearInput();
	}

167 168 169 170 171 172 173
	private updateInput(oldInput: PreferencesEditorInput, newInput: PreferencesEditorInput, options?: EditorOptions): TPromise<void> {
		const editablePreferencesUri = toResource(newInput.master);
		this.settingsTabsWidget.show(editablePreferencesUri.toString() === this.preferencesService.userSettingsResource.toString() ? ConfigurationTarget.USER : ConfigurationTarget.WORKSPACE);

		this.disposablesByInput = dispose(this.disposablesByInput);
		return this.sideBySidePreferencesWidget.setInput(<DefaultPreferencesEditorInput>newInput.details, newInput.master, options).then(() => {
			this.showTotalCount();
174 175 176
			const defaultPreferencesRenderer = this.getDefaultPreferencesRenderer();
			const editablePreferencesRender = this.getEditablePreferencesRenderer();
			if (!defaultPreferencesRenderer || !editablePreferencesRender) {
177 178
				return;
			}
179 180
			defaultPreferencesRenderer.onFocusPreference(setting => editablePreferencesRender.focusPreference(setting), this.disposablesByInput);
			defaultPreferencesRenderer.onClearFocusPreference(setting => editablePreferencesRender.clearFocus(setting), this.disposablesByInput);
181 182 183 184 185
			this.filterPreferences(this.searchWidget.value());
		});
	}

	private switchSettings(): void {
186 187 188 189
		// Focus the editor if this editor is not active editor
		if (this.editorService.getActiveEditor() !== this) {
			this.focus();
		}
190 191 192 193 194 195 196
		const promise = this.input.isDirty() ? this.input.save() : TPromise.as(true);
		promise.done(value => this.preferencesService.switchSettings());
	}

	private filterPreferences(filter: string) {
		const defaultPreferencesRenderer = this.getDefaultPreferencesRenderer();
		const editablePreferencesRender = this.getEditablePreferencesRenderer();
197 198 199 200
		if (!defaultPreferencesRenderer || !editablePreferencesRender) {
			return;
		}

201 202 203 204 205 206
		if (filter) {
			const filterResult = defaultPreferencesRenderer.preferencesModel.filterSettings(filter);
			defaultPreferencesRenderer.filterPreferences(filterResult);
			editablePreferencesRender.filterPreferences(filterResult);
			const count = this.getCount(filterResult.filteredGroups);
			this.searchWidget.showMessage(this.showSearchResultsMessage(count), count);
207 208 209 210 211

			if (count === 0) {
				this.latestEmptyFilters.push(filter);
			}
			this.delayedFilterLogging.trigger(() => this.reportFilteringUsed(filter));
212 213 214 215 216 217 218 219
		} else {
			defaultPreferencesRenderer.filterPreferences(null);
			editablePreferencesRender.filterPreferences(null);
			this.showTotalCount();
		}
	}

	private showTotalCount(): void {
220 221 222 223
		const defaultPreferencesRenderer = this.getDefaultPreferencesRenderer();
		const editablePreferencesRender = this.getEditablePreferencesRenderer();
		if (!defaultPreferencesRenderer || !editablePreferencesRender) {
			return;
224
		}
225 226
		const count = this.getCount(defaultPreferencesRenderer.preferencesModel.settingsGroups);
		this.searchWidget.showMessage(nls.localize('totalSettingsMessage', "Total {0} Settings", count), count);
227 228 229
	}

	private showSearchResultsMessage(count: number): string {
S
Sandeep Somavarapu 已提交
230
		return count === 0 ? nls.localize('noSettingsFound', "No Results") :
231 232 233 234 235 236
			count === 1 ? nls.localize('oneSettingFound', "1 Setting matched") :
				nls.localize('settingsFound', "{0} Settings matched", count);
	}

	private focusNextPreference() {
		const defaultPreferencesRenderer = this.getDefaultPreferencesRenderer();
237 238 239 240 241 242 243 244
		const editablePreferencesRender = this.getEditablePreferencesRenderer();
		if (!defaultPreferencesRenderer || !editablePreferencesRender) {
			return;
		}
		const setting = defaultPreferencesRenderer.iterator.next();
		if (setting) {
			defaultPreferencesRenderer.focusPreference(setting);
			editablePreferencesRender.focusPreference(setting);
245 246 247
		}
	}

248
	private getDefaultPreferencesRenderer(): IPreferencesRenderer<ISetting> {
249 250
		const detailsEditor = this.sideBySidePreferencesWidget.getDefaultPreferencesEditor();
		if (detailsEditor) {
251
			return (<CodeEditor>this.sideBySidePreferencesWidget.getDefaultPreferencesEditor().getControl()).getContribution<PreferencesEditorContribution<ISetting>>(DefaultSettingsEditorContribution.ID).getPreferencesRenderer();
252 253 254 255
		}
		return null;
	}

256
	private getEditablePreferencesRenderer(): IPreferencesRenderer<ISetting> {
257
		if (this.sideBySidePreferencesWidget.getEditablePreferencesEditor()) {
258
			return (<CodeEditor>this.sideBySidePreferencesWidget.getEditablePreferencesEditor().getControl()).getContribution<PreferencesEditorContribution<ISetting>>(SettingsEditorContribution.ID).getPreferencesRenderer();
259 260 261 262 263
		}
		return null;
	}

	private reportFilteringUsed(filter: string): void {
264 265 266 267 268
		let data = {
			filter,
			emptyFilters: this.getLatestEmptyFiltersForTelemetry()
		};
		this.latestEmptyFilters = [];
269 270 271
		this.telemetryService.publicLog('defaultSettings.filter', data);
	}

272 273 274 275 276 277 278 279 280
	/**
	 * Put a rough limit on the size of the telemetry data, since otherwise it could be an unbounded large amount
	 * of data. 8192 is the max size of a property value. This is rough since that probably includes ""s, etc.
	 */
	private getLatestEmptyFiltersForTelemetry(): string[] {
		let cumulativeSize = 0;
		return this.latestEmptyFilters.filter(filterText => (cumulativeSize += filterText.length) <= 8192);
	}

281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
	private getCount(settingsGroups: ISettingsGroup[]): number {
		let count = 0;
		for (const group of settingsGroups) {
			for (const section of group.sections) {
				count += section.settings.length;
			}
		}
		return count;
	}
}

export class SideBySidePreferencesWidget extends Widget {

	private dimension: Dimension;

	private defaultPreferencesEditor: DefaultPreferencesEditor;
	private defaultPreferencesEditorContainer: HTMLElement;
	private editablePreferencesEditor: BaseEditor;
	private editablePreferencesEditorContainer: HTMLElement;

	private sash: VSash;

	constructor(parent: HTMLElement, @IInstantiationService private instantiationService: IInstantiationService) {
		super();
		this.create(parent);
	}

	private create(parentElement: HTMLElement): void {
		DOM.addClass(parentElement, 'side-by-side-preferences-editor');
		this.createSash(parentElement);

		this.defaultPreferencesEditorContainer = DOM.append(parentElement, DOM.$('.default-preferences-editor-container'));
		this.defaultPreferencesEditorContainer.style.position = 'absolute';
		this.defaultPreferencesEditor = this.instantiationService.createInstance(DefaultPreferencesEditor);
		this.defaultPreferencesEditor.create(new Builder(this.defaultPreferencesEditorContainer));
S
Sandeep Somavarapu 已提交
316
		this.defaultPreferencesEditor.setVisible(true);
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336

		this.editablePreferencesEditorContainer = DOM.append(parentElement, DOM.$('.editable-preferences-editor-container'));
		this.editablePreferencesEditorContainer.style.position = 'absolute';
	}

	public setInput(defaultPreferencesEditorInput: DefaultPreferencesEditorInput, editablePreferencesEditorInput: EditorInput, options?: EditorOptions): TPromise<void> {
		return this.getOrCreateEditablePreferencesEditor(editablePreferencesEditorInput)
			.then(() => {
				this.dolayout(this.sash.getVerticalSashLeft());
				return TPromise.join([this.defaultPreferencesEditor.updateInput(defaultPreferencesEditorInput, options, toResource(editablePreferencesEditorInput), this.editablePreferencesEditor),
				this.editablePreferencesEditor.setInput(editablePreferencesEditorInput, options)])
					.then(() => null);
			});
	}

	public layout(dimension: Dimension): void {
		this.dimension = dimension;
		this.sash.setDimenesion(this.dimension);
	}

S
Sandeep Somavarapu 已提交
337 338 339 340 341 342
	public focus(): void {
		if (this.editablePreferencesEditor) {
			this.editablePreferencesEditor.focus();
		}
	}

343 344 345 346 347 348 349 350
	public getEditablePreferencesEditor(): IEditor {
		return this.editablePreferencesEditor;
	}

	public getDefaultPreferencesEditor(): DefaultPreferencesEditor {
		return this.defaultPreferencesEditor;
	}

351 352 353 354 355 356
	public clearInput(): void {
		if (this.editablePreferencesEditor) {
			this.editablePreferencesEditor.clearInput();
		}
	}

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
	private getOrCreateEditablePreferencesEditor(editorInput: EditorInput): TPromise<BaseEditor> {
		if (this.editablePreferencesEditor) {
			return TPromise.as(this.editablePreferencesEditor);
		}
		const descriptor = Registry.as<IEditorRegistry>(EditorExtensions.Editors).getEditor(editorInput);
		return this.instantiationService.createInstance(<EditorDescriptor>descriptor)
			.then((editor: BaseEditor) => {
				this.editablePreferencesEditor = editor;
				this.editablePreferencesEditor.create(new Builder(this.editablePreferencesEditorContainer));
				this.editablePreferencesEditor.setVisible(true);
				return editor;
			});
	}

	private createSash(parentElement: HTMLElement): void {
		this.sash = this._register(new VSash(parentElement, 220));
		this._register(this.sash.onPositionChange(position => this.dolayout(position)));
	}

	private dolayout(splitPoint: number): void {
		if (!this.editablePreferencesEditor || !this.dimension) {
			return;
		}
		const masterEditorWidth = this.dimension.width - splitPoint;
		const detailsEditorWidth = this.dimension.width - masterEditorWidth;

		this.defaultPreferencesEditorContainer.style.width = `${detailsEditorWidth}px`;
		this.defaultPreferencesEditorContainer.style.height = `${this.dimension.height}px`;
		this.defaultPreferencesEditorContainer.style.left = '0px';

		this.editablePreferencesEditorContainer.style.width = `${masterEditorWidth}px`;
		this.editablePreferencesEditorContainer.style.height = `${this.dimension.height}px`;
		this.editablePreferencesEditorContainer.style.left = `${splitPoint}px`;

		this.defaultPreferencesEditor.layout(new Dimension(detailsEditorWidth, this.dimension.height));
		this.editablePreferencesEditor.layout(new Dimension(masterEditorWidth, this.dimension.height));
	}

	private disposeEditors(): void {
		if (this.defaultPreferencesEditor) {
			this.defaultPreferencesEditor.dispose();
			this.defaultPreferencesEditor = null;
		}
		if (this.editablePreferencesEditor) {
			this.editablePreferencesEditor.dispose();
			this.editablePreferencesEditor = null;
		}
	}

	public dispose(): void {
		this.disposeEditors();
S
Sandeep Somavarapu 已提交
408
		super.dispose();
409 410 411
	}
}

S
Sandeep Somavarapu 已提交
412
export class DefaultPreferencesEditor extends BaseTextEditor {
413

S
Sandeep Somavarapu 已提交
414
	public static ID: string = 'workbench.editor.defaultPreferences';
415

S
Sandeep Somavarapu 已提交
416 417
	constructor(
		@ITelemetryService telemetryService: ITelemetryService,
S
Sandeep Somavarapu 已提交
418
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
S
Sandeep Somavarapu 已提交
419 420 421 422 423
		@IInstantiationService instantiationService: IInstantiationService,
		@IStorageService storageService: IStorageService,
		@IConfigurationService configurationService: IConfigurationService,
		@IThemeService themeService: IThemeService,
		@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
S
Sandeep Somavarapu 已提交
424 425
		@IPreferencesService private preferencesService: IPreferencesService,
		@IModelService private modelService: IModelService,
426
		@IModeService modeService: IModeService,
S
Sandeep Somavarapu 已提交
427
	) {
428
		super(DefaultPreferencesEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, modeService);
S
Sandeep Somavarapu 已提交
429 430
	}

431
	public createEditorControl(parent: Builder, configuration: editorCommon.IEditorOptions): editorCommon.IEditor {
432
		return this.instantiationService.createInstance(DefaultPreferencesCodeEditor, parent.getHTMLElement(), configuration);
433 434
	}

435 436
	protected getConfigurationOverrides(): editorCommon.IEditorOptions {
		const options = super.getConfigurationOverrides();
437
		options.readOnly = true;
438
		if (this.input) {
S
Sandeep Somavarapu 已提交
439 440 441 442 443 444
			options.lineNumbers = 'off';
			options.renderLineHighlight = 'none';
			options.scrollBeyondLastLine = false;
			options.folding = false;
			options.renderWhitespace = 'none';
			options.wrappingColumn = 0;
S
Sandeep Somavarapu 已提交
445
			options.renderIndentGuides = false;
S
Sandeep Somavarapu 已提交
446
			options.rulers = [];
S
Sandeep Somavarapu 已提交
447
			options.glyphMargin = true;
S
Sandeep Somavarapu 已提交
448
		}
S
Sandeep Somavarapu 已提交
449 450 451
		return options;
	}

452 453 454 455 456 457 458 459
	updateInput(input: DefaultPreferencesEditorInput, options: EditorOptions, editablePreferencesUri: URI, settingsEditor: BaseEditor): TPromise<void> {
		return this.setInput(input, options)
			.then(() => this.input.resolve()
				.then(editorModel => TPromise.join<any>([
					editorModel.load(),
					this.preferencesService.resolvePreferencesEditorModel(editablePreferencesUri)
				]))
				.then(([editorModel, preferencesModel]) => (<DefaultPreferencesCodeEditor>this.getControl()).setModels((<ResourceEditorModel>editorModel).textEditorModel, <SettingsEditorModel>preferencesModel, settingsEditor)));
S
Sandeep Somavarapu 已提交
460 461 462
	}

	public layout(dimension: Dimension) {
463
		this.getControl().layout(dimension);
S
Sandeep Somavarapu 已提交
464 465
	}

466
	public clearInput(): void {
S
Sandeep Somavarapu 已提交
467
		this.getControl().setModel(null);
468 469
		super.clearInput();
	}
470 471 472 473

	protected getAriaLabel(): string {
		return nls.localize('preferencesAriaLabel', "Default preferences. Readonly text editor.");
	}
S
Sandeep Somavarapu 已提交
474 475
}

S
Sandeep Somavarapu 已提交
476
class DefaultPreferencesCodeEditor extends CodeEditor {
S
Sandeep Somavarapu 已提交
477

478
	private _settingsModel: SettingsEditorModel;
479
	private _settingsEditor: BaseEditor;
480

S
Sandeep Somavarapu 已提交
481 482
	protected _getContributions(): IEditorContributionCtor[] {
		let contributions = super._getContributions();
S
Sandeep Somavarapu 已提交
483
		let skipContributions = [FoldingController.prototype, SelectionHighlighter.prototype, FindController.prototype];
S
Sandeep Somavarapu 已提交
484
		contributions = contributions.filter(c => skipContributions.indexOf(c.prototype) === -1);
485 486
		contributions.push(DefaultSettingsEditorContribution);
		return contributions;
S
Sandeep Somavarapu 已提交
487
	}
488

489
	setModels(model: editorCommon.IModel, settingsModel: SettingsEditorModel, settingsEditor: BaseEditor): void {
490
		this._settingsModel = settingsModel;
491
		this._settingsEditor = settingsEditor;
492 493 494 495 496 497
		return super.setModel(model);
	}

	get settingsModel(): SettingsEditorModel {
		return this._settingsModel;
	}
498 499 500 501

	get settingsEditor(): BaseEditor {
		return this._settingsEditor;
	}
S
Sandeep Somavarapu 已提交
502 503
}

504
export interface IPreferencesRenderer<T> {
505 506 507 508 509
	iterator: IIterator<ISetting>;
	onFocusPreference: Event<ISetting>;
	onClearFocusPreference: Event<ISetting>;
	preferencesModel: ISettingsEditorModel;
	render(): void;
510
	updatePreference(key: string, value: any, source: T): void;
511 512 513
	filterPreferences(filterResult: IFilterResult): void;
	focusPreference(setting: ISetting): void;
	clearFocus(setting: ISetting): void;
514 515 516
	dispose();
}

517
export abstract class PreferencesEditorContribution<T> extends Disposable implements editorCommon.IEditorContribution {
S
Sandeep Somavarapu 已提交
518

519
	private preferencesRenderer: IPreferencesRenderer<T>;
S
Sandeep Somavarapu 已提交
520

521 522 523
	constructor(protected editor: ICodeEditor,
		@IInstantiationService protected instantiationService: IInstantiationService,
		@IPreferencesService protected preferencesService: IPreferencesService
S
Sandeep Somavarapu 已提交
524 525 526 527 528 529 530
	) {
		super();
		this._register(editor.onDidChangeModel(() => this.onModelChanged()));
	}

	private onModelChanged(): void {
		const model = this.editor.getModel();
531 532 533 534 535 536
		this.disposePreferencesRenderer();
		if (model) {
			this.preferencesService.resolvePreferencesEditorModel(model.uri)
				.then(editorModel => {
					if (editorModel) {
						this.preferencesRenderer = this.createPreferencesRenderer(editorModel);
S
Sandeep Somavarapu 已提交
537 538 539
						if (this.preferencesRenderer) {
							this.preferencesRenderer.render();
						}
540 541 542 543
					}
				});
		}
	}
S
Sandeep Somavarapu 已提交
544

545
	getPreferencesRenderer(): IPreferencesRenderer<T> {
S
Sandeep Somavarapu 已提交
546
		return this.preferencesRenderer;
547 548
	}

549
	protected abstract createPreferencesRenderer(editorModel: IPreferencesEditorModel<any>): IPreferencesRenderer<T>
550
	abstract getId(): string;
551 552 553 554 555 556 557 558 559 560 561 562 563 564

	private disposePreferencesRenderer() {
		if (this.preferencesRenderer) {
			this.preferencesRenderer.dispose();
			this.preferencesRenderer = null;
		}
	}

	public dispose() {
		this.disposePreferencesRenderer();
		super.dispose();
	}
}

565
export class DefaultSettingsEditorContribution extends PreferencesEditorContribution<ISetting> implements editorCommon.IEditorContribution {
566 567 568

	static ID: string = 'editor.contrib.defaultsettings';

569
	protected createPreferencesRenderer(editorModel: IPreferencesEditorModel<ISetting>): IPreferencesRenderer<ISetting> {
570
		if (editorModel instanceof DefaultSettingsEditorModel) {
571
			return this.instantiationService.createInstance(DefaultSettingsRenderer, this.editor, editorModel);
572 573 574
		}
		return null;
	}
575 576 577 578

	getId(): string {
		return DefaultSettingsEditorContribution.ID;
	}
579 580 581
}

@editorContribution
582
export class SettingsEditorContribution extends PreferencesEditorContribution<ISetting> implements editorCommon.IEditorContribution {
583 584 585 586 587 588 589

	static ID: string = 'editor.contrib.settings';

	getId(): string {
		return SettingsEditorContribution.ID;
	}

590
	protected createPreferencesRenderer(editorModel: IPreferencesEditorModel<ISetting>): IPreferencesRenderer<ISetting> {
591 592 593 594 595 596 597
		if (editorModel instanceof SettingsEditorModel) {
			return this.instantiationService.createInstance(SettingsRenderer, this.editor, editorModel);
		}
		return null;
	}
}

598
export class SettingsRenderer extends Disposable implements IPreferencesRenderer<ISetting> {
599

600 601 602
	private initializationPromise: TPromise<void>;
	private settingHighlighter: SettingHighlighter;
	private editSettingActionRenderer: EditSettingRenderer;
603 604
	private highlightPreferencesRenderer: HighlightPreferencesRenderer;
	private defaultSettingsModel: DefaultSettingsEditorModel;
605
	private untrustedSettingRenderer: UnTrustedWorkspaceSettingsRenderer;
S
Sandeep Somavarapu 已提交
606
	private modelChangeDelayer: Delayer<void> = new Delayer<void>(200);
607

608 609 610 611 612 613
	private _onFocusPreference: Emitter<ISetting> = new Emitter<ISetting>();
	public readonly onFocusPreference: Event<ISetting> = this._onFocusPreference.event;

	private _onClearFocusPreference: Emitter<ISetting> = new Emitter<ISetting>();
	public readonly onClearFocusPreference: Event<ISetting> = this._onClearFocusPreference.event;

S
Sandeep Somavarapu 已提交
614 615
	private filterResult: IFilterResult;

616
	constructor(protected editor: ICodeEditor, public readonly preferencesModel: SettingsEditorModel,
617
		@IPreferencesService protected preferencesService: IPreferencesService,
618 619 620
		@ITelemetryService private telemetryService: ITelemetryService,
		@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService,
		@IMessageService private messageService: IMessageService,
621 622 623
		@IInstantiationService protected instantiationService: IInstantiationService
	) {
		super();
S
Sandeep Somavarapu 已提交
624
		if (ConfigurationTarget.WORKSPACE === preferencesModel.configurationTarget) {
625 626
			this.untrustedSettingRenderer = this._register(instantiationService.createInstance(UnTrustedWorkspaceSettingsRenderer, editor, preferencesModel));
		}
627 628
		this.settingHighlighter = this._register(instantiationService.createInstance(SettingHighlighter, editor, this._onFocusPreference, this._onClearFocusPreference));
		this.highlightPreferencesRenderer = this._register(instantiationService.createInstance(HighlightPreferencesRenderer, editor));
629
		this.initializationPromise = this.initialize();
630 631
	}

632 633 634 635
	public get iterator(): IIterator<ISetting> {
		return null;
	}

S
Sandeep Somavarapu 已提交
636
	public render(): void {
637
		this.initializationPromise.then(() => {
S
Sandeep Somavarapu 已提交
638
			this.editSettingActionRenderer.render(this.preferencesModel.settingsGroups);
639 640 641
			if (this.untrustedSettingRenderer) {
				this.untrustedSettingRenderer.render();
			}
S
Sandeep Somavarapu 已提交
642 643 644
			if (this.filterResult) {
				this.filterPreferences(this.filterResult);
			}
645
		});
646 647 648 649 650
	}

	private initialize(): TPromise<void> {
		return this.preferencesService.createDefaultPreferencesEditorModel(this.preferencesService.defaultSettingsResource)
			.then(defaultSettingsModel => {
651
				this.defaultSettingsModel = <DefaultSettingsEditorModel>defaultSettingsModel;
S
Sandeep Somavarapu 已提交
652 653
				this.editSettingActionRenderer = this._register(this.instantiationService.createInstance(EditSettingRenderer, this.editor, this.preferencesModel, () => defaultSettingsModel, this.settingHighlighter));
				this._register(this.editSettingActionRenderer.onUpdateSetting(({key, value, source}) => this.updatePreference(key, value, source)));
654 655 656
				this._register(this.editor.getModel().onDidChangeContent(() => this.modelChangeDelayer.trigger(() => this.onModelChanged())));
				return null;
			});
657
	}
S
Fixes:  
Sandeep Somavarapu 已提交
658

S
Sandeep Somavarapu 已提交
659 660 661 662 663 664 665
	public updatePreference(key: string, value: any, source: ISetting): void {
		this.telemetryService.publicLog('defaultSettingsActions.copySetting', { userConfigurationKeys: [key] });
		const overrideIdentifier = source.overrideOf ? overrideIdentifierFromKey(source.overrideOf.key) : null;
		this.configurationEditingService.writeConfiguration(this.preferencesModel.configurationTarget, { key, value, overrideIdentifier }, { writeToBuffer: true, autoSave: true })
			.then(() => this.onSettingUpdated(source), error => this.messageService.show(Severity.Error, error));
	}

S
Sandeep Somavarapu 已提交
666 667 668 669 670
	private onModelChanged(): void {
		if (!this.editor.getModel()) {
			// model could have been disposed during the delay
			return;
		}
S
Fixes:  
Sandeep Somavarapu 已提交
671 672
		this.render();
	}
673 674 675

	private onSettingUpdated(setting: ISetting) {
		this.editor.focus();
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
		setting = this.getSetting(setting);
		if (setting) {
			// TODO:@sandy Selection range should be template range
			this.editor.setSelection(setting.valueRange);
			this.settingHighlighter.highlight(setting, true);
		}
	}

	private getSetting(setting: ISetting): ISetting {
		const {key, overrideOf} = setting;
		if (overrideOf) {
			const setting = this.getSetting(overrideOf);
			for (const override of setting.overrides) {
				if (override.key === key) {
					return override;
				}
			}
			return null;
		}
		return this.preferencesModel.getPreference(key);
696 697 698
	}

	public filterPreferences(filterResult: IFilterResult): void {
S
Sandeep Somavarapu 已提交
699
		this.filterResult = filterResult;
700 701 702 703 704 705
		this.highlightPreferencesRenderer.render([]);
		this.settingHighlighter.clear(true);
		if (this.defaultSettingsModel && filterResult) {
			const settings = distinct(filterResult.filteredGroups.reduce((settings: ISetting[], settingsGroup: ISettingsGroup) => {
				for (const section of settingsGroup.sections) {
					for (const setting of section.settings) {
706
						const s = this.getSetting(setting);
707 708 709 710 711 712 713 714 715 716 717 718
						if (s) {
							settings.push(s);
						}
					}
				}
				return settings;
			}, []));
			this.highlightPreferencesRenderer.render(settings);
		}
	}

	public focusPreference(setting: ISetting): void {
719
		const s = this.getSetting(setting);
720 721 722 723 724 725 726 727 728
		if (s) {
			this.settingHighlighter.highlight(s, true);
		} else {
			this.settingHighlighter.clear(true);
		}
	}

	public clearFocus(setting: ISetting): void {
		this.settingHighlighter.clear(true);
729
	}
730 731
}

732
export class DefaultSettingsRenderer extends Disposable implements IPreferencesRenderer<ISetting> {
733

S
Sandeep Somavarapu 已提交
734 735
	private defaultSettingsEditorContextKey: IContextKey<boolean>;

736
	private settingHighlighter: SettingHighlighter;
S
Sandeep Somavarapu 已提交
737 738
	private settingsGroupTitleRenderer: SettingsGroupTitleRenderer;
	private filteredMatchesRenderer: FilteredMatchesRenderer;
739
	private filteredSettingsNavigationRenderer: FilteredSettingsNavigationRenderer;
S
Sandeep Somavarapu 已提交
740
	private hiddenAreasRenderer: HiddenAreasRenderer;
741
	private editSettingActionRenderer: EditSettingRenderer;
742

743 744 745 746 747 748 749
	private _onFocusPreference: Emitter<ISetting> = new Emitter<ISetting>();
	public readonly onFocusPreference: Event<ISetting> = this._onFocusPreference.event;

	private _onClearFocusPreference: Emitter<ISetting> = new Emitter<ISetting>();
	public readonly onClearFocusPreference: Event<ISetting> = this._onClearFocusPreference.event;

	constructor(protected editor: ICodeEditor, public readonly preferencesModel: DefaultSettingsEditorModel,
750
		@IPreferencesService protected preferencesService: IPreferencesService,
S
Sandeep Somavarapu 已提交
751
		@IContextKeyService contextKeyService: IContextKeyService,
752
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
753 754 755
		@IInstantiationService protected instantiationService: IInstantiationService
	) {
		super();
S
Sandeep Somavarapu 已提交
756
		this.defaultSettingsEditorContextKey = CONTEXT_DEFAULT_SETTINGS_EDITOR.bindTo(contextKeyService);
757
		this.settingHighlighter = this._register(instantiationService.createInstance(SettingHighlighter, editor, this._onFocusPreference, this._onClearFocusPreference));
S
Sandeep Somavarapu 已提交
758 759
		this.settingsGroupTitleRenderer = this._register(instantiationService.createInstance(SettingsGroupTitleRenderer, editor));
		this.filteredMatchesRenderer = this._register(instantiationService.createInstance(FilteredMatchesRenderer, editor));
760
		this.filteredSettingsNavigationRenderer = this._register(instantiationService.createInstance(FilteredSettingsNavigationRenderer, editor, this.settingHighlighter));
761
		this.editSettingActionRenderer = this._register(instantiationService.createInstance(EditSettingRenderer, editor, preferencesModel, () => (<DefaultPreferencesCodeEditor>this.editor).settingsModel, this.settingHighlighter));
762
		this._register(this.editSettingActionRenderer.onUpdateSetting(({key, value, source}) => this.updatePreference(key, value, source)));
763
		const paranthesisHidingRenderer = this._register(instantiationService.createInstance(StaticContentHidingRenderer, editor, preferencesModel.settingsGroups));
S
Sandeep Somavarapu 已提交
764
		this.hiddenAreasRenderer = this._register(instantiationService.createInstance(HiddenAreasRenderer, editor, [this.settingsGroupTitleRenderer, this.filteredMatchesRenderer, paranthesisHidingRenderer]));
S
Sandeep Somavarapu 已提交
765 766

		this._register(this.settingsGroupTitleRenderer.onHiddenAreasChanged(() => this.hiddenAreasRenderer.render()));
767 768
	}

769 770 771 772
	public get iterator(): IIterator<ISetting> {
		return this.filteredSettingsNavigationRenderer;
	}

773
	public render() {
S
Sandeep Somavarapu 已提交
774
		this.defaultSettingsEditorContextKey.set(true);
775 776
		this.settingsGroupTitleRenderer.render(this.preferencesModel.settingsGroups);
		this.editSettingActionRenderer.render(this.preferencesModel.settingsGroups);
S
Sandeep Somavarapu 已提交
777
		this.hiddenAreasRenderer.render();
778
		this.filteredSettingsNavigationRenderer.render([]);
S
Push:  
Sandeep Somavarapu 已提交
779
		this.settingsGroupTitleRenderer.showGroup(1);
S
Sandeep Somavarapu 已提交
780
		this.hiddenAreasRenderer.render();
S
Sandeep Somavarapu 已提交
781 782
	}

783 784
	public filterPreferences(filterResult: IFilterResult): void {
		if (!filterResult) {
785
			this.filteredSettingsNavigationRenderer.render([]);
786 787
			this.filteredMatchesRenderer.render(null);
			this.settingsGroupTitleRenderer.render(this.preferencesModel.settingsGroups);
S
Push:  
Sandeep Somavarapu 已提交
788
			this.settingsGroupTitleRenderer.showGroup(1);
S
Sandeep Somavarapu 已提交
789
		} else {
790 791
			this.filteredMatchesRenderer.render(filterResult);
			this.settingsGroupTitleRenderer.render(filterResult.filteredGroups);
792
			this.filteredSettingsNavigationRenderer.render(filterResult.filteredGroups);
S
Push:  
Sandeep Somavarapu 已提交
793
		}
S
Sandeep Somavarapu 已提交
794
		this.hiddenAreasRenderer.render();
S
Sandeep Somavarapu 已提交
795 796
	}

797 798 799 800 801 802 803
	public focusPreference(setting: ISetting): void {
		this.settingsGroupTitleRenderer.showSetting(setting);
		this.settingHighlighter.highlight(setting, true);
	}

	public clearFocus(setting: ISetting): void {
		this.settingHighlighter.clear(true);
S
Sandeep Somavarapu 已提交
804 805
	}

S
Sandeep Somavarapu 已提交
806 807 808 809
	public collapseAll() {
		this.settingsGroupTitleRenderer.collapseAll();
	}

810
	public updatePreference(key: string, value: any, source: ISetting): void {
811 812
		const settingsEditor = this.getEditableSettingsEditor();
		if (settingsEditor) {
813
			settingsEditor.getContribution<PreferencesEditorContribution<ISetting>>(SettingsEditorContribution.ID).getPreferencesRenderer().updatePreference(key, value, source);
814 815 816 817
		}
	}

	private getEditableSettingsEditor(): editorCommon.ICommonCodeEditor {
818
		return <editorCommon.ICommonCodeEditor>(<DefaultPreferencesCodeEditor>this.editor).settingsEditor.getControl();
S
Push:  
Sandeep Somavarapu 已提交
819 820
	}

S
Sandeep Somavarapu 已提交
821
	dispose() {
822
		this.defaultSettingsEditorContextKey.set(false);
S
Sandeep Somavarapu 已提交
823
		super.dispose();
824 825 826
	}
}

S
Sandeep Somavarapu 已提交
827 828 829
export interface HiddenAreasProvider {
	hiddenAreas: editorCommon.IRange[];
}
830

S
Sandeep Somavarapu 已提交
831
export class StaticContentHidingRenderer extends Disposable implements HiddenAreasProvider {
832

S
Sandeep Somavarapu 已提交
833
	constructor(private editor: ICodeEditor, private settingsGroups: ISettingsGroup[]
834 835
	) {
		super();
836 837
	}

S
Sandeep Somavarapu 已提交
838 839 840 841 842 843
	get hiddenAreas(): editorCommon.IRange[] {
		const model = this.editor.getModel();
		return [
			{
				startLineNumber: 1,
				startColumn: model.getLineMinColumn(1),
S
Sandeep Somavarapu 已提交
844 845
				endLineNumber: 2,
				endColumn: model.getLineMaxColumn(2)
S
Sandeep Somavarapu 已提交
846 847
			},
			{
S
Sandeep Somavarapu 已提交
848 849 850 851 852 853 854 855
				startLineNumber: this.settingsGroups[0].range.endLineNumber + 1,
				startColumn: model.getLineMinColumn(this.settingsGroups[0].range.endLineNumber + 1),
				endLineNumber: this.settingsGroups[0].range.endLineNumber + 4,
				endColumn: model.getLineMaxColumn(this.settingsGroups[0].range.endLineNumber + 4)
			},
			{
				startLineNumber: model.getLineCount() - 1,
				startColumn: model.getLineMinColumn(model.getLineCount() - 1),
S
Sandeep Somavarapu 已提交
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
				endLineNumber: model.getLineCount(),
				endColumn: model.getLineMaxColumn(model.getLineCount())
			}
		];
	}

}

export class SettingsGroupTitleRenderer extends Disposable implements HiddenAreasProvider {

	private _onHiddenAreasChanged: Emitter<void> = new Emitter<void>();
	get onHiddenAreasChanged(): Event<void> { return this._onHiddenAreasChanged.event; };

	private settingsGroups: ISettingsGroup[];
	private hiddenGroups: ISettingsGroup[] = [];
	private settingsGroupTitleWidgets: SettingsGroupTitleWidget[];
	private disposables: IDisposable[] = [];

	constructor(private editor: ICodeEditor,
		@IInstantiationService private instantiationService: IInstantiationService
	) {
		super();
	}

	public get hiddenAreas(): editorCommon.IRange[] {
		const hiddenAreas: editorCommon.IRange[] = [];
		for (const group of this.hiddenGroups) {
			hiddenAreas.push(group.range);
		}
		return hiddenAreas;
	}

	public render(settingsGroups: ISettingsGroup[]) {
		this.disposeWidgets();
		this.settingsGroups = settingsGroups.slice();
		this.settingsGroupTitleWidgets = [];
		for (const group of this.settingsGroups.slice().reverse()) {
			const settingsGroupTitleWidget = this.instantiationService.createInstance(SettingsGroupTitleWidget, this.editor, group);
			settingsGroupTitleWidget.render();
			this.settingsGroupTitleWidgets.push(settingsGroupTitleWidget);
			this.disposables.push(settingsGroupTitleWidget);
			this.disposables.push(settingsGroupTitleWidget.onToggled(collapsed => this.onToggled(collapsed, settingsGroupTitleWidget.settingsGroup)));
S
Sandeep Somavarapu 已提交
898
		}
S
Fixes:  
Sandeep Somavarapu 已提交
899
		this.settingsGroupTitleWidgets.reverse();
S
Sandeep Somavarapu 已提交
900 901
	}

S
Push:  
Sandeep Somavarapu 已提交
902 903 904
	public showGroup(group: number) {
		this.hiddenGroups = this.settingsGroups.filter((g, i) => i !== group - 1);
		for (const groupTitleWidget of this.settingsGroupTitleWidgets.filter((g, i) => i !== group - 1)) {
S
Sandeep Somavarapu 已提交
905
			groupTitleWidget.toggleCollapse(true);
S
Push:  
Sandeep Somavarapu 已提交
906 907 908 909
		}
		this._onHiddenAreasChanged.fire();
	}

S
Sandeep Somavarapu 已提交
910 911 912 913 914 915 916 917 918
	public showSetting(setting: ISetting): void {
		const settingsGroupTitleWidget = this.settingsGroupTitleWidgets.filter(widget => Range.containsRange(widget.settingsGroup.range, setting.range))[0];
		if (settingsGroupTitleWidget && settingsGroupTitleWidget.isCollapsed()) {
			settingsGroupTitleWidget.toggleCollapse(false);
			this.hiddenGroups.splice(this.hiddenGroups.indexOf(settingsGroupTitleWidget.settingsGroup), 1);
			this._onHiddenAreasChanged.fire();
		}
	}

S
Sandeep Somavarapu 已提交
919 920 921 922
	public collapseAll() {
		this.editor.setPosition({ lineNumber: 1, column: 1 });
		this.hiddenGroups = this.settingsGroups.slice();
		for (const groupTitleWidget of this.settingsGroupTitleWidgets) {
S
Sandeep Somavarapu 已提交
923
			groupTitleWidget.toggleCollapse(true);
924
		}
S
Sandeep Somavarapu 已提交
925 926 927 928 929 930 931 932 933 934 935
		this._onHiddenAreasChanged.fire();
	}

	private onToggled(collapsed: boolean, group: ISettingsGroup) {
		const index = this.hiddenGroups.indexOf(group);
		if (collapsed) {
			const currentPosition = this.editor.getPosition();
			if (group.range.startLineNumber <= currentPosition.lineNumber && group.range.endLineNumber >= currentPosition.lineNumber) {
				this.editor.setPosition({ lineNumber: group.range.startLineNumber - 1, column: 1 });
			}
			this.hiddenGroups.push(group);
936
		} else {
S
Sandeep Somavarapu 已提交
937
			this.hiddenGroups.splice(index, 1);
S
Sandeep Somavarapu 已提交
938
		}
S
Sandeep Somavarapu 已提交
939
		this._onHiddenAreasChanged.fire();
S
Sandeep Somavarapu 已提交
940 941
	}

S
Sandeep Somavarapu 已提交
942 943 944
	private disposeWidgets() {
		this.hiddenGroups = [];
		this.disposables = dispose(this.disposables);
945 946
	}

S
Sandeep Somavarapu 已提交
947 948 949 950 951 952 953 954 955 956 957 958
	public dispose() {
		this.disposeWidgets();
		super.dispose();
	}
}

export class HiddenAreasRenderer extends Disposable {

	constructor(private editor: ICodeEditor, private hiddenAreasProviders: HiddenAreasProvider[],
		@IInstantiationService private instantiationService: IInstantiationService
	) {
		super();
S
Sandeep Somavarapu 已提交
959 960
	}

S
Sandeep Somavarapu 已提交
961
	public render() {
S
Sandeep Somavarapu 已提交
962 963 964 965 966 967
		const ranges: editorCommon.IRange[] = [];
		for (const hiddenAreaProvider of this.hiddenAreasProviders) {
			ranges.push(...hiddenAreaProvider.hiddenAreas);
		}
		this.editor.setHiddenAreas(ranges);
	}
S
Sandeep Somavarapu 已提交
968 969 970 971 972

	public dispose() {
		this.editor.setHiddenAreas([]);
		super.dispose();
	}
S
Sandeep Somavarapu 已提交
973 974 975 976 977 978 979 980 981 982 983 984 985 986
}

export class FilteredMatchesRenderer extends Disposable implements HiddenAreasProvider {

	private decorationIds: string[] = [];
	public hiddenAreas: editorCommon.IRange[] = [];

	constructor(private editor: ICodeEditor,
		@IInstantiationService private instantiationService: IInstantiationService
	) {
		super();
	}

	public render(result: IFilterResult): void {
987
		const model = this.editor.getModel();
S
Sandeep Somavarapu 已提交
988
		this.hiddenAreas = [];
989
		this.editor.changeDecorations(changeAccessor => {
S
Sandeep Somavarapu 已提交
990 991 992
			this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, []);
		});
		if (result) {
993 994 995
			this.hiddenAreas = this.computeHiddenRanges(result.filteredGroups, result.allGroups, model);
			this.editor.changeDecorations(changeAccessor => {
				this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, flatten(result.matches.values()).map(match => this.createDecoration(match, model)));
S
Sandeep Somavarapu 已提交
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
			});
		}
	}

	private createDecoration(range: editorCommon.IRange, model: editorCommon.IModel): editorCommon.IModelDeltaDecoration {
		return {
			range,
			options: {
				stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
				className: 'findMatch'
			}
		};
	}

	private computeHiddenRanges(filteredGroups: ISettingsGroup[], allSettingsGroups: ISettingsGroup[], model: editorCommon.IModel): editorCommon.IRange[] {
		const notMatchesRanges: editorCommon.IRange[] = [];
		for (const group of allSettingsGroups) {
			const filteredGroup = filteredGroups.filter(g => g.title === group.title)[0];
			if (!filteredGroup) {
				notMatchesRanges.push({
					startLineNumber: group.range.startLineNumber - 1,
					startColumn: model.getLineMinColumn(group.range.startLineNumber - 1),
					endLineNumber: group.range.endLineNumber,
					endColumn: model.getLineMaxColumn(group.range.endLineNumber),
				});
			} else {
1022
				for (const section of group.sections) {
1023 1024 1025
					if (section.titleRange) {
						if (!this.containsLine(section.titleRange.startLineNumber, filteredGroup)) {
							notMatchesRanges.push(this.createCompleteRange(section.titleRange, model));
S
Sandeep Somavarapu 已提交
1026 1027
						}
					}
1028
					for (const setting of section.settings) {
S
Sandeep Somavarapu 已提交
1029 1030
						if (!this.containsLine(setting.range.startLineNumber, filteredGroup)) {
							notMatchesRanges.push(this.createCompleteRange(setting.range, model));
1031 1032 1033 1034 1035
						}
					}
				}
			}
		}
S
Sandeep Somavarapu 已提交
1036 1037 1038 1039 1040 1041 1042 1043 1044
		return notMatchesRanges;
	}

	private containsLine(lineNumber: number, settingsGroup: ISettingsGroup): boolean {
		if (settingsGroup.titleRange && lineNumber >= settingsGroup.titleRange.startLineNumber && lineNumber <= settingsGroup.titleRange.endLineNumber) {
			return true;
		}

		for (const section of settingsGroup.sections) {
1045
			if (section.titleRange && lineNumber >= section.titleRange.startLineNumber && lineNumber <= section.titleRange.endLineNumber) {
S
Sandeep Somavarapu 已提交
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
				return true;
			}

			for (const setting of section.settings) {
				if (lineNumber >= setting.range.startLineNumber && lineNumber <= setting.range.endLineNumber) {
					return true;
				}
			}
		}
		return false;
	}

	private createCompleteRange(range: editorCommon.IRange, model: editorCommon.IModel): editorCommon.IRange {
		return {
			startLineNumber: range.startLineNumber,
			startColumn: model.getLineMinColumn(range.startLineNumber),
			endLineNumber: range.endLineNumber,
			endColumn: model.getLineMaxColumn(range.endLineNumber)
		};
	}

	public dispose() {
1068 1069
		if (this.decorationIds) {
			this.decorationIds = this.editor.changeDecorations(changeAccessor => {
1070
				return changeAccessor.deltaDecorations(this.decorationIds, []);
S
Sandeep Somavarapu 已提交
1071 1072 1073
			});
		}
		super.dispose();
S
Sandeep Somavarapu 已提交
1074 1075 1076
	}
}

1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
export class HighlightPreferencesRenderer extends Disposable {

	private decorationIds: string[] = [];

	constructor(private editor: ICodeEditor,
		@IInstantiationService private instantiationService: IInstantiationService
	) {
		super();
	}

	public render(settings: ISetting[]): void {
		const model = this.editor.getModel();
		this.editor.changeDecorations(changeAccessor => {
			this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, []);
		});
		if (settings.length) {
			this.editor.changeDecorations(changeAccessor => {
				this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, settings.map(setting => this.createDecoration(setting.keyRange, model)));
			});
		}
	}

	private createDecoration(range: editorCommon.IRange, model: editorCommon.IModel): editorCommon.IModelDeltaDecoration {
		return {
			range,
			options: {
				stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
				className: 'findMatch'
			}
		};
	}

	public dispose() {
		if (this.decorationIds) {
			this.decorationIds = this.editor.changeDecorations(changeAccessor => {
				return changeAccessor.deltaDecorations(this.decorationIds, []);
			});
		}
		super.dispose();
	}
}

class FilteredSettingsNavigationRenderer extends Disposable implements IIterator<ISetting> {
S
Sandeep Somavarapu 已提交
1120

1121
	private iterator: ArrayNavigator<ISetting>;
S
Sandeep Somavarapu 已提交
1122

1123
	constructor(private editor: ICodeEditor, private settingHighlighter: SettingHighlighter) {
S
Sandeep Somavarapu 已提交
1124 1125 1126
		super();
	}

1127
	public next(): ISetting {
1128
		return this.iterator.next() || this.iterator.first();
S
Sandeep Somavarapu 已提交
1129 1130 1131
	}

	public render(filteredGroups: ISettingsGroup[]) {
1132
		this.settingHighlighter.clear(true);
S
Sandeep Somavarapu 已提交
1133 1134 1135 1136 1137 1138
		const settings: ISetting[] = [];
		for (const group of filteredGroups) {
			for (const section of group.sections) {
				settings.push(...section.settings);
			}
		}
1139
		this.iterator = new ArrayNavigator<ISetting>(settings);
S
Sandeep Somavarapu 已提交
1140 1141 1142
	}
}

1143
class EditSettingRenderer extends Disposable {
1144

1145 1146
	private editPreferenceWidgetForCusorPosition: EditPreferenceWidget<ISetting>;
	private editPreferenceWidgetForMouseMove: EditPreferenceWidget<ISetting>;
S
Sandeep Somavarapu 已提交
1147

1148
	private settingsGroups: ISettingsGroup[];
1149
	private toggleEditPreferencesForMouseMoveDelayer: Delayer<void>;
1150

1151 1152
	private _onUpdateSetting: Emitter<{ key: string, value: any, source: ISetting }> = new Emitter<{ key: string, value: any, source: ISetting }>();
	public readonly onUpdateSetting: Event<{ key: string, value: any, source: ISetting }> = this._onUpdateSetting.event;
1153

1154
	constructor(private editor: ICodeEditor, private masterSettingsModel: ISettingsEditorModel,
1155
		private otherSettingsModel: () => ISettingsEditorModel,
1156
		private settingHighlighter: SettingHighlighter,
1157 1158
		@IPreferencesService private preferencesService: IPreferencesService,
		@IInstantiationService private instantiationService: IInstantiationService,
S
Sandeep Somavarapu 已提交
1159 1160 1161
		@IContextMenuService private contextMenuService: IContextMenuService
	) {
		super();
1162

1163 1164 1165
		this.editPreferenceWidgetForCusorPosition = this._register(this.instantiationService.createInstance(EditPreferenceWidget, editor));
		this.editPreferenceWidgetForMouseMove = this._register(this.instantiationService.createInstance(EditPreferenceWidget, editor));
		this.toggleEditPreferencesForMouseMoveDelayer = new Delayer<void>(75);
1166

1167 1168
		this._register(this.editPreferenceWidgetForCusorPosition.onClick(setting => this.onEditSettingClicked(this.editPreferenceWidgetForCusorPosition)));
		this._register(this.editPreferenceWidgetForMouseMove.onClick(setting => this.onEditSettingClicked(this.editPreferenceWidgetForMouseMove)));
1169

1170 1171
		this._register(this.editPreferenceWidgetForCusorPosition.onMouseOver(setting => this.onMouseOver(this.editPreferenceWidgetForCusorPosition)));
		this._register(this.editPreferenceWidgetForMouseMove.onMouseOver(setting => this.onMouseOver(this.editPreferenceWidgetForMouseMove)));
1172 1173 1174

		this._register(this.editor.onDidChangeCursorPosition(positionChangeEvent => this.onPositionChanged(positionChangeEvent)));
		this._register(this.editor.onMouseMove(mouseMoveEvent => this.onMouseMoved(mouseMoveEvent)));
S
Sandeep Somavarapu 已提交
1175
		this._register(this.editor.onDidChangeConfiguration(() => this.onConfigurationChanged()));
S
Sandeep Somavarapu 已提交
1176 1177
	}

1178
	public render(settingsGroups: ISettingsGroup[]): void {
1179 1180
		this.editPreferenceWidgetForCusorPosition.hide();
		this.editPreferenceWidgetForMouseMove.hide();
1181
		this.settingsGroups = settingsGroups;
S
Sandeep Somavarapu 已提交
1182

1183 1184
		const settings = this.getSettings(this.editor.getPosition().lineNumber);
		if (settings.length) {
1185
			this.showEditPreferencesWidget(this.editPreferenceWidgetForCusorPosition, settings);
S
Sandeep Somavarapu 已提交
1186 1187 1188
		}
	}

1189 1190 1191 1192
	private isDefaultSettings(): boolean {
		return this.masterSettingsModel instanceof DefaultSettingsEditorModel;
	}

S
Sandeep Somavarapu 已提交
1193 1194 1195 1196 1197 1198 1199
	private onConfigurationChanged(): void {
		if (!this.editor.getRawConfiguration().glyphMargin) {
			this.editPreferenceWidgetForCusorPosition.hide();
			this.editPreferenceWidgetForMouseMove.hide();
		}
	}

1200
	private onPositionChanged(positionChangeEvent: editorCommon.ICursorPositionChangedEvent) {
1201
		this.editPreferenceWidgetForMouseMove.hide();
1202 1203
		const settings = this.getSettings(positionChangeEvent.position.lineNumber);
		if (settings.length) {
1204
			this.showEditPreferencesWidget(this.editPreferenceWidgetForCusorPosition, settings);
1205
		} else {
1206
			this.editPreferenceWidgetForCusorPosition.hide();
1207
		}
S
Sandeep Somavarapu 已提交
1208 1209
	}

1210
	private onMouseMoved(mouseMoveEvent: IEditorMouseEvent): void {
S
#17292  
Sandeep Somavarapu 已提交
1211 1212 1213
		const editPreferenceWidget = this.getEditPreferenceWidgetUnderMouse(mouseMoveEvent);
		if (editPreferenceWidget) {
			this.onMouseOver(editPreferenceWidget);
S
Sandeep Somavarapu 已提交
1214 1215
			return;
		}
1216 1217 1218 1219
		this.settingHighlighter.clear();
		this.toggleEditPreferencesForMouseMoveDelayer.trigger(() => this.toggleEidtPreferenceWidgetForMouseMove(mouseMoveEvent));
	}

S
#17292  
Sandeep Somavarapu 已提交
1220 1221 1222
	private getEditPreferenceWidgetUnderMouse(mouseMoveEvent: IEditorMouseEvent): EditPreferenceWidget<ISetting> {
		if (mouseMoveEvent.event.target === this.editPreferenceWidgetForMouseMove.getDomNode()) {
			return this.editPreferenceWidgetForMouseMove;
S
Sandeep Somavarapu 已提交
1223
		}
S
#17292  
Sandeep Somavarapu 已提交
1224 1225 1226 1227 1228
		if (mouseMoveEvent.event.target === this.editPreferenceWidgetForCusorPosition.getDomNode()) {
			return this.editPreferenceWidgetForCusorPosition;
		}
		return null;
	}
S
Sandeep Somavarapu 已提交
1229

1230
	private toggleEidtPreferenceWidgetForMouseMove(mouseMoveEvent: IEditorMouseEvent): void {
1231
		const settings = mouseMoveEvent.target.position ? this.getSettings(mouseMoveEvent.target.position.lineNumber) : null;
1232 1233
		if (settings && settings.length) {
			this.showEditPreferencesWidget(this.editPreferenceWidgetForMouseMove, settings);
1234
		} else {
1235
			this.editPreferenceWidgetForMouseMove.hide();
S
Sandeep Somavarapu 已提交
1236 1237 1238
		}
	}

1239
	private showEditPreferencesWidget(editPreferencesWidget: EditPreferenceWidget<ISetting>, settings: ISetting[]) {
S
Sandeep Somavarapu 已提交
1240 1241 1242
		if (this.editor.getRawConfiguration().glyphMargin) {
			editPreferencesWidget.show(settings[0].valueRange.startLineNumber, settings);
			editPreferencesWidget.getDomNode().title = nls.localize('editTtile', "Edit");
S
Sandeep Somavarapu 已提交
1243 1244
			const editPreferenceWidgetToHide = editPreferencesWidget === this.editPreferenceWidgetForCusorPosition ? this.editPreferenceWidgetForMouseMove : this.editPreferenceWidgetForCusorPosition;
			editPreferenceWidgetToHide.hide();
S
Sandeep Somavarapu 已提交
1245
		}
S
Sandeep Somavarapu 已提交
1246 1247
	}

1248 1249 1250 1251
	private getSettings(lineNumber: number): ISetting[] {
		const configurationMap = this.getConfigurationsMap();
		return this.getSettingsAtLineNumber(lineNumber).filter(setting => {
			let jsonSchema: IJSONSchema = configurationMap[setting.key];
1252
			return jsonSchema && (this.isDefaultSettings() || jsonSchema.type === 'boolean' || jsonSchema.enum);
1253
		});
S
Sandeep Somavarapu 已提交
1254 1255
	}

1256 1257
	private getSettingsAtLineNumber(lineNumber: number): ISetting[] {
		const settings = [];
1258
		for (const group of this.settingsGroups) {
1259 1260 1261
			if (group.range.startLineNumber > lineNumber) {
				break;
			}
1262 1263 1264
			if (lineNumber >= group.range.startLineNumber && lineNumber <= group.range.endLineNumber) {
				for (const section of group.sections) {
					for (const setting of section.settings) {
1265 1266 1267 1268
						if (setting.range.startLineNumber > lineNumber) {
							break;
						}
						if (lineNumber >= setting.range.startLineNumber && lineNumber <= setting.range.endLineNumber) {
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
							if (setting.overrides.length > 0) {
								// Only one level because override settings cannot have override settings
								for (const overrideSetting of setting.overrides) {
									if (lineNumber >= overrideSetting.range.startLineNumber && lineNumber <= overrideSetting.range.endLineNumber) {
										settings.push(overrideSetting);
									}
								}
							} else {
								settings.push(setting);
							}
1279 1280 1281 1282 1283
						}
					}
				}
			}
		}
1284 1285 1286
		return settings;
	}

1287 1288
	private onMouseOver(editPreferenceWidget: EditPreferenceWidget<ISetting>): void {
		this.settingHighlighter.highlight(editPreferenceWidget.preferences[0]);
1289 1290
	}

1291 1292
	private onEditSettingClicked(editPreferenceWidget: EditPreferenceWidget<ISetting>): void {
		const elementPosition = DOM.getDomNodePagePosition(editPreferenceWidget.getDomNode());
1293
		const anchor = { x: elementPosition.left + elementPosition.width, y: elementPosition.top + elementPosition.height + 10 };
1294
		const actions = this.getSettingsAtLineNumber(editPreferenceWidget.getLine()).length === 1 ? this.getActions(editPreferenceWidget.preferences[0], this.getConfigurationsMap()[editPreferenceWidget.preferences[0].key])
1295
			: editPreferenceWidget.preferences.map(setting => new ContextSubMenu(setting.key, this.getActions(setting, this.getConfigurationsMap()[setting.key])));
1296 1297 1298 1299 1300 1301 1302 1303
		this.contextMenuService.showContextMenu({
			getAnchor: () => anchor,
			getActions: () => TPromise.wrap(actions)
		});
	}

	private getConfigurationsMap(): { [qualifiedKey: string]: IJSONSchema } {
		return Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).getConfigurationProperties();
1304 1305 1306
	}

	private getActions(setting: ISetting, jsonSchema: IJSONSchema): IAction[] {
S
Sandeep Somavarapu 已提交
1307 1308 1309 1310 1311
		if (jsonSchema.type === 'boolean') {
			return [<IAction>{
				id: 'truthyValue',
				label: 'true',
				enabled: true,
1312
				run: () => this.updateSetting(setting.key, true, setting)
S
Sandeep Somavarapu 已提交
1313 1314 1315 1316
			}, <IAction>{
				id: 'falsyValue',
				label: 'false',
				enabled: true,
1317
				run: () => this.updateSetting(setting.key, false, setting)
S
Sandeep Somavarapu 已提交
1318 1319 1320 1321 1322 1323
			}];
		}
		if (jsonSchema.enum) {
			return jsonSchema.enum.map(value => {
				return <IAction>{
					id: value,
S
Sandeep Somavarapu 已提交
1324
					label: JSON.stringify(value),
S
Sandeep Somavarapu 已提交
1325
					enabled: true,
1326
					run: () => this.updateSetting(setting.key, value, setting)
S
Sandeep Somavarapu 已提交
1327 1328 1329
				};
			});
		}
1330
		return this.getDefaultActions(setting);
S
Sandeep Somavarapu 已提交
1331
	}
1332

1333
	private getDefaultActions(setting: ISetting): IAction[] {
1334
		const settingInOtherModel = this.otherSettingsModel().getPreference(setting.key);
1335 1336 1337 1338 1339
		if (this.isDefaultSettings()) {
			return [<IAction>{
				id: 'setDefaultValue',
				label: settingInOtherModel ? nls.localize('replaceDefaultValue', "Replace in Settings") : nls.localize('copyDefaultValue', "Copy to Settings"),
				enabled: true,
1340
				run: () => this.updateSetting(setting.key, setting.value, setting)
1341 1342 1343
			}];
		}
		return [];
S
Sandeep Somavarapu 已提交
1344
	}
1345

1346 1347
	private updateSetting(key: string, value: any, source: ISetting): void {
		this._onUpdateSetting.fire({ key, value, source });
1348
	}
S
Sandeep Somavarapu 已提交
1349 1350
}

1351 1352 1353 1354
class SettingHighlighter extends Disposable {

	private fixedHighlighter: RangeHighlightDecorations;
	private volatileHighlighter: RangeHighlightDecorations;
1355
	private highlightedSetting: ISetting;
1356

1357 1358 1359
	constructor(private editor: editorCommon.ICommonCodeEditor, private focusEventEmitter: Emitter<ISetting>, private clearFocusEventEmitter: Emitter<ISetting>,
		@IInstantiationService instantiationService: IInstantiationService
	) {
1360 1361 1362
		super();
		this.fixedHighlighter = this._register(instantiationService.createInstance(RangeHighlightDecorations));
		this.volatileHighlighter = this._register(instantiationService.createInstance(RangeHighlightDecorations));
1363 1364
		this.fixedHighlighter.onHighlghtRemoved(() => this.clearFocusEventEmitter.fire(this.highlightedSetting));
		this.volatileHighlighter.onHighlghtRemoved(() => this.clearFocusEventEmitter.fire(this.highlightedSetting));
1365 1366
	}

S
Sandeep Somavarapu 已提交
1367
	highlight(setting: ISetting, fix: boolean = false) {
1368
		this.highlightedSetting = setting;
1369 1370 1371 1372 1373
		this.volatileHighlighter.removeHighlightRange();
		this.fixedHighlighter.removeHighlightRange();

		const highlighter = fix ? this.fixedHighlighter : this.volatileHighlighter;
		highlighter.highlightRange({
S
Sandeep Somavarapu 已提交
1374 1375
			range: setting.valueRange,
			resource: this.editor.getModel().uri
1376
		}, this.editor);
1377 1378

		this.editor.revealLinesInCenterIfOutsideViewport(setting.valueRange.startLineNumber, setting.valueRange.endLineNumber - 1);
1379
		this.focusEventEmitter.fire(setting);
1380 1381
	}

1382
	clear(fix: boolean = false): void {
1383
		this.volatileHighlighter.removeHighlightRange();
1384 1385
		if (fix) {
			this.fixedHighlighter.removeHighlightRange();
S
Sandeep Somavarapu 已提交
1386
		}
1387
		this.clearFocusEventEmitter.fire(this.highlightedSetting);
1388
	}
S
Sandeep Somavarapu 已提交
1389 1390
}

1391 1392 1393 1394 1395 1396 1397 1398 1399
class UnTrustedWorkspaceSettingsRenderer extends Disposable {

	constructor(private editor: editorCommon.ICommonCodeEditor, private workspaceSettingsEditorModel: SettingsEditorModel,
		@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService,
		@IMarkerService private markerService: IMarkerService
	) {
		super();
	}

1400 1401 1402
	private getMarkerMessage(settingKey): string {
		switch (settingKey) {
			case 'php.validate.executablePath':
K
kieferrm 已提交
1403
				return nls.localize('unsupportedPHPExecutablePathSetting', "This setting must be a User Setting. To configure PHP for the workspace, open a PHP file and click on 'PHP Path' in the status bar.");
1404 1405 1406 1407 1408
			default:
				return nls.localize('unsupportedWorkspaceSetting', "This setting must be a User Setting.");
		}
	}

1409 1410 1411 1412 1413 1414 1415 1416
	public render(): void {
		const untrustedConfigurations = this.configurationService.getUntrustedConfigurations();
		if (untrustedConfigurations.length) {
			const markerData: IMarkerData[] = [];
			for (const untrustedConfiguration of untrustedConfigurations) {
				const setting = this.workspaceSettingsEditorModel.getPreference(untrustedConfiguration);
				if (setting) {
					markerData.push({
K
kieferrm 已提交
1417
						severity: Severity.Warning,
1418 1419 1420 1421
						startLineNumber: setting.keyRange.startLineNumber,
						startColumn: setting.keyRange.startColumn,
						endLineNumber: setting.keyRange.endLineNumber,
						endColumn: setting.keyRange.endColumn,
1422
						message: this.getMarkerMessage(untrustedConfiguration)
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
					});
				}
			}
			this.markerService.changeOne('preferencesEditor', this.workspaceSettingsEditorModel.uri, markerData);
		}
	}

	public dispose(): void {
		this.markerService.remove('preferencesEditor', [this.workspaceSettingsEditorModel.uri]);
		super.dispose();
	}
}

1436
const DefaultSettingsEditorCommand = EditorCommand.bindToContribution<PreferencesEditorContribution<ISetting>>((editor: editorCommon.ICommonCodeEditor) => <PreferencesEditorContribution<ISetting>>editor.getContribution(DefaultSettingsEditorContribution.ID));
S
Sandeep Somavarapu 已提交
1437 1438 1439 1440 1441

CommonEditorRegistry.registerEditorCommand(new DefaultSettingsEditorCommand({
	id: DEFAULT_EDITOR_COMMAND_COLLAPSE_ALL,
	precondition: ContextKeyExpr.and(CONTEXT_DEFAULT_SETTINGS_EDITOR),
	handler: x => (<DefaultSettingsRenderer>x.getPreferencesRenderer()).collapseAll()
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
}));

class StartSearchDefaultSettingsCommand extends Command {

	public runCommand(accessor: ServicesAccessor, args: any): void {
		const defaultPreferencesEditor = this.getDefaultPreferencesEditor(accessor);
		if (defaultPreferencesEditor) {
			defaultPreferencesEditor.focus();
		}
	}

	private getDefaultPreferencesEditor(accessor: ServicesAccessor): DefaultPreferencesEditor {
		const activeEditor = accessor.get(IWorkbenchEditorService).getActiveEditor();
		if (activeEditor instanceof SideBySideEditor) {
			const detailsEditor = activeEditor.getDetailsEditor();
			if (detailsEditor instanceof DefaultPreferencesEditor) {
				return detailsEditor;
			}
		}
		return null;
	}
}

CommonEditorRegistry.registerEditorCommand(new StartSearchDefaultSettingsCommand({
	id: DEFAULT_EDITOR_COMMAND_FOCUS_SEARCH,
	precondition: ContextKeyExpr.and(CONTEXT_DEFAULT_SETTINGS_EDITOR),
	kbOpts: { primary: KeyMod.CtrlCmd | KeyCode.KEY_F }
S
Sandeep Somavarapu 已提交
1469
}));