提交 deb2f763 编写于 作者: A Alex Dima

Introduce and adopt ICodeEditorWidgetOptions

上级 e95910ad
......@@ -41,7 +41,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl';
import { IEditorContributionCtor, EditorAction, EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
import { IEditorContributionCtor, EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
import { InternalEditorAction } from 'vs/editor/common/editorAction';
import { ICommandDelegate } from 'vs/editor/browser/view/viewController';
......@@ -52,6 +52,26 @@ import { ClassName } from 'vs/editor/common/model/intervalTree';
let EDITOR_ID = 0;
export interface ICodeEditorWidgetOptions {
/**
* Is this a simple widget (not a real code editor) ?
* Defaults to false.
*/
isSimpleWidget?: boolean;
/**
* Contributions to instantiate.
* Defaults to EditorExtensionsRegistry.getEditorContributions().
*/
contributions?: IEditorContributionCtor[];
/**
* Telemetry data associated with this CodeEditorWidget.
* Defaults to null.
*/
telemetryData?: object;
}
export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeEditor {
//#region Eventing
......@@ -143,6 +163,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
//#endregion
public readonly isSimpleWidget: boolean;
private readonly _telemetryData: object;
private readonly domElement: HTMLElement;
private readonly id: number;
......@@ -182,7 +203,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
constructor(
domElement: HTMLElement,
options: editorOptions.IEditorOptions,
isSimpleWidget: boolean,
codeEditorWidgetOptions: ICodeEditorWidgetOptions,
@IInstantiationService instantiationService: IInstantiationService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@ICommandService commandService: ICommandService,
......@@ -195,7 +216,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
this.id = (++EDITOR_ID);
this._decorationTypeKeysToIds = {};
this._decorationTypeSubtypes = {};
this.isSimpleWidget = isSimpleWidget;
this.isSimpleWidget = codeEditorWidgetOptions.isSimpleWidget || false;
this._telemetryData = codeEditorWidgetOptions.telemetryData || null;
options = options || {};
this._configuration = this._register(this._createConfiguration(options));
......@@ -230,7 +252,10 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
this.contentWidgets = {};
this.overlayWidgets = {};
let contributions = this._getContributions();
let contributions: IEditorContributionCtor[] = codeEditorWidgetOptions.contributions;
if (!Array.isArray(contributions)) {
contributions = EditorExtensionsRegistry.getEditorContributions();
}
for (let i = 0, len = contributions.length; i < len; i++) {
let ctor = contributions[i];
try {
......@@ -241,7 +266,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
}
}
this._getActions().forEach((action) => {
EditorExtensionsRegistry.getEditorActions().forEach((action) => {
const internalAction = new InternalEditorAction(
action.id,
action.label,
......@@ -264,14 +289,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
return new Configuration(options, this.domElement);
}
protected _getContributions(): IEditorContributionCtor[] {
return EditorExtensionsRegistry.getEditorContributions();
}
protected _getActions(): EditorAction[] {
return EditorExtensionsRegistry.getEditorActions();
}
public getId(): string {
return this.getEditorType() + ':' + this.id;
}
......@@ -1478,7 +1495,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
"EditorTelemetryData" : {}
*/
public getTelemetryData(): { [key: string]: any; } {
return null;
return this._telemetryData;
}
}
......
......@@ -469,7 +469,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
}
protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: editorOptions.IEditorOptions): CodeEditorWidget {
return instantiationService.createInstance(CodeEditorWidget, container, options, false);
return instantiationService.createInstance(CodeEditorWidget, container, options, {});
}
public dispose(): void {
......
......@@ -33,7 +33,7 @@ export class EmbeddedCodeEditorWidget extends CodeEditorWidget {
@IThemeService themeService: IThemeService,
@INotificationService notificationService: INotificationService
) {
super(domElement, parentEditor.getRawConfiguration(), false, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService);
super(domElement, parentEditor.getRawConfiguration(), {}, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService);
this._parentEditor = parentEditor;
this._overwriteOptions = options;
......
......@@ -175,7 +175,7 @@ export class StandaloneCodeEditor extends CodeEditorWidget implements IStandalon
? nls.localize('accessibilityHelpMessageIE', "Press Ctrl+F1 for Accessibility Options.")
: nls.localize('accessibilityHelpMessage', "Press Alt+F1 for Accessibility Options.")
);
super(domElement, options, false, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService);
super(domElement, options, {}, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService);
if (keybindingService instanceof StandaloneKeybindingService) {
this._standaloneKeybindingService = keybindingService;
......
......@@ -14,12 +14,11 @@ import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import { TextModel } from 'vs/editor/common/model/textModel';
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
import * as editorOptions from 'vs/editor/common/config/editorOptions';
import { EditorAction } from 'vs/editor/browser/editorExtensions';
import { ITextModel } from 'vs/editor/common/model';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { IConstructorSignature1 } from 'vs/platform/instantiation/common/instantiation';
import { CodeEditorWidget, ICodeEditorWidgetOptions, } from 'vs/editor/browser/widget/codeEditorWidget';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { TestCodeEditorService, TestCommandService } from 'vs/editor/test/browser/editorTestServices';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { ICommandService } from 'vs/platform/commands/common/commands';
......@@ -28,13 +27,6 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
export class TestCodeEditor extends CodeEditorWidget implements editorBrowser.ICodeEditor {
protected _getContributions(): IConstructorSignature1<editorBrowser.ICodeEditor, editorCommon.IEditorContribution>[] {
return [];
}
protected _getActions(): EditorAction[] {
return [];
}
//#region testing overrides
protected _createConfiguration(options: editorOptions.IEditorOptions): editorCommon.IConfiguration {
return new TestConfiguration(options);
......@@ -95,7 +87,7 @@ export function withTestCodeEditor(text: string[], options: TestCodeEditorCreati
export function createTestCodeEditor(options: TestCodeEditorCreationOptions): TestCodeEditor {
const services: ServiceCollection = options.serviceCollection || new ServiceCollection();
const instantiationService = new InstantiationService(services);
const instantiationService: IInstantiationService = new InstantiationService(services);
if (!services.has(ICodeEditorService)) {
services.set(ICodeEditorService, new TestCodeEditorService());
......@@ -113,7 +105,15 @@ export function createTestCodeEditor(options: TestCodeEditorCreationOptions): Te
services.set(IThemeService, new TestThemeService());
}
const editor = instantiationService.createInstance(TestCodeEditor, <any>new TestEditorDomElement(), options, false);
const codeEditorWidgetOptions: ICodeEditorWidgetOptions = {
contributions: []
};
const editor = instantiationService.createInstance(
TestCodeEditor,
<HTMLElement><any>new TestEditorDomElement(),
options,
codeEditorWidgetOptions
);
editor.setModel(options.model);
return editor;
}
......@@ -182,7 +182,7 @@ export abstract class BaseTextEditor extends BaseEditor {
protected createEditorControl(parent: HTMLElement, configuration: IEditorOptions): IEditor {
// Use a getter for the instantiation service since some subclasses might use scoped instantiation services
return this.instantiationService.createInstance(CodeEditorWidget, parent, configuration, false);
return this.instantiationService.createInstance(CodeEditorWidget, parent, configuration, {});
}
public setInput(input: EditorInput, options?: EditorOptions): TPromise<void> {
......
......@@ -34,6 +34,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService
import { transparent, editorForeground } from 'vs/platform/theme/common/colorRegistry';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { IDecorationOptions } from 'vs/editor/common/editorCommon';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
const $ = dom.$;
const IPrivateBreakopintWidgetService = createDecorator<IPrivateBreakopintWidgetService>('privateBreakopintWidgetService');
......@@ -47,7 +48,7 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakopintWi
public _serviceBrand: any;
private selectContainer: HTMLElement;
private input: SimpleDebugEditor;
private input: CodeEditorWidget;
private toDispose: lifecycle.IDisposable[];
private conditionInput = '';
private hitCountInput = '';
......@@ -202,7 +203,8 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakopintWi
[IContextKeyService, scopedContextKeyService], [IPrivateBreakopintWidgetService, this]));
const options = SimpleDebugEditor.getEditorOptions();
this.input = scopedInstatiationService.createInstance(SimpleDebugEditor, container, options);
const codeEditorWidgetOptions = SimpleDebugEditor.getCodeEditorWidgetOptions();
this.input = scopedInstatiationService.createInstance(CodeEditorWidget, container, options, codeEditorWidgetOptions);
CONTEXT_IN_BREAKPOINT_WIDGET.bindTo(scopedContextKeyService).set(true);
const model = this.modelService.createModel('', null, uri.parse(`${DEBUG_SCHEME}:breakpointinput`), true);
this.input.setModel(model);
......
......@@ -43,6 +43,7 @@ import { memoize } from 'vs/base/common/decorators';
import { dispose } from 'vs/base/common/lifecycle';
import { OpenMode, ClickBehavior } from 'vs/base/parts/tree/browser/treeDefaults';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
const $ = dom.$;
......@@ -75,7 +76,7 @@ export class Repl extends Panel implements IPrivateReplService {
private renderer: ReplExpressionsRenderer;
private container: HTMLElement;
private treeContainer: HTMLElement;
private replInput: SimpleDebugEditor;
private replInput: CodeEditorWidget;
private replInputContainer: HTMLElement;
private refreshTimeoutHandle: number;
private actions: IAction[];
......@@ -174,7 +175,7 @@ export class Repl extends Panel implements IPrivateReplService {
const scopedInstantiationService = this.instantiationService.createChild(new ServiceCollection(
[IContextKeyService, scopedContextKeyService], [IPrivateReplService, this]));
this.replInput = scopedInstantiationService.createInstance(SimpleDebugEditor, this.replInputContainer, SimpleDebugEditor.getEditorOptions());
this.replInput = scopedInstantiationService.createInstance(CodeEditorWidget, this.replInputContainer, SimpleDebugEditor.getEditorOptions(), SimpleDebugEditor.getCodeEditorWidgetOptions());
modes.SuggestRegistry.register({ scheme: debug.DEBUG_SCHEME, hasAccessToAllModels: true }, {
triggerCharacters: ['.'],
......
......@@ -4,12 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { EditorAction, EditorExtensionsRegistry, IEditorContributionCtor } from 'vs/editor/browser/editorExtensions';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget';
// Allowed Editor Contributions:
import { MenuPreventer } from 'vs/workbench/parts/codeEditor/electron-browser/menuPreventer';
......@@ -18,36 +13,21 @@ import { ContextMenuController } from 'vs/editor/contrib/contextmenu/contextmenu
import { SuggestController } from 'vs/editor/contrib/suggest/suggestController';
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
import { TabCompletionController } from 'vs/workbench/parts/snippets/electron-browser/tabCompletion';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { INotificationService } from 'vs/platform/notification/common/notification';
export class SimpleDebugEditor extends CodeEditorWidget {
constructor(
domElement: HTMLElement,
options: IEditorOptions,
@IInstantiationService instantiationService: IInstantiationService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@ICommandService commandService: ICommandService,
@IContextKeyService contextKeyService: IContextKeyService,
@IThemeService themeService: IThemeService,
@INotificationService notificationService: INotificationService,
) {
super(domElement, options, true, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService);
}
protected _getContributions(): IEditorContributionCtor[] {
return [
MenuPreventer,
SelectionClipboard,
ContextMenuController,
SuggestController,
SnippetController2,
TabCompletionController,
];
}
export class SimpleDebugEditor {
protected _getActions(): EditorAction[] {
return EditorExtensionsRegistry.getEditorActions();
public static getCodeEditorWidgetOptions(): ICodeEditorWidgetOptions {
return {
isSimpleWidget: true,
contributions: [
MenuPreventer,
SelectionClipboard,
ContextMenuController,
SuggestController,
SnippetController2,
TabCompletionController,
]
};
}
public static getEditorOptions(): IEditorOptions {
......
......@@ -33,7 +33,7 @@ import { SettingsEditorModel, DefaultSettingsEditorModel } from 'vs/workbench/se
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { SearchWidget, SettingsTargetsWidget, SettingsTarget } from 'vs/workbench/parts/preferences/browser/preferencesWidgets';
import { ContextKeyExpr, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { registerEditorContribution, Command, IEditorContributionCtor } from 'vs/editor/browser/editorExtensions';
import { registerEditorContribution, Command, IEditorContributionCtor, EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IStorageService } from 'vs/platform/storage/common/storage';
......@@ -965,8 +965,15 @@ export class DefaultPreferencesEditor extends BaseTextEditor {
super(DefaultPreferencesEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorGroupService);
}
private static _getContributions(): IEditorContributionCtor[] {
let skipContributions = [FoldingController.prototype, SelectionHighlighter.prototype, FindController.prototype];
let contributions = EditorExtensionsRegistry.getEditorContributions().filter(c => skipContributions.indexOf(c.prototype) === -1);
contributions.push(DefaultSettingsEditorContribution);
return contributions;
}
public createEditorControl(parent: HTMLElement, configuration: IEditorOptions): editorCommon.IEditor {
const editor = this.instantiationService.createInstance(DefaultPreferencesCodeEditor, parent, configuration, false);
const editor = this.instantiationService.createInstance(CodeEditorWidget, parent, configuration, { contributions: DefaultPreferencesEditor._getContributions() });
// Inform user about editor being readonly if user starts type
this.toUnbind.push(editor.onDidType(() => this.showReadonlyHint(editor)));
......@@ -1030,18 +1037,6 @@ export class DefaultPreferencesEditor extends BaseTextEditor {
}
}
class DefaultPreferencesCodeEditor extends CodeEditorWidget {
protected _getContributions(): IEditorContributionCtor[] {
let contributions = super._getContributions();
let skipContributions = [FoldingController.prototype, SelectionHighlighter.prototype, FindController.prototype];
contributions = contributions.filter(c => skipContributions.indexOf(c.prototype) === -1);
contributions.push(DefaultSettingsEditorContribution);
return contributions;
}
}
interface ISettingsEditorContribution extends editorCommon.IEditorContribution {
updatePreferencesRenderer(associatedPreferencesModelUri: URI): TPromise<IPreferencesRenderer<ISetting>>;
......
......@@ -29,8 +29,7 @@ import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/cont
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { once } from 'vs/base/common/event';
import { isObject } from 'vs/base/common/types';
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { registerColor, focusBorder, textLinkForeground, textLinkActiveForeground, textPreformatForeground, contrastBorder, textBlockQuoteBackground, textBlockQuoteBorder } from 'vs/platform/theme/common/colorRegistry';
......@@ -55,27 +54,6 @@ interface IWalkThroughEditorViewState {
viewState: IViewState;
}
class WalkThroughCodeEditor extends CodeEditorWidget {
constructor(
domElement: HTMLElement,
options: IEditorOptions,
private telemetryData: Object,
@IInstantiationService instantiationService: IInstantiationService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@ICommandService commandService: ICommandService,
@IContextKeyService contextKeyService: IContextKeyService,
@IThemeService themeService: IThemeService,
@INotificationService notificationService: INotificationService,
) {
super(domElement, options, false, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService);
}
getTelemetryData() {
return this.telemetryData;
}
}
export class WalkThroughPart extends BaseEditor {
static readonly ID: string = 'workbench.editor.walkThroughPart';
......@@ -330,7 +308,9 @@ export class WalkThroughPart extends BaseEditor {
target: this.input instanceof WalkThroughInput ? this.input.getTelemetryFrom() : undefined,
snippet: i
};
const editor = this.instantiationService.createInstance(WalkThroughCodeEditor, div, options, telemetryData);
const editor = this.instantiationService.createInstance(CodeEditorWidget, div, options, {
telemetryData: telemetryData
});
editor.setModel(model);
this.contentDisposables.push(editor);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册