提交 95835bfd 编写于 作者: B Benjamin Pasero

simplify EditorEvent

上级 ec4d50c2
......@@ -123,7 +123,7 @@ export abstract class BaseEditor extends Panel implements IEditor {
*/
public changePosition(position: Position): void {
this._position = position;
this.emit(EventType.EDITOR_POSITION_CHANGED, new EditorEvent(this, this.getId(), this.input, this.options, this.position));
this.emit(EventType.EDITOR_POSITION_CHANGED, new EditorEvent(this, this.input, this.options, this.position));
}
/**
......
......@@ -163,7 +163,7 @@ export class EditorPart extends Part implements IEditorPart {
}
// Emit early open event to allow for veto
let event = new EditorEvent(null, null, input, options, position);
let event = new EditorEvent(null, input, options, position);
this.emit(WorkbenchEventType.EDITOR_INPUT_OPENING, event);
if (event.isPrevented()) {
return TPromise.as<BaseEditor>(null);
......@@ -263,7 +263,7 @@ export class EditorPart extends Part implements IEditorPart {
this.sideBySideControl.layout(position);
// Emit Editor-Opened Event
this.emit(WorkbenchEventType.EDITOR_OPENED, new EditorEvent(editor, editor.getId(), input, options, position));
this.emit(WorkbenchEventType.EDITOR_OPENED, new EditorEvent(editor, input, options, position));
timerEvent.stop();
......@@ -369,7 +369,7 @@ export class EditorPart extends Part implements IEditorPart {
const previousInput = editor.getInput();
const inputChanged = (!previousInput || !previousInput.matches(input) || (options && options.forceOpen));
if (inputChanged) {
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGING, new EditorEvent(editor, editor.getId(), input, options, position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGING, new EditorEvent(editor, input, options, position));
}
// Call into Editor
......@@ -394,7 +394,7 @@ export class EditorPart extends Part implements IEditorPart {
// editor title area is up to date.
if (group.activeEditor && group.activeEditor.matches(input)) {
this.doRecreateEditorTitleArea();
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(editor, editor.getId(), group.activeEditor, options, position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(editor, group.activeEditor, options, position));
}
return editor;
......@@ -411,7 +411,7 @@ export class EditorPart extends Part implements IEditorPart {
// Emit Input-Changed Event (if input changed)
if (inputChanged) {
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(editor, editor.getId(), input, options, position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(editor, input, options, position));
}
// Update Title Area
......@@ -452,7 +452,7 @@ export class EditorPart extends Part implements IEditorPart {
this.sideBySideControl.updateProgress(position, ProgressState.DONE);
// Event
this.emit(WorkbenchEventType.EDITOR_SET_INPUT_ERROR, new EditorEvent(editor, editor.getId(), input, options, position));
this.emit(WorkbenchEventType.EDITOR_SET_INPUT_ERROR, new EditorEvent(editor, input, options, position));
// Recover by closing the active editor (if the input is still the active one)
if (group.activeEditor === input) {
......@@ -524,13 +524,13 @@ export class EditorPart extends Part implements IEditorPart {
this.modifyGroups(() => this.stacks.closeGroup(group));
// Emit Input-Changing Event
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGING, new EditorEvent(null, null, null, null, position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGING, new EditorEvent(null, null, null, position));
// Hide Editor
this.doHideEditor(position, true);
// Emit Input-Changed Event
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(null, null, null, null, position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(null, null, null, position));
// Focus next group if we have an active one left
const currentActiveGroup = this.stacks.activeGroup;
......@@ -570,7 +570,7 @@ export class EditorPart extends Part implements IEditorPart {
this.sideBySideControl.clearTitleArea(position);
// Emit Editor Closed Event
this.emit(WorkbenchEventType.EDITOR_CLOSED, new EditorEvent(editor, editor.getId(), null, null, position));
this.emit(WorkbenchEventType.EDITOR_CLOSED, new EditorEvent(editor, null, null, position));
}
public closeAllEditors(except?: Position): TPromise<void> {
......@@ -812,8 +812,8 @@ export class EditorPart extends Part implements IEditorPart {
// Emit as editor input change event so that clients get aware of new active editor
let activeEditor = this.sideBySideControl.getActiveEditor();
if (activeEditor) {
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGING, new EditorEvent(activeEditor, activeEditor.getId(), activeEditor.input, null, activeEditor.position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(activeEditor, activeEditor.getId(), activeEditor.input, null, activeEditor.position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGING, new EditorEvent(activeEditor, activeEditor.input, null, activeEditor.position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(activeEditor, activeEditor.input, null, activeEditor.position));
}
// Update Title Area
......
......@@ -136,27 +136,27 @@ export abstract class BaseTextEditor extends BaseEditor {
// Hook Listener for Selection changes
this.toUnbind.push(this.editorControl.onDidChangeCursorPosition((event: ICursorPositionChangedEvent) => {
let selection = this.editorControl.getSelection();
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_SELECTION_CHANGED, new TextEditorSelectionEvent(selection, this, this.getId(), this.input, null, this.position, event));
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_SELECTION_CHANGED, new TextEditorSelectionEvent(selection, this, this.input, null, this.position, event));
}));
// Hook Listener for mode changes
this.toUnbind.push(this.editorControl.onDidChangeModelMode((event: IModelModeChangedEvent) => {
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_MODE_CHANGED, new EditorEvent(this, this.getId(), this.input, null, this.position, event));
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_MODE_CHANGED, new EditorEvent(this, this.input, null, this.position, event));
}));
// Hook Listener for content changes
this.toUnbind.push(this.editorControl.onDidChangeModelRawContent((event: IModelContentChangedEvent) => {
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_CONTENT_CHANGED, new EditorEvent(this, this.getId(), this.input, null, this.position, event));
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_CONTENT_CHANGED, new EditorEvent(this, this.input, null, this.position, event));
}));
// Hook Listener for content options changes
this.toUnbind.push(this.editorControl.onDidChangeModelOptions((event: IModelOptionsChangedEvent) => {
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_CONTENT_OPTIONS_CHANGED, new EditorEvent(this, this.getId(), this.input, null, this.position, event));
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_CONTENT_OPTIONS_CHANGED, new EditorEvent(this, this.input, null, this.position, event));
}));
// Hook Listener for options changes
this.toUnbind.push(this.editorControl.onDidChangeConfiguration((event: IConfigurationChangedEvent) => {
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_CONFIGURATION_CHANGED, new EditorEvent(this, this.getId(), this.input, null, this.position, event));
this.eventService.emit(WorkbenchEventType.TEXT_EDITOR_CONFIGURATION_CHANGED, new EditorEvent(this, this.input, null, this.position, event));
}));
// Configuration
......
......@@ -136,11 +136,11 @@ export class EditorEvent extends Event {
private prevented: boolean;
constructor(editor: IEditor, editorId: string, editorInput: IEditorInput, editorOptions: EditorOptions, position: Position, originalEvent?: any) {
constructor(editor: IEditor, editorInput: IEditorInput, editorOptions: EditorOptions, position: Position, originalEvent?: any) {
super(originalEvent);
this.editor = editor;
this.editorId = editorId;
this.editorId = editor ? editor.getId() : void 0;
this.editorInput = editorInput;
this.editorOptions = editorOptions;
this.position = position;
......@@ -161,8 +161,8 @@ export class EditorEvent extends Event {
export class TextEditorSelectionEvent extends EditorEvent {
public selection: Selection;
constructor(selection: Selection, editor: IEditor, editorId: string, editorInput: IEditorInput, editorOptions: EditorOptions, position: Position, originalEvent?: any) {
super(editor, editorId, editorInput, editorOptions, position, originalEvent);
constructor(selection: Selection, editor: IEditor, editorInput: IEditorInput, editorOptions: EditorOptions, position: Position, originalEvent?: any) {
super(editor, editorInput, editorOptions, position, originalEvent);
this.selection = selection;
}
......
......@@ -240,7 +240,7 @@ suite('Workbench QuickOpen', () => {
assert.equal(0, controller.getEditorHistoryModel().getEntries().length);
let cinput1 = <EditorInput>inst.createInstance(fileInputCtor, toResource('Hello World'), 'text/plain', null);
let event = new EditorEvent(null, '', cinput1, null, Position.LEFT);
let event = new EditorEvent(null, cinput1, null, Position.LEFT);
eventService.emit(EventType.EDITOR_INPUT_CHANGING, event);
assert.equal(1, controller.getEditorHistoryModel().getEntries().length);
......
......@@ -25,12 +25,12 @@ suite('Workbench Events', () => {
});
test('Editor Change Event', function () {
let editor: any = {};
let editor: any = { getId: () => 'foo.bar' };
let origEvent: any = {};
let input: any = {};
let options: any = {};
let id = 'foo.bar';
let event = new EditorEvent(editor, id, input, options, 0, origEvent);
let event = new EditorEvent(editor, input, options, 0, origEvent);
assert.strictEqual(event.editor, editor);
assert.strictEqual(event.originalEvent, origEvent);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册