提交 6126d34c 编写于 作者: S Sandeep Somavarapu

Use resource content providers for preferences

上级 9b135130
......@@ -13,6 +13,7 @@ import JSONContributionRegistry = require('vs/platform/jsonschemas/common/jsonCo
import { Registry } from 'vs/platform/platform';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences';
let schemaRegistry = <JSONContributionRegistry.IJSONContributionRegistry>Registry.as(JSONContributionRegistry.Extensions.JSONContribution);
......@@ -21,6 +22,7 @@ export class WorkbenchContentProvider implements IWorkbenchContribution {
constructor(
@IModelService private modelService: IModelService,
@ITextModelResolverService private textModelResolverService: ITextModelResolverService,
@IPreferencesService private preferencesService: IPreferencesService,
@IModeService private modeService: IModeService
) {
this.start();
......@@ -45,7 +47,14 @@ export class WorkbenchContentProvider implements IWorkbenchContribution {
return TPromise.as(this.modelService.createModel(modelContent, mode, uri));
}
}
return null;
return this.preferencesService.resolvePreferencesEditorModel(uri)
.then(preferencesModel => {
if (preferencesModel) {
let mode = this.modeService.getOrCreateMode('json');
return TPromise.as(this.modelService.createModel(preferencesModel.content, mode, uri));
}
return null;
});
}
});
}
......
......@@ -13,7 +13,7 @@ import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { DefaultSettingsEditor, DefaultSettingsInput, DefaultKeybindingsInput } from 'vs/workbench/parts/preferences/browser/preferencesEditor';
import { DefaultPreferencesEditor, DefaultSettingsInput, DefaultKeybindingsInput } from 'vs/workbench/parts/preferences/browser/preferencesEditor';
import { OpenGlobalSettingsAction, OpenGlobalKeybindingsAction, OpenWorkspaceSettingsAction } from 'vs/workbench/parts/preferences/browser/preferencesActions';
import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/parts/preferences/browser/preferencesService';
......@@ -22,10 +22,10 @@ registerSingleton(IPreferencesService, PreferencesService);
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerEditor(
new EditorDescriptor(
DefaultSettingsEditor.ID,
DefaultPreferencesEditor.ID,
nls.localize('defaultSettingsEditor', "Default Settings Editor"),
'vs/workbench/parts/preferences/browser/preferencesEditor',
'DefaultSettingsEditor'
'DefaultPreferencesEditor'
),
[
new SyncDescriptor(DefaultSettingsInput),
......
......@@ -15,18 +15,19 @@ import Event, { Emitter } from 'vs/base/common/event';
import { LinkedMap as Map } from 'vs/base/common/map';
import { Registry } from 'vs/platform/platform';
import { EditorOptions, EditorInput, } from 'vs/workbench/common/editor';
import { StringEditorInput } from 'vs/workbench/common/editor/stringEditorInput';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { StringEditor } from 'vs/workbench/browser/parts/editor/stringEditor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IFoldingController, ID as FoldingContributionId } from 'vs/editor/contrib/folding/common/folding';
import { IPreferencesService, ISettingsGroup, ISetting } from 'vs/workbench/parts/preferences/common/preferences';
import { IPreferencesService, ISettingsGroup, ISetting, ISettingsEditorModel, IKeybindingsEditorModel } from 'vs/workbench/parts/preferences/common/preferences';
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
import { ICodeEditor, IEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
export class AbstractSettingsInput extends StringEditorInput {
export class DefaultPreferencesInput extends ResourceEditorInput {
private _willDispose = new Emitter<void>();
public willDispose: Event<void> = this._willDispose.event;
......@@ -34,17 +35,14 @@ export class AbstractSettingsInput extends StringEditorInput {
constructor(
name: string,
description: string,
value: string,
private _resource: URI,
modeId: string,
singleton: boolean,
@IInstantiationService instantiationService: IInstantiationService
resource: URI,
@ITextModelResolverService textModelResolverService: ITextModelResolverService
) {
super(name, description, value, modeId, singleton, instantiationService);
super(name, description, resource, textModelResolverService);
}
public getResource(): URI {
return this._resource;
return this.resource;
}
public dispose() {
......@@ -54,41 +52,39 @@ export class AbstractSettingsInput extends StringEditorInput {
}
}
export class DefaultSettingsInput extends AbstractSettingsInput {
export class DefaultSettingsInput extends DefaultPreferencesInput {
private static INSTANCE: DefaultSettingsInput;
public static getInstance(instantiationService: IInstantiationService, preferencesService: IPreferencesService): DefaultSettingsInput {
public static getInstance(instantiationService: IInstantiationService, defaultSettings: ISettingsEditorModel): DefaultSettingsInput {
if (!DefaultSettingsInput.INSTANCE) {
const defaultSettings = preferencesService.defaultSettings;
DefaultSettingsInput.INSTANCE = instantiationService.createInstance(DefaultSettingsInput, nls.localize('defaultName', "Default Settings"), null, defaultSettings.content, defaultSettings.uri, 'application/json', false);
DefaultSettingsInput.INSTANCE = instantiationService.createInstance(DefaultSettingsInput, nls.localize('defaultName', "Default Settings"), null, defaultSettings.uri);
}
return DefaultSettingsInput.INSTANCE;
}
}
export class DefaultKeybindingsInput extends AbstractSettingsInput {
export class DefaultKeybindingsInput extends DefaultPreferencesInput {
private static INSTANCE: DefaultKeybindingsInput;
public static getInstance(instantiationService: IInstantiationService, preferencesService: IPreferencesService): DefaultKeybindingsInput {
public static getInstance(instantiationService: IInstantiationService, defaultKeybindings: IKeybindingsEditorModel): DefaultKeybindingsInput {
if (!DefaultKeybindingsInput.INSTANCE) {
const defaultKeybindings = preferencesService.defaultKeybindings;
DefaultKeybindingsInput.INSTANCE = instantiationService.createInstance(DefaultKeybindingsInput, nls.localize('defaultKeybindings', "Default Keyboard Shortcuts"), null, defaultKeybindings.content, defaultKeybindings.uri, 'application/json', false);
DefaultKeybindingsInput.INSTANCE = instantiationService.createInstance(DefaultKeybindingsInput, nls.localize('defaultKeybindings', "Default Keyboard Shortcuts"), null, defaultKeybindings.uri);
}
return DefaultKeybindingsInput.INSTANCE;
}
}
export class DefaultSettingsEditor extends StringEditor {
export class DefaultPreferencesEditor extends StringEditor {
public static ID = 'workbench.editors.defaultSettingsEditor';
public static ID = 'workbench.editors.defaultPrefrencesEditor';
private static VIEW_STATE: Map<URI, editorCommon.IEditorViewState> = new Map<URI, editorCommon.IEditorViewState>();
private inputDisposeListener;
public getId(): string {
return DefaultSettingsEditor.ID;
return DefaultPreferencesEditor.ID;
}
public setInput(input: EditorInput, options: EditorOptions): TPromise<void> {
......@@ -97,7 +93,7 @@ export class DefaultSettingsEditor extends StringEditor {
}
public clearInput(): void {
this.saveState(<AbstractSettingsInput>this.input);
this.saveState(<DefaultPreferencesInput>this.input);
if (this.inputDisposeListener) {
this.inputDisposeListener.dispose();
}
......@@ -105,7 +101,7 @@ export class DefaultSettingsEditor extends StringEditor {
}
protected restoreViewState(input: EditorInput) {
const viewState = DefaultSettingsEditor.VIEW_STATE.get((<AbstractSettingsInput>input).getResource());
const viewState = DefaultPreferencesEditor.VIEW_STATE.get((<DefaultPreferencesInput>input).getResource());
if (viewState) {
this.getControl().restoreViewState(viewState);
} else if (input instanceof DefaultSettingsInput) {
......@@ -113,14 +109,14 @@ export class DefaultSettingsEditor extends StringEditor {
}
}
private saveState(input: AbstractSettingsInput) {
private saveState(input: DefaultPreferencesInput) {
const state = this.getControl().saveViewState();
if (state) {
const resource = input.getResource();
if (DefaultSettingsEditor.VIEW_STATE.has(resource)) {
DefaultSettingsEditor.VIEW_STATE.delete(resource);
if (DefaultPreferencesEditor.VIEW_STATE.has(resource)) {
DefaultPreferencesEditor.VIEW_STATE.delete(resource);
}
DefaultSettingsEditor.VIEW_STATE.set(resource, state);
DefaultPreferencesEditor.VIEW_STATE.set(resource, state);
}
}
......@@ -133,8 +129,8 @@ export class DefaultSettingsEditor extends StringEditor {
if (this.inputDisposeListener) {
this.inputDisposeListener.dispose();
}
if (input instanceof AbstractSettingsInput) {
this.inputDisposeListener = (<AbstractSettingsInput>input).willDispose(() => this.saveState(<AbstractSettingsInput>input));
if (input instanceof DefaultPreferencesInput) {
this.inputDisposeListener = (<DefaultPreferencesInput>input).willDispose(() => this.saveState(<DefaultPreferencesInput>input));
}
}
}
......
......@@ -11,7 +11,6 @@ import { Delayer } from 'vs/base/common/async';
import { Disposable } from 'vs/base/common/lifecycle';
import { parseTree, findNodeAtLocation } from 'vs/base/common/json';
import { asFileEditorInput } from 'vs/workbench/common/editor';
import { StringEditorInput } from 'vs/workbench/common/editor/stringEditorInput';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceConfigurationService, WORKSPACE_CONFIG_DEFAULT_PATH } from 'vs/workbench/services/configuration/common/configuration';
......@@ -25,13 +24,10 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IConfigurationEditingService, ConfigurationTarget, IConfigurationValue } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IPreferencesService, IDefaultSettings, IDefaultKeybindings } from 'vs/workbench/parts/preferences/common/preferences';
import { IPreferencesService, IPreferencesEditorModel, ISettingsEditorModel, IKeybindingsEditorModel } from 'vs/workbench/parts/preferences/common/preferences';
import { DefaultSettings, DefaultKeybindings } from 'vs/workbench/parts/preferences/common/preferencesModels';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ITextModelContentProvider } from 'vs/editor/common/services/resolverService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { DefaultSettingsInput, DefaultKeybindingsInput } from 'vs/workbench/parts/preferences/browser/preferencesEditor';
import { DefaultSettingsInput, DefaultKeybindingsInput, DefaultPreferencesInput } from 'vs/workbench/parts/preferences/browser/preferencesEditor';
const SETTINGS_INFO_IGNORE_KEY = 'settings.workspace.info.ignore';
......@@ -50,8 +46,8 @@ export class PreferencesService extends Disposable implements IPreferencesServic
private configurationTarget: ConfigurationTarget = null;
private _defaultSettings: IDefaultSettings;
private _defaultKeybindings: IDefaultKeybindings;
private _defaultSettings: ISettingsEditorModel;
private _defaultKeybindings: IKeybindingsEditorModel;
constructor(
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
......@@ -82,20 +78,30 @@ export class PreferencesService extends Disposable implements IPreferencesServic
}));
}
public get defaultSettings(): IDefaultSettings {
public get defaultSettings(): ISettingsEditorModel {
if (!this._defaultSettings) {
this._defaultSettings = this.instantiationService.createInstance(DefaultSettings);
}
return this._defaultSettings;
}
public get defaultKeybindings(): IDefaultKeybindings {
public get defaultKeybindings(): IKeybindingsEditorModel {
if (!this._defaultKeybindings) {
this._defaultKeybindings = this.instantiationService.createInstance(DefaultKeybindings);
}
return this._defaultKeybindings;
}
resolvePreferencesEditorModel(uri: URI): TPromise<IPreferencesEditorModel> {
if (this._defaultSettings.uri.fsPath === uri.fsPath) {
return TPromise.wrap(this._defaultSettings);
}
if (this._defaultKeybindings.uri.fsPath === uri.fsPath) {
return TPromise.wrap(this._defaultKeybindings);
}
return TPromise.wrap(null);
}
openGlobalSettings(): TPromise<void> {
if (this.configurationService.hasWorkspaceConfiguration() && !this.storageService.getBoolean(SETTINGS_INFO_IGNORE_KEY, StorageScope.WORKSPACE)) {
this.promptToOpenWorkspaceSettings();
......@@ -114,7 +120,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
openGlobalKeybindingSettings(): TPromise<void> {
const emptyContents = '// ' + nls.localize('emptyKeybindingsHeader', "Place your key bindings in this file to overwrite the defaults") + '\n[\n]';
return this.openTwoEditors(DefaultKeybindingsInput.getInstance(this.instantiationService, this), URI.file(this.environmentService.appKeybindingsPath), emptyContents).then(() => null);
return this.openTwoEditors(DefaultKeybindingsInput.getInstance(this.instantiationService, this.defaultKeybindings), URI.file(this.environmentService.appKeybindingsPath), emptyContents).then(() => null);
}
openEditableSettings(configurationTarget: ConfigurationTarget, showVisibleEditor: boolean = false): TPromise<IEditor> {
......@@ -202,12 +208,12 @@ export class PreferencesService extends Disposable implements IPreferencesServic
if (openDefaultSettings) {
const emptySettingsContents = this.getEmptyEditableSettingsContent(configurationTarget);
const settingsResource = this.getEditableSettingsURI(configurationTarget);
return this.openTwoEditors(DefaultSettingsInput.getInstance(this.instantiationService, this), settingsResource, emptySettingsContents).then(() => null);
return this.openTwoEditors(DefaultSettingsInput.getInstance(this.instantiationService, this.defaultSettings), settingsResource, emptySettingsContents).then(() => null);
}
return this.openEditableSettings(configurationTarget).then(() => null);
}
private openTwoEditors(leftHandDefaultInput: StringEditorInput, editableResource: URI, defaultEditableContents: string): TPromise<IEditor[]> {
private openTwoEditors(leftHandDefaultInput: DefaultPreferencesInput, editableResource: URI, defaultEditableContents: string): TPromise<IEditor[]> {
// Create as needed and open in editor
return this.createIfNotExists(editableResource, defaultEditableContents).then(() => {
return this.editorService.createInput({ resource: editableResource }).then(typedRightHandEditableInput => {
......@@ -252,31 +258,4 @@ export class PreferencesService extends Disposable implements IPreferencesServic
endColumn: position.column + node.length
};
}
}
export class SettingsContentProvider implements ITextModelContentProvider {
constructor(
@IPreferencesService private preferencesService: IPreferencesService,
@IModelService private modelService: IModelService,
@IModeService private modeService: IModeService
) {
}
public provideTextContent(uri: URI): TPromise<editorCommon.IModel> {
if (uri.scheme !== 'vscode') {
return null;
}
const defaultSettings = this.preferencesService.defaultSettings;
if (defaultSettings.uri.fsPath === uri.fsPath) {
let mode = this.modeService.getOrCreateMode('application/json');
return TPromise.as(this.modelService.createModel(defaultSettings.content, mode, uri));
}
const defaultKeybindings = this.preferencesService.defaultKeybindings;
if (defaultKeybindings.uri.fsPath === uri.fsPath) {
let mode = this.modeService.getOrCreateMode('application/json');
return TPromise.as(this.modelService.createModel(defaultKeybindings.content, mode, uri));
}
return null;
}
}
\ No newline at end of file
......@@ -29,15 +29,16 @@ export interface ISetting {
description: string;
}
export interface IDefaultSettings {
export interface IPreferencesEditorModel {
uri: URI;
content: string;
}
export interface ISettingsEditorModel extends IPreferencesEditorModel {
settingsGroups: ISettingsGroup[];
}
export interface IDefaultKeybindings {
uri: URI;
content: string;
export interface IKeybindingsEditorModel extends IPreferencesEditorModel {
}
export const IPreferencesService = createDecorator<IPreferencesService>('preferencesService');
......@@ -45,11 +46,13 @@ export const IPreferencesService = createDecorator<IPreferencesService>('prefere
export interface IPreferencesService {
_serviceBrand: any;
defaultSettings: IDefaultSettings;
defaultKeybindings: IDefaultKeybindings;
defaultSettings: ISettingsEditorModel;
defaultKeybindings: IKeybindingsEditorModel;
resolvePreferencesEditorModel(uri: URI): TPromise<IPreferencesEditorModel>;
openGlobalSettings(): TPromise<void>;
openWorkspaceSettings(): TPromise<void>;
openGlobalKeybindingSettings(): TPromise<void>;
copyConfiguration(configurationValue: IConfigurationValue): void;
}
}
\ No newline at end of file
......@@ -9,11 +9,11 @@ import * as strings from 'vs/base/common/strings';
import URI from 'vs/base/common/uri';
import { Registry } from 'vs/platform/platform';
import { IConfigurationNode, IConfigurationRegistry, Extensions } from 'vs/platform/configuration/common/configurationRegistry';
import { IDefaultSettings, IDefaultKeybindings, ISettingsGroup, ISetting } from 'vs/workbench/parts/preferences/common/preferences';
import { ISettingsEditorModel, IKeybindingsEditorModel, ISettingsGroup, ISetting } from 'vs/workbench/parts/preferences/common/preferences';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
export class DefaultSettings implements IDefaultSettings {
export class DefaultSettings implements ISettingsEditorModel {
private _uri: URI = URI.from({ scheme: network.Schemas.vscode, authority: 'defaultsettings', path: '/settings.json' });
private indent: string;
......@@ -148,7 +148,7 @@ export class DefaultSettings implements IDefaultSettings {
}
}
export class DefaultKeybindings implements IDefaultKeybindings {
export class DefaultKeybindings implements IKeybindingsEditorModel {
private _uri: URI = URI.from({ scheme: network.Schemas.vscode, authority: 'defaultsettings', path: '/keybindings.json' });
private _content: string;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册