diff --git a/src/vs/workbench/api/node/extHostEditors.ts b/src/vs/workbench/api/node/extHostEditors.ts index 83f0ebc8b51..540e6c96770 100644 --- a/src/vs/workbench/api/node/extHostEditors.ts +++ b/src/vs/workbench/api/node/extHostEditors.ts @@ -493,7 +493,7 @@ export class MainThreadEditors { this._toDispose.push(this._editorTracker.onDidUpdateTextEditors(() => this._updateActiveAndVisibleTextEditors())); this._toDispose.push(this._editorTracker.onChangedFocusedTextEditor((focusedTextEditorId) => this._updateActiveAndVisibleTextEditors())); - this._toDispose.push(eventService.addListener2(EventType.EDITOR_INPUT_CHANGED, () => this._updateActiveAndVisibleTextEditors())); + this._toDispose.push(workbenchEditorService.onEditorsChanged(() => this._updateActiveAndVisibleTextEditors())); this._toDispose.push(eventService.addListener2(EventType.EDITOR_POSITION_CHANGED, () => this._updateActiveAndVisibleTextEditors())); } diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index bee81b6633b..eb9876beca9 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -5,7 +5,6 @@ 'use strict'; import {Dimension, Builder, Box} from 'vs/base/browser/builder'; -import {EventType} from 'vs/workbench/common/events'; import {Part} from 'vs/workbench/browser/part'; import {QuickOpenController} from 'vs/workbench/browser/parts/quickopen/quickOpenController'; import {Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation} from 'vs/base/browser/ui/sash/sash'; @@ -121,7 +120,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_CHANGED, () => this.onEditorInputChanged())); + this.toUnbind.push(editorService.onEditorsChanged(() => this.onEditorsChanged())); this.registerSashListeners(); } @@ -243,7 +242,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal }); } - private onEditorInputChanged(): void { + private onEditorsChanged(): 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 diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index b46f43b0c72..e37f0bd64a1 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -40,6 +40,7 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {IProgressService} from 'vs/platform/progress/common/progress'; import {EditorStacksModel, EditorGroup, IEditorIdentifier} from 'vs/workbench/common/editor/editorStacksModel'; import {IDisposable, dispose} from 'vs/base/common/lifecycle'; +import Event, {Emitter} from 'vs/base/common/event'; class ProgressMonitor { @@ -82,6 +83,8 @@ export class EditorPart extends Part implements IEditorPart { private memento: any; private stacks: EditorStacksModel; + private _onEditorsChanged: Emitter; + // The following data structures are partitioned into array of Position as provided by Services.POSITION array private visibleEditors: BaseEditor[]; private visibleEditorListeners: IDisposable[][]; @@ -103,6 +106,8 @@ export class EditorPart extends Part implements IEditorPart { ) { super(id); + this._onEditorsChanged = new Emitter(); + this.visibleEditors = []; this.editorOpenToken = arrays.fill(POSITIONS.length, () => 0); @@ -142,6 +147,10 @@ export class EditorPart extends Part implements IEditorPart { this.startDelayedCloseEditorsFromInputDispose(); } + public get onEditorsChanged(): Event { + return this._onEditorsChanged.event; + } + public openEditor(input: EditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise; public openEditor(input: EditorInput, options?: EditorOptions, position?: Position, widthRatios?: number[]): TPromise; public openEditor(input: EditorInput, options?: EditorOptions, arg3?: any, widthRatios?: number[]): TPromise { @@ -390,7 +399,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, editor); + this._onEditorsChanged.fire(); } return editor; @@ -405,9 +414,9 @@ export class EditorPart extends Part implements IEditorPart { // Progress Done this.sideBySideControl.updateProgress(position, ProgressState.DONE); - // Emit Input-Changed Event (if input changed) + // Emit Change Event (if input changed) if (inputChanged) { - this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, editor); + this._onEditorsChanged.fire(); } // Update Title Area @@ -522,8 +531,8 @@ export class EditorPart extends Part implements IEditorPart { // Hide Editor this.doHideEditor(position, true); - // Emit Input-Changed Event - this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, {}); + // Emit Change Event + this._onEditorsChanged.fire(); // Focus next group if we have an active one left const currentActiveGroup = this.stacks.activeGroup; @@ -802,10 +811,10 @@ export class EditorPart extends Part implements IEditorPart { this.stacks.setActive(this.stacks.groupAt(activePosition)); } - // Emit as editor input change event so that clients get aware of new active editor + // Emit as change event so that clients get aware of new active editor let activeEditor = this.sideBySideControl.getActiveEditor(); if (activeEditor) { - this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, {}); + this._onEditorsChanged.fire(); } // Update Title Area diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index 510c6074c22..a9204794448 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -292,7 +292,7 @@ export class EditorStatus implements IStatusbarItem { } } }, - this.eventService.addListener2(EventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChanged()), + this.editorService.onEditorsChanged(() => this.onEditorsChanged()), this.eventService.addListener2(EventType.RESOURCE_ENCODING_CHANGED, (e: ResourceEvent) => this.onResourceEncodingChange(e.resource)) ); @@ -432,7 +432,7 @@ export class EditorStatus implements IStatusbarItem { } } - private onEditorInputChanged(): void { + private onEditorsChanged(): void { let control: IEditor; const activeEditor = this.editorService.getActiveEditor(); if (activeEditor instanceof BaseTextEditor) { diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 9a83d973ac5..92f6ebd6cee 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -124,7 +124,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe public create(): void { // Listen on Editor Input Changes to show in MRU List - this.toUnbind.push(this.eventService.addListener2(EventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChanged())); + this.toUnbind.push(this.editorService.onEditorsChanged(() => this.onEditorsChanged())); this.toUnbind.push(this.eventService.addListener2(EventType.EDITOR_SET_INPUT_ERROR, (e: EditorInputEvent) => this.onEditorInputSetError(e))); // Editor History Model @@ -135,7 +135,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe } } - private onEditorInputChanged(): void { + private onEditorsChanged(): void { let activeEditorInput = this.editorService.getActiveEditorInput(); if (!activeEditorInput) { return; diff --git a/src/vs/workbench/common/events.ts b/src/vs/workbench/common/events.ts index 7c93be09ff5..7ce5027ab7a 100644 --- a/src/vs/workbench/common/events.ts +++ b/src/vs/workbench/common/events.ts @@ -31,15 +31,6 @@ export class EventType { */ static EDITOR_INPUT_OPENING = 'editorInputOpening'; - /** - * Event type for when the editor input has been changed in the currently active editor. This event is being sent after - * the input has been set and displayed by the editor. - * - * Note: This event will also be emitted when multiple editors are open and the user sets focus from the active editor - * to another one. This allows to detect a focus change of the active editor. - */ - static EDITOR_INPUT_CHANGED = 'editorInputChanged'; - /** * Event type for when the editor input failed to be set to the editor. */ diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts index 5af9ab95d5e..63a688504a1 100644 --- a/src/vs/workbench/electron-browser/window.ts +++ b/src/vs/workbench/electron-browser/window.ts @@ -9,7 +9,6 @@ import platform = require('vs/base/common/platform'); import paths = require('vs/base/common/paths'); import uri from 'vs/base/common/uri'; import {Identifiers} from 'vs/workbench/common/constants'; -import {EventType} from 'vs/workbench/common/events'; import workbenchEditorCommon = require('vs/workbench/common/editor'); import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; @@ -52,7 +51,7 @@ export class ElectronWindow { // React to editor input changes (Mac only) if (platform.platform === platform.Platform.Mac) { - this.eventService.addListener2(EventType.EDITOR_INPUT_CHANGED, () => { + this.editorService.onEditorsChanged(() => { let fileInput = workbenchEditorCommon.asFileEditorInput(this.editorService.getActiveEditorInput(), true); let representedFilename = ''; if (fileInput) { diff --git a/src/vs/workbench/parts/files/browser/fileTracker.ts b/src/vs/workbench/parts/files/browser/fileTracker.ts index c4edf273acc..5a0d58ae0ab 100644 --- a/src/vs/workbench/parts/files/browser/fileTracker.ts +++ b/src/vs/workbench/parts/files/browser/fileTracker.ts @@ -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, () => this.onEditorInputChanged())); + this.toUnbind.push(this.editorService.onEditorsChanged(() => this.onEditorsChanged())); 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(): void { + private onEditorsChanged(): void { this.disposeUnusedTextFileModels(); } diff --git a/src/vs/workbench/parts/files/browser/textFileServices.ts b/src/vs/workbench/parts/files/browser/textFileServices.ts index b8d064fad42..ca5f1a33afc 100644 --- a/src/vs/workbench/parts/files/browser/textFileServices.ts +++ b/src/vs/workbench/parts/files/browser/textFileServices.ts @@ -11,7 +11,6 @@ import Event, {Emitter} from 'vs/base/common/event'; import {FileEditorInput} from 'vs/workbench/parts/files/browser/editors/fileEditorInput'; import {CACHE, TextFileEditorModel} from 'vs/workbench/parts/files/common/editors/textFileEditorModel'; import {IResult, ITextFileOperationResult, ITextFileService, IAutoSaveConfiguration, AutoSaveMode} from 'vs/workbench/parts/files/common/files'; -import {EventType} from 'vs/workbench/common/events'; import {ConfirmResult} from 'vs/workbench/common/editor'; import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService'; import {IFilesConfiguration, IFileOperationResult, FileOperationResult, AutoSaveConfiguration} from 'vs/platform/files/common/files'; @@ -20,6 +19,7 @@ import {IEventService} from 'vs/platform/event/common/event'; import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {IDisposable, dispose} from 'vs/base/common/lifecycle'; +import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; /** * The workbench file service implementation implements the raw file service spec and adds additional methods on top. @@ -42,6 +42,7 @@ export abstract class TextFileService implements ITextFileService { @IInstantiationService private instantiationService: IInstantiationService, @IConfigurationService private configurationService: IConfigurationService, @ITelemetryService private telemetryService: ITelemetryService, + @IWorkbenchEditorService protected editorService: IWorkbenchEditorService, @IEventService private eventService: IEventService ) { this.listenerToUnbind = []; @@ -68,11 +69,11 @@ export abstract class TextFileService implements ITextFileService { this.listenerToUnbind.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationChange(e.config))); // Editor focus change - window.addEventListener('blur', () => this.onEditorFocusChange(), true); - this.listenerToUnbind.push(this.eventService.addListener2(EventType.EDITOR_INPUT_CHANGED, () => this.onEditorFocusChange())); + window.addEventListener('blur', () => this.onEditorsChanged(), true); + this.listenerToUnbind.push(this.editorService.onEditorsChanged(() => this.onEditorsChanged())); } - private onEditorFocusChange(): void { + private onEditorsChanged(): void { if (this.configuredAutoSaveOnFocusChange && this.getDirty().length) { this.saveAll().done(null, errors.onUnexpectedError); // save dirty files when we change focus in the editor area } diff --git a/src/vs/workbench/parts/files/browser/views/explorerView.ts b/src/vs/workbench/parts/files/browser/views/explorerView.ts index 3cf6c03f3cf..6997c04c503 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerView.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerView.ts @@ -15,7 +15,6 @@ import {Action, IActionRunner, IAction} from 'vs/base/common/actions'; import {prepareActions} from 'vs/workbench/browser/actionBarRegistry'; import {ITree} from 'vs/base/parts/tree/browser/tree'; import {Tree} from 'vs/base/parts/tree/browser/treeImpl'; -import {EventType as WorkbenchEventType} from 'vs/workbench/common/events'; import {EditorOptions} from 'vs/workbench/common/editor'; import {LocalFileChangeEvent, IFilesConfiguration} from 'vs/workbench/parts/files/common/files'; import {IFileStat, IResolveFileOptions, FileChangeType, FileChangesEvent, IFileChange, EventType as FileEventType, IFileService} from 'vs/platform/files/common/files'; @@ -140,14 +139,14 @@ export class ExplorerView extends CollapsibleViewletView { return this.doRefresh().then(() => { // When the explorer viewer is loaded, listen to changes to the editor input - this.toDispose.push(this.eventService.addListener2(WorkbenchEventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChanged())); + this.toDispose.push(this.editorService.onEditorsChanged(() => this.onEditorsChanged())); // Also handle configuration updates this.toDispose.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config, true))); }); } - private onEditorInputChanged(): void { + private onEditorsChanged(): void { let activeInput = this.editorService.getActiveEditorInput(); let clearSelection = true; let clearFocus = false; diff --git a/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts b/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts index 81b411fff36..78a87c57d39 100644 --- a/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts +++ b/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts @@ -86,7 +86,7 @@ export class FileTracker implements IWorkbenchContribution { ipc.on('vscode:openFiles', (event, request: IOpenFileRequest) => this.onOpenFiles(request)); // Editor input changes - this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChanged())); + this.toUnbind.push(this.editorService.onEditorsChanged(() => this.onEditorsChanged())); // Lifecycle this.lifecycleService.onShutdown(this.dispose, this); @@ -165,7 +165,7 @@ export class FileTracker implements IWorkbenchContribution { }); } - private onEditorInputChanged(): void { + private onEditorsChanged(): void { let visibleOutOfWorkspaceResources = this.editorService.getVisibleEditors().map((editor) => { return asFileEditorInput(editor.input, true); }).filter((input) => { diff --git a/src/vs/workbench/parts/files/electron-browser/textFileServices.ts b/src/vs/workbench/parts/files/electron-browser/textFileServices.ts index e16df389568..0bcdba9d578 100644 --- a/src/vs/workbench/parts/files/electron-browser/textFileServices.ts +++ b/src/vs/workbench/parts/files/electron-browser/textFileServices.ts @@ -41,10 +41,10 @@ export class TextFileService extends AbstractTextFileService { @IConfigurationService configurationService: IConfigurationService, @IEventService eventService: IEventService, @IModeService private modeService: IModeService, - @IWorkbenchEditorService private editorService: IWorkbenchEditorService, + @IWorkbenchEditorService editorService: IWorkbenchEditorService, @IWindowService private windowService: IWindowService ) { - super(contextService, instantiationService, configurationService, telemetryService, eventService); + super(contextService, instantiationService, configurationService, telemetryService, editorService, eventService); this.init(); } diff --git a/src/vs/workbench/parts/git/browser/gitServices.ts b/src/vs/workbench/parts/git/browser/gitServices.ts index b9ddc28989b..2e6baada555 100644 --- a/src/vs/workbench/parts/git/browser/gitServices.ts +++ b/src/vs/workbench/parts/git/browser/gitServices.ts @@ -14,7 +14,6 @@ import errors = require('vs/base/common/errors'); import mime = require('vs/base/common/mime'); import paths = require('vs/base/common/paths'); import ee = require('vs/base/common/eventEmitter'); -import wbevents = require('vs/workbench/common/events'); import WorkbenchEditorCommon = require('vs/workbench/common/editor'); import git = require('vs/workbench/parts/git/common/git'); import model = require('vs/workbench/parts/git/common/gitModel'); @@ -216,7 +215,7 @@ class EditorInputCache */ private eventuallyDispose(editorInput: WorkbenchEditorCommon.EditorInput): void { if (!this.maybeDispose(editorInput)) { - var listener = this.eventService.addListener2(wbevents.EventType.EDITOR_INPUT_CHANGED, () => { + var listener = this.editorService.onEditorsChanged(() => { if (this.maybeDispose(editorInput)) { listener.dispose(); } diff --git a/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts b/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts index a9783372846..4f97af19259 100644 --- a/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts +++ b/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts @@ -14,7 +14,6 @@ import lifecycle = require('vs/base/common/lifecycle'); import winjs = require('vs/base/common/winjs.base'); import ext = require('vs/workbench/common/contributions'); import git = require('vs/workbench/parts/git/common/git'); -import workbenchEvents = require('vs/workbench/common/events'); import common = require('vs/editor/common/editorCommon'); import widget = require('vs/editor/browser/widget/codeEditorWidget'); import viewlet = require('vs/workbench/browser/viewlet'); @@ -351,7 +350,7 @@ export class DirtyDiffDecorator implements ext.IWorkbenchContribution { this.models = []; this.decorators = Object.create(null); this.toDispose = []; - this.toDispose.push(eventService.addListener2(workbenchEvents.EventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChange())); + this.toDispose.push(editorService.onEditorsChanged(() => this.onEditorsChanged())); this.toDispose.push(gitService.addListener2(git.ServiceEvents.DISPOSE, () => this.dispose())); } @@ -359,7 +358,7 @@ export class DirtyDiffDecorator implements ext.IWorkbenchContribution { return 'git.DirtyDiffModelDecorator'; } - private onEditorInputChange(): void { + private onEditorsChanged(): void { // HACK: This is the best current way of figuring out whether to draw these decorations // or not. Needs context from the editor, to know whether it is a diff editor, in place editor // etc. @@ -368,7 +367,7 @@ export class DirtyDiffDecorator implements ext.IWorkbenchContribution { // If there is no repository root, just wait until that changes if (typeof repositoryRoot !== 'string') { - this.gitService.addOneTimeDisposableListener(git.ServiceEvents.STATE_CHANGED, () => this.onEditorInputChange()); + this.gitService.addOneTimeDisposableListener(git.ServiceEvents.STATE_CHANGED, () => this.onEditorsChanged()); this.models.forEach(m => this.onModelInvisible(m)); this.models = []; diff --git a/src/vs/workbench/parts/git/browser/views/changes/changesView.ts b/src/vs/workbench/parts/git/browser/views/changes/changesView.ts index 0f188c4c6ff..92c3fe67fb7 100644 --- a/src/vs/workbench/parts/git/browser/views/changes/changesView.ts +++ b/src/vs/workbench/parts/git/browser/views/changes/changesView.ts @@ -20,7 +20,6 @@ import Actions = require('vs/base/common/actions'); import ActionBar = require('vs/base/browser/ui/actionbar/actionbar'); import Tree = require('vs/base/parts/tree/browser/tree'); import TreeImpl = require('vs/base/parts/tree/browser/treeImpl'); -import WorkbenchEvents = require('vs/workbench/common/events'); import git = require('vs/workbench/parts/git/common/git'); import GitView = require('vs/workbench/parts/git/browser/views/view'); import GitActions = require('vs/workbench/parts/git/browser/gitActions'); @@ -103,7 +102,7 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV this.toDispose = [ this.smartCommitAction = this.instantiationService.createInstance(GitActions.SmartCommitAction, this), - eventService.addListener2(WorkbenchEvents.EventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChanged(this.editorService.getActiveEditorInput()).done(null, Errors.onUnexpectedError)), + editorService.onEditorsChanged(() => this.onEditorsChanged(this.editorService.getActiveEditorInput()).done(null, Errors.onUnexpectedError)), this.gitService.addListener2(git.ServiceEvents.OPERATION_START, (e) => this.onGitOperationStart(e)), this.gitService.addListener2(git.ServiceEvents.OPERATION_END, (e) => this.onGitOperationEnd(e)), this.gitService.getModel().addListener2(git.ModelEvents.MODEL_UPDATED, this.onGitModelUpdate.bind(this)) @@ -217,7 +216,7 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV if (visible) { this.tree.onVisible(); - return this.onEditorInputChanged(this.editorService.getActiveEditorInput()); + return this.onEditorsChanged(this.editorService.getActiveEditorInput()); } else { this.tree.onHidden(); @@ -289,7 +288,7 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV } } - private onEditorInputChanged(input: IEditorInput): WinJS.TPromise { + private onEditorsChanged(input: IEditorInput): WinJS.TPromise { if (!this.tree) { return WinJS.TPromise.as(null); } diff --git a/src/vs/workbench/parts/markdown/browser/markdownExtension.ts b/src/vs/workbench/parts/markdown/browser/markdownExtension.ts index d83b606c5c1..834dae3f8a6 100644 --- a/src/vs/workbench/parts/markdown/browser/markdownExtension.ts +++ b/src/vs/workbench/parts/markdown/browser/markdownExtension.ts @@ -13,7 +13,6 @@ import {getBaseThemeId} from 'vs/platform/theme/common/themes'; import {IWorkbenchContribution} from 'vs/workbench/common/contributions'; import {IFrameEditor} from 'vs/workbench/browser/parts/editor/iframeEditor'; import {MarkdownEditorInput} from 'vs/workbench/parts/markdown/common/markdownEditorInput'; -import {EventType as WorkbenchEventType} from 'vs/workbench/common/events'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService'; import {IConfigurationService, IConfigurationServiceEvent} from 'vs/platform/configuration/common/configuration'; @@ -67,7 +66,7 @@ export class MarkdownFileTracker implements IWorkbenchContribution { this.configFileChangeListener = this.configurationService.onDidUpdateConfiguration(e => this.onConfigFileChange(e)); // reload markdown editors when their resources change - this.editorInputChangeListener = this.eventService.addListener2(WorkbenchEventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChanged()); + this.editorInputChangeListener = this.editorService.onEditorsChanged(() => this.onEditorsChanged()); // initially read the config for CSS styles in preview this.readMarkdownConfiguration(this.configurationService.getConfiguration()); @@ -79,7 +78,7 @@ export class MarkdownFileTracker implements IWorkbenchContribution { }); } - private onEditorInputChanged(): void { + private onEditorsChanged(): void { let input = this.editorService.getActiveEditorInput(); if (input instanceof MarkdownEditorInput) { let markdownResource = input.getResource(); diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index 164523c744e..886ad09be6a 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -24,8 +24,14 @@ import {IEditorInput, IEditorModel, IEditorOptions, Position, Direction, IEditor import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; import {AsyncDescriptor0} from 'vs/platform/instantiation/common/descriptors'; import {IEditorStacksModel} from 'vs/workbench/common/editor/editorStacksModel'; +import Event from 'vs/base/common/event'; export interface IEditorPart { + + // Events + onEditorsChanged: Event; + + // Methods openEditor(input?: EditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise; openEditor(input?: EditorInput, options?: EditorOptions, position?: Position): TPromise; openEditors(editors: { input: EditorInput, position: Position, options?: EditorOptions }[]): TPromise; @@ -62,6 +68,10 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { this.fileInputDescriptor = (Registry.as(Extensions.Editors)).getDefaultFileInput(); } + public get onEditorsChanged(): Event { + return this.editorPart.onEditorsChanged; + } + public getActiveEditor(): IEditor { return this.editorPart.getActiveEditor(); } diff --git a/src/vs/workbench/services/editor/common/editorService.ts b/src/vs/workbench/services/editor/common/editorService.ts index a5151620629..a29342a53ed 100644 --- a/src/vs/workbench/services/editor/common/editorService.ts +++ b/src/vs/workbench/services/editor/common/editorService.ts @@ -8,6 +8,7 @@ import {TPromise} from 'vs/base/common/winjs.base'; import {createDecorator, ServiceIdentifier} from 'vs/platform/instantiation/common/instantiation'; import {IEditorService, IEditor, IEditorInput, IEditorOptions, Position, Direction, IResourceInput, IEditorModel, ITextEditorModel} from 'vs/platform/editor/common/editor'; import {IEditorStacksModel} from 'vs/workbench/common/editor/editorStacksModel'; +import Event from 'vs/base/common/event'; export enum GroupArrangement { MINIMIZE_OTHERS, @@ -23,6 +24,11 @@ export var IWorkbenchEditorService = createDecorator('e export interface IWorkbenchEditorService extends IEditorService { serviceId : ServiceIdentifier; + /** + * Emitted when editors or inputs change. Examples: opening, closing of editors. Active editor change. + */ + onEditorsChanged: Event; + /** * Returns the currently active editor or null if none. */ diff --git a/src/vs/workbench/services/history/browser/history.ts b/src/vs/workbench/services/history/browser/history.ts index ff973ddbe9d..8a7d4d54313 100644 --- a/src/vs/workbench/services/history/browser/history.ts +++ b/src/vs/workbench/services/history/browser/history.ts @@ -11,7 +11,6 @@ import {EventType} from 'vs/base/common/events'; import {IEditor as IBaseEditor} from 'vs/platform/editor/common/editor'; import {TextEditorOptions, EditorInput} from 'vs/workbench/common/editor'; import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor'; -import {EventType as WorkbenchEventType} from 'vs/workbench/common/events'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; import {IHistoryService} from 'vs/workbench/services/history/common/history'; import {Selection} from 'vs/editor/common/core/selection'; @@ -81,10 +80,10 @@ export abstract class BaseHistoryService { window.document.title = this.getWindowTitle(null); // Editor Input Changes - this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChanged())); + this.toUnbind.push(this.editorService.onEditorsChanged(() => this.onEditorsChanged())); } - private onEditorInputChanged(): void { + private onEditorsChanged(): void { // Dispose old listeners dispose(this.activeEditorListeners); diff --git a/src/vs/workbench/test/browser/parts/quickOpen/quickopen.test.ts b/src/vs/workbench/test/browser/parts/quickOpen/quickopen.test.ts index c21d121fa45..4f6d3f6708a 100644 --- a/src/vs/workbench/test/browser/parts/quickOpen/quickopen.test.ts +++ b/src/vs/workbench/test/browser/parts/quickOpen/quickopen.test.ts @@ -223,7 +223,7 @@ suite('Workbench QuickOpen', () => { let cinput1 = inst.createInstance(fileInputCtor, toResource('Hello World'), 'text/plain', null); editorService.activeEditorInput = cinput1; - eventService.emit(EventType.EDITOR_INPUT_CHANGED, {}); + editorService.fireChange(); assert.equal(1, controller.getEditorHistoryModel().getEntries().length); diff --git a/src/vs/workbench/test/browser/services.test.ts b/src/vs/workbench/test/browser/services.test.ts index a59696a13cd..91c2ca82799 100644 --- a/src/vs/workbench/test/browser/services.test.ts +++ b/src/vs/workbench/test/browser/services.test.ts @@ -43,6 +43,7 @@ import {Position, Direction, IEditor} from 'vs/platform/editor/common/editor'; import {IEventService} from 'vs/platform/event/common/event'; import {createMockModeService, createMockModelService} from 'vs/editor/test/common/servicesTestUtils'; import {IEditorStacksModel} from 'vs/workbench/common/editor/editorStacksModel'; +import Event from 'vs/base/common/event'; let activeViewlet: Viewlet = {}; let activeEditor: BaseEditor = { @@ -70,6 +71,10 @@ class TestEditorPart implements IEditorPart { return TPromise.as([]); } + public get onEditorsChanged(): Event { + return null; + } + public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: any }[]): TPromise { return TPromise.as([]); } diff --git a/src/vs/workbench/test/common/servicesTestUtils.ts b/src/vs/workbench/test/common/servicesTestUtils.ts index e70905767b1..73553df7c8e 100644 --- a/src/vs/workbench/test/common/servicesTestUtils.ts +++ b/src/vs/workbench/test/common/servicesTestUtils.ts @@ -292,9 +292,13 @@ export class TestEditorService implements WorkbenchEditorService.IWorkbenchEdito private callback: (method: string) => void; private stacksModel: EditorStacksModel; + private _onEditorsChanged: Emitter; + constructor(callback?: (method: string) => void) { this.callback = callback || ((s: string) => { }); + this._onEditorsChanged = new Emitter(); + let services = new ServiceCollection(); services.set(IStorageService, new TestStorageService()); @@ -307,6 +311,14 @@ export class TestEditorService implements WorkbenchEditorService.IWorkbenchEdito this.stacksModel = inst.createInstance(EditorStacksModel); } + public fireChange(): void { + this._onEditorsChanged.fire(); + } + + public get onEditorsChanged(): Event { + return this._onEditorsChanged.event; + } + public openEditors(inputs): Promise { return TPromise.as([]); }