diff --git a/src/vs/workbench/browser/parts/editor/stringEditor.ts b/src/vs/workbench/browser/parts/editor/stringEditor.ts index f530f11c46f..1812f99ac25 100644 --- a/src/vs/workbench/browser/parts/editor/stringEditor.ts +++ b/src/vs/workbench/browser/parts/editor/stringEditor.ts @@ -51,10 +51,10 @@ export class StringEditor extends BaseTextEditor { this.mapResourceToEditorViewState = Object.create(null); - this.toUnbind.push(this.eventService.addListener2(EventType.UNTITLED_FILE_SAVED, (e: UntitledEditorEvent) => this.onUntitledSavedEvent(e))); + this.toUnbind.push(this.eventService.addListener2(EventType.UNTITLED_FILE_DELETED, (e: UntitledEditorEvent) => this.onUntitledDeletedEvent(e))); } - private onUntitledSavedEvent(e: UntitledEditorEvent): void { + private onUntitledDeletedEvent(e: UntitledEditorEvent): void { delete this.mapResourceToEditorViewState[e.resource.toString()]; } diff --git a/src/vs/workbench/common/editor/untitledEditorInput.ts b/src/vs/workbench/common/editor/untitledEditorInput.ts index 63b169ce2d9..9e1306354e0 100644 --- a/src/vs/workbench/common/editor/untitledEditorInput.ts +++ b/src/vs/workbench/common/editor/untitledEditorInput.ts @@ -58,7 +58,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { } private registerListeners(): void { - this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, (e: UntitledEditorEvent) => this.onDirtyStateChange(e))); + this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, (e: UntitledEditorEvent) => this.onDirtyStateChange(e))); this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DIRTY, (e: UntitledEditorEvent) => this.onDirtyStateChange(e))); } @@ -97,9 +97,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { } public revert(): TPromise { - this.cachedModel.revert(); - - return TPromise.as(true); + return this.textFileService.revert(this.resource); } public suggestFileName(): string { @@ -181,15 +179,15 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { public dispose(): void { - // Listeners - dispose(this.toUnbind); - // Model if (this.cachedModel) { this.cachedModel.dispose(); this.cachedModel = null; } + // Listeners + dispose(this.toUnbind); + super.dispose(); } } \ No newline at end of file diff --git a/src/vs/workbench/common/editor/untitledEditorModel.ts b/src/vs/workbench/common/editor/untitledEditorModel.ts index fae42740555..2e56ef52901 100644 --- a/src/vs/workbench/common/editor/untitledEditorModel.ts +++ b/src/vs/workbench/common/editor/untitledEditorModel.ts @@ -86,12 +86,6 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS return this.dirty; } - public revert(): void { - this.dirty = false; - - this.eventService.emit(WorkbenchEventType.UNTITLED_FILE_SAVED, new UntitledEditorEvent(this.resource)); - } - public load(): TPromise { return super.load().then((model) => { const configuration = this.configurationService.getConfiguration(); @@ -123,6 +117,8 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS public dispose(): void { super.dispose(); + this.dirty = false; // we can no longer be dirty + if (this.textModelChangeListener) { this.textModelChangeListener.dispose(); this.textModelChangeListener = null; @@ -132,5 +128,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS this.configurationChangeListener.dispose(); this.configurationChangeListener = null; } + + this.eventService.emit(WorkbenchEventType.UNTITLED_FILE_DELETED, new UntitledEditorEvent(this.resource)); } } \ No newline at end of file diff --git a/src/vs/workbench/common/events.ts b/src/vs/workbench/common/events.ts index 85d595b824f..5247264ee05 100644 --- a/src/vs/workbench/common/events.ts +++ b/src/vs/workbench/common/events.ts @@ -33,9 +33,9 @@ export class EventType { static UNTITLED_FILE_DIRTY = 'untitledFileDirty'; /** - * Event type for when an untitled file is saved. + * Event type for when an untitled file is deleted. */ - static UNTITLED_FILE_SAVED = 'untitledFileSaved'; + static UNTITLED_FILE_DELETED = 'untitledFileDeleted'; /** * Event type for when a resources encoding changes. diff --git a/src/vs/workbench/parts/files/browser/fileActions.ts b/src/vs/workbench/parts/files/browser/fileActions.ts index 4f73160ccc1..8fd49f80646 100644 --- a/src/vs/workbench/parts/files/browser/fileActions.ts +++ b/src/vs/workbench/parts/files/browser/fileActions.ts @@ -1535,7 +1535,7 @@ export abstract class BaseSaveAllAction extends BaseActionWithErrorReporting { if (this.includeUntitled()) { this.toDispose.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DIRTY, () => this.updateEnablement(true))); - this.toDispose.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, () => this.updateEnablement(false))); + this.toDispose.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, () => this.updateEnablement(false))); } } diff --git a/src/vs/workbench/parts/files/browser/fileTracker.ts b/src/vs/workbench/parts/files/browser/fileTracker.ts index 3704f098e1b..d651542c072 100644 --- a/src/vs/workbench/parts/files/browser/fileTracker.ts +++ b/src/vs/workbench/parts/files/browser/fileTracker.ts @@ -65,7 +65,7 @@ export class FileTracker implements IWorkbenchContribution { // Update editors and inputs from local changes and saves this.toUnbind.push(this.editorGroupService.onEditorsChanged(() => this.onEditorsChanged())); - this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, (e: UntitledEditorEvent) => this.onUntitledEditorSaved(e))); + 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))); this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_SAVE_ERROR, (e: TextFileChangeEvent) => this.onTextFileSaveError(e))); @@ -107,7 +107,7 @@ export class FileTracker implements IWorkbenchContribution { this.updateActivityBadge(); } - private onUntitledEditorSaved(e: UntitledEditorEvent): void { + private onUntitledEditorDeleted(e: UntitledEditorEvent): void { if (this.lastDirtyCount > 0) { this.updateActivityBadge(); } diff --git a/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts b/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts index b1a414925df..487a6e1da1d 100644 --- a/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts +++ b/src/vs/workbench/parts/files/electron-browser/electronFileTracker.ts @@ -77,7 +77,7 @@ export class FileTracker implements IWorkbenchContribution { private registerListeners(): void { // Local text file changes - this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, () => this.onUntitledSavedEvent())); + this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, () => this.onUntitledDeletedEvent())); this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DIRTY, () => this.onUntitledDirtyEvent())); this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_DIRTY, (e: TextFileChangeEvent) => this.onTextFileDirty(e))); this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_SAVED, (e: TextFileChangeEvent) => this.onTextFileSaved(e))); @@ -199,7 +199,7 @@ export class FileTracker implements IWorkbenchContribution { } } - private onUntitledSavedEvent(): void { + private onUntitledDeletedEvent(): void { if (this.isDocumentedEdited) { this.updateDocumentEdited(); } diff --git a/src/vs/workbench/parts/files/electron-browser/textFileServices.ts b/src/vs/workbench/parts/files/electron-browser/textFileServices.ts index 33ced42460f..7d5302f9c8a 100644 --- a/src/vs/workbench/parts/files/electron-browser/textFileServices.ts +++ b/src/vs/workbench/parts/files/electron-browser/textFileServices.ts @@ -117,8 +117,17 @@ export class TextFileService extends AbstractTextFileService { return super.revertAll(resources, force).then(r => { // Revert untitled - const reverted = this.untitledEditorService.revertAll(resources); - reverted.forEach(res => r.results.push({ source: res, success: true })); + let untitledInputs = this.untitledEditorService.getAll(resources); + untitledInputs.forEach(input => { + if (input) { + input.dispose(); + + r.results.push({ + source: input.getResource(), + success: true + }); + } + }); return r; }); diff --git a/src/vs/workbench/parts/search/browser/searchViewlet.ts b/src/vs/workbench/parts/search/browser/searchViewlet.ts index 0c01d0a10ec..56e3e857fec 100644 --- a/src/vs/workbench/parts/search/browser/searchViewlet.ts +++ b/src/vs/workbench/parts/search/browser/searchViewlet.ts @@ -692,7 +692,7 @@ export class SearchViewlet extends Viewlet { this.viewletSettings = this.getMemento(storageService, Scope.WORKSPACE); this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_CHANGES, (e) => this.onFilesChanged(e))); - this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, (e) => this.onUntitledFileSaved(e))); + this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, (e) => this.onUntitledFileDeleted(e))); this.toUnbind.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config))); } @@ -1456,7 +1456,7 @@ export class SearchViewlet extends Viewlet { }, sideBySide); } - private onUntitledFileSaved(e: UntitledEditorEvent): void { + private onUntitledFileDeleted(e: UntitledEditorEvent): void { if (!this.viewModel) { return; } diff --git a/src/vs/workbench/services/untitled/common/untitledEditorService.ts b/src/vs/workbench/services/untitled/common/untitledEditorService.ts index dcf869e4d93..2107f71c889 100644 --- a/src/vs/workbench/services/untitled/common/untitledEditorService.ts +++ b/src/vs/workbench/services/untitled/common/untitledEditorService.ts @@ -36,11 +36,6 @@ export interface IUntitledEditorService { */ isDirty(resource: URI): boolean; - /** - * Reverts the untitled resources if found. - */ - revertAll(resources?: URI[]): URI[]; - /** * Creates a new untitled input with the optional resource URI or returns an existing one * if the provided resource exists already as untitled input. @@ -77,21 +72,6 @@ export class UntitledEditorService implements IUntitledEditorService { return Object.keys(UntitledEditorService.CACHE).map((key) => UntitledEditorService.CACHE[key]); } - public revertAll(resources?: URI[], force?: boolean): URI[] { - const reverted: URI[] = []; - - const untitledInputs = this.getAll(resources); - untitledInputs.forEach(input => { - if (input) { - input.revert(); - - reverted.push(input.getResource()); - } - }); - - return reverted; - } - public isDirty(resource: URI): boolean { let input = this.get(resource); diff --git a/src/vs/workbench/test/common/servicesTestUtils.ts b/src/vs/workbench/test/common/servicesTestUtils.ts index 4c773cef9cb..9cb30e53938 100644 --- a/src/vs/workbench/test/common/servicesTestUtils.ts +++ b/src/vs/workbench/test/common/servicesTestUtils.ts @@ -295,10 +295,6 @@ export class TestUntitledEditorService implements IUntitledEditorService { return []; } - public revertAll(resources?: URI[]): URI[] { - return []; - } - public isDirty() { return false; }