mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
#16674: Use resource editor input
- Show warnings only once - Open resource editor to show warnings
This commit is contained in:
parent
b4f906798a
commit
8d5ac39056
|
@ -31,11 +31,7 @@
|
|||
"url": "vscode://schemas/keybindings"
|
||||
},
|
||||
{
|
||||
"fileMatch": "vscode://defaultsettings/settings.json#user",
|
||||
"url": "vscode://schemas/settings"
|
||||
},
|
||||
{
|
||||
"fileMatch": "vscode://defaultsettings/settings.json#workspace",
|
||||
"fileMatch": "vscode://defaultsettings/settings.json",
|
||||
"url": "vscode://schemas/settings"
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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';
|
||||
|
||||
const schemaRegistry = Registry.as<JSONContributionRegistry.IJSONContributionRegistry>(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 this.preferencesService.createDefaultPreferencesEditorModel(uri)
|
||||
.then(preferencesModel => {
|
||||
if (preferencesModel) {
|
||||
let mode = this.modeService.getOrCreateMode('json');
|
||||
return TPromise.as(this.modelService.createModel(preferencesModel.content, mode, uri));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
|
|||
|
||||
interface ISerializedDefaultPreferencesEditorInput {
|
||||
resource: string;
|
||||
isSettings: boolean;
|
||||
}
|
||||
|
||||
// Register Editor Input Factory for Default Preferences Input
|
||||
|
@ -46,7 +45,7 @@ class DefaultPreferencesEditorInputFactory implements IEditorInputFactory {
|
|||
public serialize(editorInput: EditorInput): string {
|
||||
const input = <DefaultPreferencesEditorInput>editorInput;
|
||||
|
||||
const serialized: ISerializedDefaultPreferencesEditorInput = { resource: input.getResource().toString(), isSettings: input.isSettings };
|
||||
const serialized: ISerializedDefaultPreferencesEditorInput = { resource: input.getResource().toString() };
|
||||
|
||||
return JSON.stringify(serialized);
|
||||
}
|
||||
|
@ -54,7 +53,7 @@ class DefaultPreferencesEditorInputFactory implements IEditorInputFactory {
|
|||
public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput {
|
||||
const deserialized: ISerializedDefaultPreferencesEditorInput = JSON.parse(serializedEditorInput);
|
||||
|
||||
return instantiationService.createInstance(DefaultPreferencesEditorInput, URI.parse(deserialized.resource), deserialized.isSettings);
|
||||
return instantiationService.createInstance(DefaultPreferencesEditorInput, URI.parse(deserialized.resource));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ 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 { StringEditorModel } from 'vs/workbench/common/editor/stringEditorModel';
|
||||
import { IEditorModel } from 'vs/platform/editor/common/editor';
|
||||
import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel';
|
||||
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
|
||||
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
|
||||
|
@ -48,6 +48,7 @@ import { IEventService } from 'vs/platform/event/common/event';
|
|||
import { IMessageService } from 'vs/platform/message/common/message';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
|
||||
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
|
||||
|
||||
// Ignore following contributions
|
||||
import { FoldingController } from 'vs/editor/contrib/folding/browser/folding';
|
||||
|
@ -55,77 +56,45 @@ import { FindController } from 'vs/editor/contrib/find/browser/find';
|
|||
import { SelectionHighlighter } from 'vs/editor/contrib/find/common/findController';
|
||||
|
||||
|
||||
export class DefaultPreferencesEditorInput extends EditorInput {
|
||||
export class DefaultPreferencesEditorInput extends ResourceEditorInput {
|
||||
|
||||
public static ID = 'workbench.editorinputs.defaultpreferences';
|
||||
|
||||
private editorModel: IEditorModel;
|
||||
private _willDispose = new Emitter<void>();
|
||||
public willDispose: Event<void> = this._willDispose.event;
|
||||
|
||||
constructor(private _defaultPreferencesResource: URI, private _isSettingsInput: boolean,
|
||||
@IPreferencesService private preferencesService: IPreferencesService,
|
||||
@IInstantiationService private instantiationService: IInstantiationService
|
||||
constructor(resource: URI, @ITextModelResolverService textModelResolverService: ITextModelResolverService
|
||||
) {
|
||||
super();
|
||||
super(nls.localize('settingsEditorName', "Default Settings"), '', resource, textModelResolverService);
|
||||
}
|
||||
|
||||
get isSettings(): boolean {
|
||||
return this._isSettingsInput;
|
||||
}
|
||||
|
||||
getName(): string {
|
||||
return this._isSettingsInput ? nls.localize('settingsEditorName', "Default Settings") : nls.localize('keybindingsEditorName', "Default Keyboard Shortcuts");
|
||||
getResource(): URI {
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
getTypeId(): string {
|
||||
return DefaultPreferencesEditorInput.ID;
|
||||
}
|
||||
|
||||
getResource(): URI {
|
||||
return this._defaultPreferencesResource;
|
||||
}
|
||||
|
||||
supportsSplitEditor(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
resolve(): TPromise<IEditorModel> {
|
||||
return this.getOrCreateEditorModel();
|
||||
}
|
||||
|
||||
matches(other: any): boolean {
|
||||
if (!super.matches(other)) {
|
||||
return false;
|
||||
}
|
||||
if (!(other instanceof DefaultPreferencesEditorInput)) {
|
||||
return false;
|
||||
}
|
||||
if (this._defaultPreferencesResource.fsPath !== other._defaultPreferencesResource.fsPath) {
|
||||
return false;
|
||||
}
|
||||
if (this._isSettingsInput !== other._isSettingsInput) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._willDispose.fire();
|
||||
this._willDispose.dispose();
|
||||
if (this.editorModel) {
|
||||
this.editorModel.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private getOrCreateEditorModel(): TPromise<IEditorModel> {
|
||||
if (this.editorModel) {
|
||||
return TPromise.as(this.editorModel);
|
||||
}
|
||||
return this.preferencesService.createDefaultPreferencesEditorModel(this.getResource())
|
||||
.then(preferencesEditorModel => {
|
||||
this.editorModel = this.instantiationService.createInstance(StringEditorModel, preferencesEditorModel.content, 'json', this.getResource());
|
||||
return this.editorModel;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class DefaultPreferencesEditor extends BaseTextEditor {
|
||||
|
@ -172,7 +141,7 @@ export class DefaultPreferencesEditor extends BaseTextEditor {
|
|||
protected getCodeEditorOptions(): editorCommon.IEditorOptions {
|
||||
const options = super.getCodeEditorOptions();
|
||||
options.readOnly = true;
|
||||
if (this.input && (<DefaultPreferencesEditorInput>this.input).isSettings) {
|
||||
if (this.input) {
|
||||
options.lineNumbers = 'off';
|
||||
options.renderLineHighlight = 'none';
|
||||
options.scrollBeyondLastLine = false;
|
||||
|
@ -202,7 +171,7 @@ export class DefaultPreferencesEditor extends BaseTextEditor {
|
|||
}
|
||||
|
||||
public focus(): void {
|
||||
if (this.input && (<DefaultPreferencesEditorInput>this.input).isSettings) {
|
||||
if (this.input) {
|
||||
this.defaultSettingHeaderWidget.focus();
|
||||
} else {
|
||||
super.focus();
|
||||
|
@ -212,7 +181,7 @@ export class DefaultPreferencesEditor extends BaseTextEditor {
|
|||
private updateInput(): TPromise<void> {
|
||||
return this.input.resolve()
|
||||
.then(editorModel => editorModel.load())
|
||||
.then(editorModel => this.getControl().setModel((<StringEditorModel>editorModel).textEditorModel));
|
||||
.then(editorModel => this.getControl().setModel((<ResourceEditorModel>editorModel).textEditorModel));
|
||||
}
|
||||
|
||||
private filterPreferences(filter: string) {
|
||||
|
@ -276,7 +245,9 @@ class DefaultPreferencesCodeEditor extends CodeEditor {
|
|||
protected _getContributions(): IEditorContributionCtor[] {
|
||||
let contributions = super._getContributions();
|
||||
let skipContributions = [FoldingController.prototype, SelectionHighlighter.prototype, FindController.prototype];
|
||||
return contributions.filter(c => skipContributions.indexOf(c.prototype) === -1);
|
||||
contributions.filter(c => skipContributions.indexOf(c.prototype) === -1);
|
||||
contributions.push(DefaultSettingsEditorContribution);
|
||||
return contributions;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,15 +256,14 @@ export interface IPreferencesRenderer {
|
|||
dispose();
|
||||
}
|
||||
|
||||
@editorContribution
|
||||
export class PreferencesEditorContribution extends Disposable implements editorCommon.IEditorContribution {
|
||||
export abstract class PreferencesEditorContribution extends Disposable implements editorCommon.IEditorContribution {
|
||||
|
||||
static ID: string = 'editor.contrib.preferences';
|
||||
private preferencesRenderer: IPreferencesRenderer;
|
||||
|
||||
constructor(private editor: ICodeEditor,
|
||||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
@IPreferencesService private preferencesService: IPreferencesService
|
||||
constructor(protected editor: ICodeEditor,
|
||||
@IInstantiationService protected instantiationService: IInstantiationService,
|
||||
@IPreferencesService protected preferencesService: IPreferencesService
|
||||
) {
|
||||
super();
|
||||
this._register(editor.onDidChangeModel(() => this.onModelChanged()));
|
||||
|
@ -323,15 +293,7 @@ export class PreferencesEditorContribution extends Disposable implements editorC
|
|||
return this.preferencesRenderer;
|
||||
}
|
||||
|
||||
private createPreferencesRenderer(editorModel: IPreferencesEditorModel): IPreferencesRenderer {
|
||||
if (editorModel instanceof DefaultSettingsEditorModel) {
|
||||
return this.instantiationService.createInstance(DefaultSettingsRenderer, this.editor, editorModel);
|
||||
}
|
||||
if (editorModel instanceof SettingsEditorModel) {
|
||||
return this.instantiationService.createInstance(SettingsRenderer, this.editor, editorModel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
protected abstract createPreferencesRenderer(editorModel: IPreferencesEditorModel): IPreferencesRenderer
|
||||
|
||||
private disposePreferencesRenderer() {
|
||||
if (this.preferencesRenderer) {
|
||||
|
@ -346,6 +308,25 @@ export class PreferencesEditorContribution extends Disposable implements editorC
|
|||
}
|
||||
}
|
||||
|
||||
export class DefaultSettingsEditorContribution extends PreferencesEditorContribution implements editorCommon.IEditorContribution {
|
||||
protected createPreferencesRenderer(editorModel: IPreferencesEditorModel): IPreferencesRenderer {
|
||||
if (editorModel instanceof DefaultSettingsEditorModel) {
|
||||
return this.instantiationService.createInstance(DefaultSettingsRenderer, this.editor, editorModel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@editorContribution
|
||||
export class SettingsEditorContribution extends PreferencesEditorContribution implements editorCommon.IEditorContribution {
|
||||
protected createPreferencesRenderer(editorModel: IPreferencesEditorModel): IPreferencesRenderer {
|
||||
if (editorModel instanceof SettingsEditorModel) {
|
||||
return this.instantiationService.createInstance(SettingsRenderer, this.editor, editorModel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export class SettingsRenderer extends Disposable implements IPreferencesRenderer {
|
||||
|
||||
private copySettingActionRenderer: CopySettingActionRenderer;
|
||||
|
|
|
@ -50,7 +50,10 @@ export class PreferencesService extends Disposable implements IPreferencesServic
|
|||
|
||||
_serviceBrand: any;
|
||||
|
||||
private defaultEditorModels: Map<URI, IPreferencesEditorModel>;
|
||||
// TODO:@sandy merge these models into editor inputs by extending resource editor model
|
||||
private defaultPreferencesEditorModels: Map<URI, IPreferencesEditorModel>;
|
||||
private defaultSettingsEditorInputForUser: DefaultPreferencesEditorInput;
|
||||
private defaultSettingsEditorInputForWorkspace: DefaultPreferencesEditorInput;
|
||||
|
||||
constructor(
|
||||
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
|
||||
|
@ -69,11 +72,11 @@ export class PreferencesService extends Disposable implements IPreferencesServic
|
|||
@IExtensionService private extensionService: IExtensionService
|
||||
) {
|
||||
super();
|
||||
this.defaultEditorModels = new Map<URI, IPreferencesEditorModel>();
|
||||
this.defaultPreferencesEditorModels = new Map<URI, IPreferencesEditorModel>();
|
||||
}
|
||||
|
||||
createDefaultPreferencesEditorModel(uri: URI): TPromise<IPreferencesEditorModel> {
|
||||
const editorModel = this.defaultEditorModels.get(uri);
|
||||
const editorModel = this.defaultPreferencesEditorModels.get(uri);
|
||||
if (editorModel) {
|
||||
return TPromise.as(editorModel);
|
||||
}
|
||||
|
@ -83,14 +86,14 @@ export class PreferencesService extends Disposable implements IPreferencesServic
|
|||
.then(result => {
|
||||
const mostCommonSettings = result[1];
|
||||
const model = this.instantiationService.createInstance(DefaultSettingsEditorModel, uri, mostCommonSettings);
|
||||
this.defaultEditorModels.set(uri, model);
|
||||
this.defaultPreferencesEditorModels.set(uri, model);
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
if (PreferencesService.DEFAULT_KEY_BINDINGS_URI.fsPath === uri.fsPath) {
|
||||
const model = this.instantiationService.createInstance(DefaultKeybindingsEditorModel, uri);
|
||||
this.defaultEditorModels.set(uri, model);
|
||||
this.defaultPreferencesEditorModels.set(uri, model);
|
||||
return TPromise.wrap(model);
|
||||
}
|
||||
|
||||
|
@ -98,7 +101,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
|
|||
}
|
||||
|
||||
public resolvePreferencesEditorModel(uri: URI): TPromise<IPreferencesEditorModel> {
|
||||
const model = this.defaultEditorModels.get(uri);
|
||||
const model = this.defaultPreferencesEditorModels.get(uri);
|
||||
if (model) {
|
||||
return TPromise.wrap(model);
|
||||
}
|
||||
|
@ -197,10 +200,6 @@ export class PreferencesService extends Disposable implements IPreferencesServic
|
|||
return null;
|
||||
}
|
||||
|
||||
private getDefaultSettingsURI(configurationTarget: ConfigurationTarget): URI {
|
||||
return URI.from({ scheme: PreferencesService.DEFAULT_SETTINGS_URI.scheme, authority: PreferencesService.DEFAULT_SETTINGS_URI.authority, path: PreferencesService.DEFAULT_SETTINGS_URI.path, fragment: ConfigurationTarget.USER === configurationTarget ? 'user' : 'workspace' });
|
||||
}
|
||||
|
||||
private promptToOpenWorkspaceSettings() {
|
||||
this.choiceService.choose(Severity.Info, nls.localize('workspaceHasSettings', "The currently opened folder contains workspace settings that may override user settings"),
|
||||
[nls.localize('openWorkspaceSettings', "Open Workspace Settings"), nls.localize('neverShowAgain', "Don't show again"), nls.localize('close', "Close")]
|
||||
|
@ -223,13 +222,27 @@ export class PreferencesService extends Disposable implements IPreferencesServic
|
|||
const openDefaultSettings = !!this.configurationService.getConfiguration<IWorkbenchSettingsConfiguration>().workbench.settings.openDefaultSettings;
|
||||
if (openDefaultSettings) {
|
||||
const emptySettingsContents = this.getEmptyEditableSettingsContent(configurationTarget);
|
||||
const defaultSettingsResource = this.getDefaultSettingsURI(configurationTarget);
|
||||
const settingsResource = this.getEditableSettingsURI(configurationTarget);
|
||||
return this.openTwoEditors(this.instantiationService.createInstance(DefaultPreferencesEditorInput, defaultSettingsResource, true), settingsResource, emptySettingsContents).then(() => null);
|
||||
return this.openTwoEditors(this.getDefaultSettingsEditorInput(configurationTarget), settingsResource, emptySettingsContents).then(() => null);
|
||||
}
|
||||
return this.openEditableSettings(configurationTarget).then(() => null);
|
||||
}
|
||||
|
||||
private getDefaultSettingsEditorInput(configurationTarget: ConfigurationTarget): DefaultPreferencesEditorInput {
|
||||
switch (configurationTarget) {
|
||||
case ConfigurationTarget.USER:
|
||||
if (!this.defaultSettingsEditorInputForUser) {
|
||||
this.defaultSettingsEditorInputForUser = this._register(this.instantiationService.createInstance(DefaultPreferencesEditorInput, PreferencesService.DEFAULT_SETTINGS_URI));
|
||||
}
|
||||
return this.defaultSettingsEditorInputForUser;
|
||||
case ConfigurationTarget.WORKSPACE:
|
||||
if (!this.defaultSettingsEditorInputForWorkspace) {
|
||||
this.defaultSettingsEditorInputForWorkspace = this._register(this.instantiationService.createInstance(DefaultPreferencesEditorInput, PreferencesService.DEFAULT_SETTINGS_URI));
|
||||
}
|
||||
return this.defaultSettingsEditorInputForWorkspace;
|
||||
}
|
||||
}
|
||||
|
||||
private openTwoEditors(leftHandDefaultInput: EditorInput, editableResource: URI, defaultEditableContents: string): TPromise<IEditor> {
|
||||
// Create as needed and open in editor
|
||||
return this.createIfNotExists(editableResource, defaultEditableContents).then(() => {
|
||||
|
@ -300,4 +313,9 @@ export class PreferencesService extends Disposable implements IPreferencesServic
|
|||
'files.associations'
|
||||
]);
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.defaultPreferencesEditorModels.clear();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue