提交 ec4d50c2 编写于 作者: B Benjamin Pasero

starting events cleanup

上级 ecf180ea
......@@ -14,6 +14,7 @@ import URI from 'vs/base/common/uri';
import {IDisposable} from 'vs/base/common/lifecycle';
import labels = require('vs/base/common/labels');
import {EventType} from 'vs/base/common/events';
import {IEditorInput} from 'vs/platform/editor/common/editor';
import {Mode, IEntryRunContext} from 'vs/base/parts/quickopen/common/quickOpen';
import {QuickOpenEntry, QuickOpenModel, IHighlight} from 'vs/base/parts/quickopen/browser/quickOpenModel';
import {EditorInput, getUntitledOrFileResource} from 'vs/workbench/common/editor';
......@@ -132,14 +133,14 @@ export class EditorHistoryModel extends QuickOpenModel {
this.registry = Registry.as<IEditorRegistry>(Extensions.Editors);
}
public add(input: EditorInput, index?: number): void {
public add(input: IEditorInput, index?: number): void {
// Ensure we have at least a name to show
if (!input.getName()) {
return;
}
const entry = new EditorHistoryEntry(this.editorService, this.contextService, input, null, null, this);
const entry = new EditorHistoryEntry(this.editorService, this.contextService, <EditorInput>input, null, null, this);
// Remove any existing entry and add to the beginning if we do not get an index
if (typeof index !== 'number') {
......@@ -187,8 +188,9 @@ export class EditorHistoryModel extends QuickOpenModel {
// Factory failed, just remove entry then
this.remove(input);
}
public remove(input: EditorInput): void {
let index = this.indexOf(input);
public remove(input: IEditorInput): void {
let index = this.indexOf(<EditorInput>input);
if (index >= 0) {
const entry = <EditorHistoryEntry>this.entries[index];
if (entry) {
......
......@@ -23,10 +23,10 @@ import {WorkbenchComponent} from 'vs/workbench/common/component';
import {EditorEvent, 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';
import {Scope} from 'vs/workbench/common/memento';
import {QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions} from 'vs/workbench/browser/quickopen';
import {EditorHistoryModel} from 'vs/workbench/browser/parts/quickopen/editorHistoryModel';
import {EditorInput} from 'vs/workbench/common/editor';
import errors = require('vs/base/common/errors');
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IPickOpenEntry, IInputOptions, IQuickOpenService, IPickOptions, IShowOptions} from 'vs/workbench/services/quickopen/common/quickOpenService';
......@@ -161,7 +161,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
}
}
public getEditorHistory(): EditorInput[] {
public getEditorHistory(): IEditorInput[] {
return this.editorHistoryModel ? this.editorHistoryModel.getEntries().map((entry) => entry.getInput()) : [];
}
......@@ -169,7 +169,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
this.editorHistoryModel.setEntries([]);
}
public removeEditorHistoryEntry(input: EditorInput): void {
public removeEditorHistoryEntry(input: IEditorInput): void {
this.editorHistoryModel.remove(input);
}
......
......@@ -6,8 +6,8 @@
import URI from 'vs/base/common/uri';
import {Event} from 'vs/base/common/events';
import {IEditor} from 'vs/platform/editor/common/editor';
import {EditorInput, EditorOptions} from 'vs/workbench/common/editor';
import {IEditor, IEditorInput} from 'vs/platform/editor/common/editor';
import {EditorOptions} from 'vs/workbench/common/editor';
import {Position} from 'vs/platform/editor/common/editor';
import {Selection} from 'vs/editor/common/core/selection';
......@@ -130,13 +130,13 @@ export class EventType {
export class EditorEvent extends Event {
public editor: IEditor;
public editorId: string;
public editorInput: EditorInput;
public editorInput: IEditorInput;
public editorOptions: EditorOptions;
public position: Position;
private prevented: boolean;
constructor(editor: IEditor, editorId: string, editorInput: EditorInput, editorOptions: EditorOptions, position: Position, originalEvent?: any) {
constructor(editor: IEditor, editorId: string, editorInput: IEditorInput, editorOptions: EditorOptions, position: Position, originalEvent?: any) {
super(originalEvent);
this.editor = editor;
......@@ -155,26 +155,13 @@ export class EditorEvent extends Event {
}
}
/**
* Editor input events are being emitted when the editor input state changes.
*/
export class EditorInputEvent extends Event {
public editorInput: EditorInput;
constructor(editorInput: EditorInput, originalEvent?: any) {
super(originalEvent);
this.editorInput = editorInput;
}
}
/**
* A subclass of EditorEvent for text editor selection changes.
*/
export class TextEditorSelectionEvent extends EditorEvent {
public selection: Selection;
constructor(selection: Selection, editor: IEditor, editorId: string, editorInput: EditorInput, editorOptions: EditorOptions, position: Position, originalEvent?: any) {
constructor(selection: Selection, editor: IEditor, editorId: string, editorInput: IEditorInput, editorOptions: EditorOptions, position: Position, originalEvent?: any) {
super(editor, editorId, editorInput, editorOptions, position, originalEvent);
this.selection = selection;
......@@ -198,19 +185,6 @@ export class OptionsChangeEvent extends Event {
}
}
/**
* Command events are emitted when an action is being executed through a command handler (Keybinding).
*/
export class CommandEvent extends Event {
public actionId: string;
constructor(actionId: string, originalEvent?: any) {
super(originalEvent);
this.actionId = actionId;
}
}
/**
* Composite events are emitted when a composite opens or closes in the sidebar or panel.
*/
......
......@@ -20,7 +20,7 @@ import {FileEditorInput} from 'vs/workbench/parts/files/browser/editors/fileEdit
import {IFrameEditorInput} from 'vs/workbench/common/editor/iframeEditorInput';
import {TextFileEditorModel, CACHE} from 'vs/workbench/parts/files/common/editors/textFileEditorModel';
import {IFrameEditor} from 'vs/workbench/browser/parts/editor/iframeEditor';
import {EventType as WorkbenchEventType, EditorInputEvent, UntitledEditorEvent} from 'vs/workbench/common/events';
import {EventType as WorkbenchEventType, UntitledEditorEvent} from 'vs/workbench/common/events';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
......@@ -63,7 +63,7 @@ export class FileTracker implements IWorkbenchContribution {
private registerListeners(): void {
// Update editors and inputs from local changes and saves
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.EDITOR_INPUT_CHANGED, (e: EditorInputEvent) => this.onEditorInputChanged(e)));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChanged()));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, (e: UntitledEditorEvent) => this.onUntitledEditorDeleted(e)));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DIRTY, (e: UntitledEditorEvent) => this.onUntitledEditorDirty(e)));
this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_DIRTY, (e: TextFileChangeEvent) => this.onTextFileDirty(e)));
......@@ -76,7 +76,7 @@ export class FileTracker implements IWorkbenchContribution {
this.toUnbind.push(this.eventService.addListener2(CommonFileEventType.FILE_CHANGES, (e: FileChangesEvent) => this.onFileChanges(e)));
}
private onEditorInputChanged(e: EditorInputEvent): void {
private onEditorInputChanged(): void {
this.disposeUnusedTextFileModels();
}
......
......@@ -10,7 +10,7 @@ import URI from 'vs/base/common/uri';
import * as Paths from 'vs/base/common/paths';
import * as Files from 'vs/platform/files/common/files';
import {Event, PropertyChangeEvent} from 'vs/base/common/events';
import {CommandEvent, CompositeEvent, EditorEvent} from 'vs/workbench/common/events';
import {CompositeEvent, EditorEvent} from 'vs/workbench/common/events';
let FileChangesEvent = Files.FileChangesEvent;
......@@ -24,16 +24,6 @@ suite('Workbench Events', () => {
assert(event.time);
});
test('Command Event', function () {
let actionId = 'foo.bar';
let origEvent = {};
let event = new CommandEvent(actionId, origEvent);
assert.strictEqual(event.originalEvent, origEvent);
assert.strictEqual(event.actionId, actionId);
assert(event.time);
});
test('Editor Change Event', function () {
let editor: any = {};
let origEvent: any = {};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册