提交 6989497e 编写于 作者: B Benjamin Pasero

more editor events clean up

上级 0b7dd3ea
......@@ -121,7 +121,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
this.panelHeight = this.storageService.getInteger(WorkbenchLayout.sashYHeightSettingsKey, StorageScope.GLOBAL, 0);
this.toUnbind.push(themeService.onDidThemeChange(_ => this.relayout()));
this.toUnbind.push(eventService.addListener2(EventType.EDITOR_INPUT_CHANGING, (e: EditorEvent) => this.onEditorInputChanging(e)));
this.toUnbind.push(eventService.addListener2(EventType.EDITOR_INPUT_CHANGING, (e: EditorEvent) => this.onEditorInputChanging()));
this.registerSashListeners();
}
......@@ -243,7 +243,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
});
}
private onEditorInputChanging(e: EditorEvent): void {
private onEditorInputChanging(): void {
// Make sure that we layout properly in case we detect that the sidebar is large enought to cause
// multiple opened editors to go below minimal size. The fix is to trigger a layout for any editor
......
......@@ -9,7 +9,7 @@ import {Action, IAction} from 'vs/base/common/actions';
import {ActionBarContributor} from 'vs/workbench/browser/actionBarRegistry';
import types = require('vs/base/common/types');
import {Builder} from 'vs/base/browser/builder';
import {EventType, EditorEvent} from 'vs/workbench/common/events';
import {EventType} from 'vs/workbench/common/events';
import {Registry} from 'vs/platform/platform';
import {Panel} from 'vs/workbench/browser/panel';
import {EditorInput, IFileEditorInput, EditorOptions} from 'vs/workbench/common/editor';
......@@ -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.input, this.options, this.position));
this.emit(EventType.EDITOR_POSITION_CHANGED, this);
}
/**
......
......@@ -21,7 +21,7 @@ import errors = require('vs/base/common/errors');
import {Scope as MementoScope} from 'vs/workbench/common/memento';
import {Scope} from 'vs/workbench/browser/actionBarRegistry';
import {Part} from 'vs/workbench/browser/part';
import {EventType as WorkbenchEventType, EditorEvent} from 'vs/workbench/common/events';
import {EventType as WorkbenchEventType, EditorEvent, EditorInputEvent} from 'vs/workbench/common/events';
import {IEditorRegistry, Extensions as EditorExtensions, BaseEditor, EditorDescriptor} from 'vs/workbench/browser/parts/editor/baseEditor';
import {EditorInput, EditorOptions, TextEditorOptions, ConfirmResult} from 'vs/workbench/common/editor';
import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor';
......@@ -163,7 +163,7 @@ export class EditorPart extends Part implements IEditorPart {
}
// Emit early open event to allow for veto
let event = new EditorEvent(null, input, options, position);
let event = new EditorInputEvent(input);
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, input, options, position));
this.emit(WorkbenchEventType.EDITOR_OPENED, editor);
timerEvent.stop();
......@@ -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, input, options, position));
this.emit(WorkbenchEventType.EDITOR_SET_INPUT_ERROR, new EditorInputEvent(input));
// Recover by closing the active editor (if the input is still the active one)
if (group.activeEditor === input) {
......@@ -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, null, null, position));
this.emit(WorkbenchEventType.EDITOR_CLOSED, editor);
}
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.input, null, activeEditor.position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(activeEditor, activeEditor.input, null, activeEditor.position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGING, new EditorEvent(activeEditor));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(activeEditor));
}
// Update Title Area
......
......@@ -20,7 +20,7 @@ import {ContributableActionProvider} from 'vs/workbench/browser/actionBarRegistr
import {ITree, IElementCallback} from 'vs/base/parts/tree/browser/tree';
import {Registry} from 'vs/platform/platform';
import {WorkbenchComponent} from 'vs/workbench/common/component';
import {EditorEvent, EventType} from 'vs/workbench/common/events';
import {EditorEvent, EditorInputEvent, EventType} from 'vs/workbench/common/events';
import Event, {Emitter} from 'vs/base/common/event';
import {Identifiers} from 'vs/workbench/common/constants';
import {IEditorInput} from 'vs/platform/editor/common/editor';
......@@ -125,7 +125,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
// Listen on Editor Input Changes to show in MRU List
this.toUnbind.push(this.eventService.addListener2(EventType.EDITOR_INPUT_CHANGING, (e: EditorEvent) => this.onEditorInputChanging(e)));
this.toUnbind.push(this.eventService.addListener2(EventType.EDITOR_SET_INPUT_ERROR, (e: EditorEvent) => this.onEditorInputSetError(e)));
this.toUnbind.push(this.eventService.addListener2(EventType.EDITOR_SET_INPUT_ERROR, (e: EditorInputEvent) => this.onEditorInputSetError(e)));
// Editor History Model
this.editorHistoryModel = new EditorHistoryModel(this.editorService, this.instantiationService, this.contextService);
......@@ -155,10 +155,8 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
}
}
private onEditorInputSetError(e: EditorEvent): void {
if (e.editorInput) {
this.removeEditorHistoryEntry(e.editorInput); // make sure this input does not show up in history if it failed to open
}
private onEditorInputSetError(e: EditorInputEvent): void {
this.removeEditorHistoryEntry(e.editorInput); // make sure this input does not show up in history if it failed to open
}
public getEditorHistory(): IEditorInput[] {
......
......@@ -6,8 +6,7 @@
import URI from 'vs/base/common/uri';
import {Event} from 'vs/base/common/events';
import {IEditor, IEditorInput} from 'vs/platform/editor/common/editor';
import {EditorOptions} from 'vs/workbench/common/editor';
import {IEditor, IEditorInput, IEditorOptions} from 'vs/platform/editor/common/editor';
import {Position} from 'vs/platform/editor/common/editor';
/**
......@@ -98,26 +97,18 @@ export class EventType {
static WORKBENCH_OPTIONS_CHANGED = 'workbenchOptionsChanged';
}
/**
* Editor events are being emitted when the editor input changes, shows, is being saved or when the editor content changes.
*/
export class EditorEvent extends Event {
public editor: IEditor;
public editorId: string;
public editorInput: IEditorInput;
public editorOptions: EditorOptions;
public position: Position;
export class EditorInputEvent extends Event {
private _editorInput: IEditorInput;
private prevented: boolean;
constructor(editor: IEditor, editorInput: IEditorInput, editorOptions: EditorOptions, position: Position, originalEvent?: any) {
super(originalEvent);
constructor(editorInput: IEditorInput) {
super(null);
this._editorInput = editorInput;
}
this.editor = editor;
this.editorId = editor ? editor.getId() : void 0;
this.editorInput = editorInput;
this.editorOptions = editorOptions;
this.position = position;
public get editorInput(): IEditorInput {
return this._editorInput;
}
public prevent(): void {
......@@ -129,6 +120,47 @@ export class EditorEvent extends Event {
}
}
/**
* Editor events are being emitted when the editor input changes, shows, is being saved or when the editor content changes.
*/
export class EditorEvent extends Event {
private _editor: IEditor;
private _editorId: string;
private _editorInput: IEditorInput;
private _editorOptions: IEditorOptions;
private _position: Position;
constructor(editor: IEditor, editorInput = editor.input, editorOptions = editor.options, position = editor.position, originalEvent?: any) {
super(originalEvent);
this._editor = editor;
this._editorId = editor ? editor.getId() : void 0;
this._editorInput = editorInput;
this._editorOptions = editorOptions;
this._position = position;
}
public get editor(): IEditor {
return this._editor;
}
public get editorId(): string {
return this._editorId;
}
public get editorInput(): IEditorInput {
return this._editorInput;
}
public get editorOptions(): IEditorOptions {
return this._editorOptions;
}
public get position(): Position {
return this._position;
}
}
/**
* Option change events are send when the options in the running instance change.
*/
......
......@@ -24,7 +24,7 @@ import {Action, IAction} from 'vs/base/common/actions';
import {MessageType, IInputValidator} from 'vs/base/browser/ui/inputbox/inputBox';
import {ITree, IHighlightEvent} from 'vs/base/parts/tree/browser/tree';
import {dispose, IDisposable} from 'vs/base/common/lifecycle';
import {EventType as WorkbenchEventType, EditorEvent} from 'vs/workbench/common/events';
import {EventType as WorkbenchEventType, EditorInputEvent} from 'vs/workbench/common/events';
import {LocalFileChangeEvent, VIEWLET_ID, ITextFileService, TextFileChangeEvent, EventType as FileEventType} from 'vs/workbench/parts/files/common/files';
import {IFileService, IFileStat, IImportResult} from 'vs/platform/files/common/files';
import {DiffEditorInput, toDiffLabel} from 'vs/workbench/common/editor/diffEditorInput';
......@@ -1227,7 +1227,7 @@ export class GlobalCompareResourcesAction extends Action {
globalResourceToCompare = fileInput.getResource();
// Listen for next editor to open
let unbind = this.eventService.addListener2(WorkbenchEventType.EDITOR_INPUT_OPENING, (e: EditorEvent) => {
let unbind = this.eventService.addListener2(WorkbenchEventType.EDITOR_INPUT_OPENING, (e: EditorInputEvent) => {
unbind.dispose(); // listen once
let otherFileInput = asFileEditorInput(e.editorInput);
......
......@@ -7,9 +7,10 @@
import {TPromise} from 'vs/base/common/winjs.base';
import types = require('vs/base/common/types');
import {ProgressBar} from 'vs/base/browser/ui/progressbar/progressbar';
import {EditorEvent, EventType, CompositeEvent} from 'vs/workbench/common/events';
import {EventType, CompositeEvent} from 'vs/workbench/common/events';
import {IEventService} from 'vs/platform/event/common/event';
import {IProgressService, IProgressRunner} from 'vs/platform/progress/common/progress';
import {IEditor} from 'vs/platform/editor/common/editor';
interface ProgressState {
infinite?: boolean;
......@@ -35,14 +36,14 @@ export abstract class ScopedService {
}
public registerListeners(): void {
this.eventService.addListener2(EventType.EDITOR_CLOSED, (e: EditorEvent) => {
if (e.editorId === this.scopeId) {
this.eventService.addListener2(EventType.EDITOR_CLOSED, (editor: IEditor) => {
if (editor.getId() === this.scopeId) {
this.onScopeDeactivated();
}
});
this.eventService.addListener2(EventType.EDITOR_OPENED, (e: EditorEvent) => {
if (e.editorId === this.scopeId) {
this.eventService.addListener2(EventType.EDITOR_OPENED, (editor: IEditor) => {
if (editor.getId() === this.scopeId) {
this.onScopeActivated();
}
});
......
......@@ -426,13 +426,13 @@ suite('Workbench UI Services', () => {
let service = new TestScopedService(eventService);
assert(!service.isActive);
eventService.emit(EventType.EDITOR_OPENED, { editorId: 'other.test.scopeId' });
eventService.emit(EventType.EDITOR_OPENED, { getId: () => 'other.test.scopeId' });
assert(!service.isActive);
eventService.emit(EventType.EDITOR_OPENED, { editorId: 'test.scopeId' });
eventService.emit(EventType.EDITOR_OPENED, { getId: () => 'test.scopeId' });
assert(service.isActive);
eventService.emit(EventType.EDITOR_CLOSED, { editorId: 'test.scopeId' });
eventService.emit(EventType.EDITOR_CLOSED, { getId: () => 'test.scopeId' });
assert(!service.isActive);
eventService.emit(EventType.COMPOSITE_OPENED, { compositeId: 'test.scopeId' });
......@@ -465,19 +465,19 @@ suite('Workbench UI Services', () => {
assert.strictEqual(true, testProgressBar.fDone);
// Inactive: Show (Infinite)
eventService.emit(EventType.EDITOR_CLOSED, { editorId: 'test.scopeId' });
eventService.emit(EventType.EDITOR_CLOSED, { getId: () => 'test.scopeId' });
service.show(true);
assert.strictEqual(false, !!testProgressBar.fInfinite);
eventService.emit(EventType.EDITOR_OPENED, { editorId: 'test.scopeId' });
eventService.emit(EventType.EDITOR_OPENED, { getId: () => 'test.scopeId' });
assert.strictEqual(true, testProgressBar.fInfinite);
// Inactive: Show (Total / Worked)
eventService.emit(EventType.EDITOR_CLOSED, { editorId: 'test.scopeId' });
eventService.emit(EventType.EDITOR_CLOSED, { getId: () => 'test.scopeId' });
fn = service.show(100);
fn.total(80);
fn.worked(20);
assert.strictEqual(false, !!testProgressBar.fTotal);
eventService.emit(EventType.EDITOR_OPENED, { editorId: 'test.scopeId' });
eventService.emit(EventType.EDITOR_OPENED, { getId: () => 'test.scopeId' });
assert.strictEqual(20, testProgressBar.fWorked);
assert.strictEqual(80, testProgressBar.fTotal);
......@@ -486,12 +486,12 @@ suite('Workbench UI Services', () => {
service.showWhile(p).then(() => {
assert.strictEqual(true, testProgressBar.fDone);
eventService.emit(EventType.EDITOR_CLOSED, { editorId: 'test.scopeId' });
eventService.emit(EventType.EDITOR_CLOSED, { getId: () => 'test.scopeId' });
p = TPromise.as(null);
service.showWhile(p).then(() => {
assert.strictEqual(true, testProgressBar.fDone);
eventService.emit(EventType.EDITOR_OPENED, { editorId: 'test.scopeId' });
eventService.emit(EventType.EDITOR_OPENED, { getId: () => 'test.scopeId' });
assert.strictEqual(true, testProgressBar.fDone);
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册