提交 889454cc 编写于 作者: B Benjamin Pasero

add event for input open fail

上级 43d78f09
......@@ -85,6 +85,7 @@ export class EditorPart extends Part implements IEditorPart {
private _onEditorsChanged: Emitter<void>;
private _onEditorsMoved: Emitter<void>;
private _onEditorOpenFail: Emitter<EditorInput>;
// The following data structures are partitioned into array of Position as provided by Services.POSITION array
private visibleEditors: BaseEditor[];
......@@ -109,6 +110,7 @@ export class EditorPart extends Part implements IEditorPart {
this._onEditorsChanged = new Emitter<void>();
this._onEditorsMoved = new Emitter<void>();
this._onEditorOpenFail = new Emitter<EditorInput>();
this.visibleEditors = [];
......@@ -157,6 +159,10 @@ export class EditorPart extends Part implements IEditorPart {
return this._onEditorsMoved.event;
}
public get onEditorOpenFail(): Event<EditorInput> {
return this._onEditorOpenFail.event;
}
public openEditor(input: EditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<BaseEditor>;
public openEditor(input: EditorInput, options?: EditorOptions, position?: Position, widthRatios?: number[]): TPromise<BaseEditor>;
public openEditor(input: EditorInput, options?: EditorOptions, arg3?: any, widthRatios?: number[]): TPromise<BaseEditor> {
......@@ -463,7 +469,7 @@ export class EditorPart extends Part implements IEditorPart {
this.sideBySideControl.updateProgress(position, ProgressState.DONE);
// Event
this.emit(WorkbenchEventType.EDITOR_SET_INPUT_ERROR, new EditorInputEvent(input));
this._onEditorOpenFail.fire(input);
// Recover by closing the active editor (if the input is still the active one)
if (group.activeEditor === input) {
......@@ -1145,6 +1151,7 @@ export class EditorPart extends Part implements IEditorPart {
// Emitters
this._onEditorsChanged.dispose();
this._onEditorsMoved.dispose();
this._onEditorOpenFail.dispose();
// Reset Tokens
this.editorOpenToken = [];
......
......@@ -20,7 +20,6 @@ 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 {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 +124,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
// Listen on Editor Input Changes to show in MRU List
this.toUnbind.push(this.editorService.onEditorsChanged(() => this.onEditorsChanged()));
this.toUnbind.push(this.eventService.addListener2(EventType.EDITOR_SET_INPUT_ERROR, (e: EditorInputEvent) => this.onEditorInputSetError(e)));
this.toUnbind.push(this.editorService.onEditorOpenFail(e => this.onEditorInputSetError(e)));
// Editor History Model
this.editorHistoryModel = new EditorHistoryModel(this.editorService, this.instantiationService, this.contextService);
......@@ -151,8 +150,8 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
}
}
private onEditorInputSetError(e: EditorInputEvent): void {
this.removeEditorHistoryEntry(e.editorInput); // make sure this input does not show up in history if it failed to open
private onEditorInputSetError(e: IEditorInput): void {
this.removeEditorHistoryEntry(e); // make sure this input does not show up in history if it failed to open
}
public getEditorHistory(): IEditorInput[] {
......
......@@ -31,11 +31,6 @@ export class EventType {
*/
static EDITOR_INPUT_OPENING = 'editorInputOpening';
/**
* Event type for when the editor input failed to be set to the editor.
*/
static EDITOR_SET_INPUT_ERROR = 'editorSetInputError';
/**
* Event type for when a composite is about to open.
*/
......
......@@ -31,6 +31,7 @@ export interface IEditorPart {
// Events
onEditorsChanged: Event<void>;
onEditorsMoved: Event<void>;
onEditorOpenFail: Event<IEditorInput>;
// Methods
openEditor(input?: EditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<BaseEditor>;
......@@ -77,6 +78,10 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
return this.editorPart.onEditorsMoved;
}
public get onEditorOpenFail(): Event<IEditorInput> {
return this.editorPart.onEditorOpenFail;
}
public getActiveEditor(): IEditor {
return this.editorPart.getActiveEditor();
}
......
......@@ -34,6 +34,11 @@ export interface IWorkbenchEditorService extends IEditorService {
*/
onEditorsMoved: Event<void>;
/**
* Emitted when opening an editor fails.
*/
onEditorOpenFail: Event<IEditorInput>;
/**
* Returns the currently active editor or null if none.
*/
......
......@@ -79,6 +79,10 @@ class TestEditorPart implements IEditorPart {
return null;
}
public get onEditorOpenFail(): Event<EditorInput> {
return null;
}
public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: any }[]): TPromise<IEditor[]> {
return TPromise.as([]);
}
......
......@@ -294,12 +294,14 @@ export class TestEditorService implements WorkbenchEditorService.IWorkbenchEdito
private _onEditorsChanged: Emitter<void>;
private _onEditorsMoved: Emitter<void>;
private _onEditorOpenFail: Emitter<IEditorInput>;
constructor(callback?: (method: string) => void) {
this.callback = callback || ((s: string) => { });
this._onEditorsChanged = new Emitter<void>();
this._onEditorsMoved = new Emitter<void>();
this._onEditorOpenFail = new Emitter<IEditorInput>();
let services = new ServiceCollection();
......@@ -325,6 +327,10 @@ export class TestEditorService implements WorkbenchEditorService.IWorkbenchEdito
return this._onEditorsMoved.event;
}
public get onEditorOpenFail(): Event<IEditorInput> {
return this._onEditorOpenFail.event;
}
public openEditors(inputs): Promise {
return TPromise.as([]);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册