From 6d3995aa298394db3d9fb992e883fcf21e5fbbe0 Mon Sep 17 00:00:00 2001 From: Matt Irvine Date: Thu, 11 Jan 2018 14:29:26 -0800 Subject: [PATCH] Enable hot exit for saved files (#469) --- src/sql/parts/dashboard/dashboardInput.ts | 3 +-- src/sql/parts/query/common/queryInput.ts | 2 +- .../parts/editor/editor.contribution.ts | 18 +++---------- .../common/editor/editorStacksModel.ts | 25 ++++++++++++++++--- .../parts/files/browser/files.contribution.ts | 2 +- .../textfile/common/textFileService.ts | 5 +--- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/sql/parts/dashboard/dashboardInput.ts b/src/sql/parts/dashboard/dashboardInput.ts index b4436cbbef..f3bd15f355 100644 --- a/src/sql/parts/dashboard/dashboardInput.ts +++ b/src/sql/parts/dashboard/dashboardInput.ts @@ -5,7 +5,6 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { EditorInput, EditorModel } from 'vs/workbench/common/editor'; -import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; import { IDisposable } from 'vs/base/common/lifecycle'; import URI from 'vs/base/common/uri'; import { IModelService } from 'vs/editor/common/services/modelService'; @@ -70,7 +69,7 @@ export class DashboardInput extends EditorInput { } public getTypeId(): string { - return UntitledEditorInput.ID; + return DashboardInput.ID; } public getResource(): URI { diff --git a/src/sql/parts/query/common/queryInput.ts b/src/sql/parts/query/common/queryInput.ts index b0275df8be..ffb5a67d70 100644 --- a/src/sql/parts/query/common/queryInput.ts +++ b/src/sql/parts/query/common/queryInput.ts @@ -116,7 +116,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec public getQueryResultsInputResource(): string { return this._results.uri; } public showQueryResultsEditor(): void { this._showQueryResultsEditor.fire(); } public updateSelection(selection: ISelectionData): void { this._updateSelection.fire(selection); } - public getTypeId(): string { return UntitledEditorInput.ID; } + public getTypeId(): string { return QueryInput.ID; } public getDescription(): string { return this._description; } public supportsSplitEditor(): boolean { return false; } public getModeId(): string { return QueryInput.SCHEMA; } diff --git a/src/vs/workbench/browser/parts/editor/editor.contribution.ts b/src/vs/workbench/browser/parts/editor/editor.contribution.ts index 05591013b3..24b758468a 100644 --- a/src/vs/workbench/browser/parts/editor/editor.contribution.ts +++ b/src/vs/workbench/browser/parts/editor/editor.contribution.ts @@ -42,10 +42,6 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { isMacintosh } from 'vs/base/common/platform'; import { GroupOnePicker, GroupTwoPicker, GroupThreePicker, AllEditorsPicker } from 'vs/workbench/browser/parts/editor/editorPicker'; -// {{SQL CARBON EDIT}} -import { QueryResultsInput } from 'sql/parts/query/common/queryResultsInput'; -import { QueryInput } from 'sql/parts/query/common/queryInput'; - // Register String Editor Registry.as(EditorExtensions.Editors).registerEditor( new EditorDescriptor( @@ -136,23 +132,15 @@ class UntitledEditorInputFactory implements IEditorInputFactory { return JSON.stringify(serialized); } - // {{SQL CARBON EDIT}} - public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput { - return instantiationService.invokeFunction(accessor => { + public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): UntitledEditorInput { + return instantiationService.invokeFunction(accessor => { const deserialized: ISerializedUntitledEditorInput = JSON.parse(serializedEditorInput); const resource = !!deserialized.resourceJSON ? URI.revive(deserialized.resourceJSON) : URI.parse(deserialized.resource); const filePath = resource.scheme === 'file' ? resource.fsPath : void 0; const language = deserialized.modeId; const encoding = deserialized.encoding; - // {{SQL CARBON EDIT}} - let input = accessor.get(IWorkbenchEditorService).createInput({ resource, filePath, language, encoding }) as UntitledEditorInput; - if (deserialized.modeId === QueryInput.SCHEMA) { - const queryResultsInput: QueryResultsInput = instantiationService.createInstance(QueryResultsInput, resource.toString()); - return instantiationService.createInstance(QueryInput, input.getName(), '', input, queryResultsInput, undefined); - } else { - return input; - } + return accessor.get(IWorkbenchEditorService).createInput({ resource, filePath, language, encoding }) as UntitledEditorInput; }); } } diff --git a/src/vs/workbench/common/editor/editorStacksModel.ts b/src/vs/workbench/common/editor/editorStacksModel.ts index dffc099b2c..fb6d754bb3 100644 --- a/src/vs/workbench/common/editor/editorStacksModel.ts +++ b/src/vs/workbench/common/editor/editorStacksModel.ts @@ -17,6 +17,10 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { Position, Direction } from 'vs/platform/editor/common/editor'; import { ResourceMap } from 'vs/base/common/map'; +// {{SQL CARBON EDIT}} +import { QueryInput } from 'sql/parts/query/common/queryInput'; +import * as CustomInputConverter from 'sql/parts/common/customInputConverter'; + export interface EditorCloseEvent extends IEditorCloseEvent { editor: EditorInput; } @@ -643,7 +647,14 @@ export class EditorGroup implements IEditorGroup { let serializableEditors: EditorInput[] = []; let serializedEditors: ISerializedEditorInput[] = []; let serializablePreviewIndex: number; - this.editors.forEach(e => { + // {{SQL CARBON EDIT}} + let editors = this.editors.map(e => { + if (e instanceof QueryInput) { + return e.sql; + } + return e; + }); + editors.forEach(e => { let factory = registry.getEditorInputFactory(e.getTypeId()); if (factory) { let value = factory.serialize(e); @@ -658,7 +669,14 @@ export class EditorGroup implements IEditorGroup { } }); - const serializableMru = this.mru.map(e => this.indexOf(e, serializableEditors)).filter(i => i >= 0); + // {{SQL CARBON EDIT}} + let mru = this.mru.map(e => { + if (e instanceof QueryInput) { + return e.sql; + } + return e; + }); + const serializableMru = mru.map(e => this.indexOf(e, serializableEditors)).filter(i => i >= 0); return { label: this.label, @@ -680,7 +698,8 @@ export class EditorGroup implements IEditorGroup { this.hookEditorListeners(editor); this.updateResourceMap(editor, false /* add */); - return editor; + // {{SQL CARBON EDIT}} + return CustomInputConverter.convertEditorInput(editor, undefined, this.instantiationService); } return null; diff --git a/src/vs/workbench/parts/files/browser/files.contribution.ts b/src/vs/workbench/parts/files/browser/files.contribution.ts index 082d02bc8d..39b618b3fa 100644 --- a/src/vs/workbench/parts/files/browser/files.contribution.ts +++ b/src/vs/workbench/parts/files/browser/files.contribution.ts @@ -267,7 +267,7 @@ configurationRegistry.registerConfiguration({ 'files.hotExit': { 'type': 'string', 'enum': [HotExitConfiguration.OFF, HotExitConfiguration.ON_EXIT, HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE], - 'default': HotExitConfiguration.ON_EXIT, + 'default': HotExitConfiguration.OFF, 'enumDescriptions': [ nls.localize('hotExit.off', 'Disable hot exit.'), nls.localize('hotExit.onExit', 'Hot exit will be triggered when the application is closed, that is when the last window is closed on Windows/Linux or when the workbench.action.quit command is triggered (command palette, keybinding, menu). All windows with backups will be restored upon next launch.'), diff --git a/src/vs/workbench/services/textfile/common/textFileService.ts b/src/vs/workbench/services/textfile/common/textFileService.ts index bf8172bfc1..48c67ed270 100644 --- a/src/vs/workbench/services/textfile/common/textFileService.ts +++ b/src/vs/workbench/services/textfile/common/textFileService.ts @@ -366,10 +366,7 @@ export abstract class TextFileService implements ITextFileService { } // Hot exit - // {{SQL CARBON EDIT}} - - // const hotExitMode = configuration && configuration.files ? configuration.files.hotExit : HotExitConfiguration.ON_EXIT; - const hotExitMode = HotExitConfiguration.OFF; + const hotExitMode = configuration && configuration.files ? configuration.files.hotExit : HotExitConfiguration.ON_EXIT; if (hotExitMode === HotExitConfiguration.OFF || hotExitMode === HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE) { this.configuredHotExit = hotExitMode; } else {