From a0d84f383c24361ee2dc59ee4db030c16a883d39 Mon Sep 17 00:00:00 2001 From: Karl Burtram Date: Thu, 10 Jan 2019 12:51:41 -0800 Subject: [PATCH] Generate temp files as not dirty (#3698) * Generate temp files as not dirty * Remove whitespace --- src/sql/parts/query/common/query.contribution.ts | 8 +++++--- src/sql/parts/query/common/queryEditorService.ts | 2 +- src/sql/parts/query/services/queryEditorService.ts | 9 +++++++-- src/vs/workbench/common/editor/editorGroup.ts | 9 +++++++++ src/vs/workbench/common/editor/untitledEditorModel.ts | 4 +++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/sql/parts/query/common/query.contribution.ts b/src/sql/parts/query/common/query.contribution.ts index 6eea5b35e6..a650c239db 100644 --- a/src/sql/parts/query/common/query.contribution.ts +++ b/src/sql/parts/query/common/query.contribution.ts @@ -346,6 +346,11 @@ let registryProperties = { 'description': localize('showConnectionInfoInTitle', "Controls whether to show the connection info for a tab in the title."), 'default': true }, + 'sql.promptToSaveGeneratedFiles': { + 'type': 'boolean', + 'default': false, + 'description': localize('sql.promptToSaveGeneratedFiles', 'Prompt to save generated SQL files') + }, 'mssql.intelliSense.enableIntelliSense': { 'type': 'boolean', 'default': true, @@ -413,6 +418,3 @@ configurationRegistry.registerConfiguration({ 'type': 'object', 'properties': registryProperties }); - - - diff --git a/src/sql/parts/query/common/queryEditorService.ts b/src/sql/parts/query/common/queryEditorService.ts index 33cbffd8c7..ddd3a37891 100644 --- a/src/sql/parts/query/common/queryEditorService.ts +++ b/src/sql/parts/query/common/queryEditorService.ts @@ -24,7 +24,7 @@ export interface IQueryEditorService { _serviceBrand: any; // Creates new untitled document for SQL queries and opens it in a new editor tab - newSqlEditor(sqlContent?: string, connectionProviderName?: string): Promise; + newSqlEditor(sqlContent?: string, connectionProviderName?: string, isDirty?: boolean): Promise; // Creates a new query plan document newQueryPlanEditor(xmlShowPlan: string): Promise; diff --git a/src/sql/parts/query/services/queryEditorService.ts b/src/sql/parts/query/services/queryEditorService.ts index a9949b4084..12254802bc 100644 --- a/src/sql/parts/query/services/queryEditorService.ts +++ b/src/sql/parts/query/services/queryEditorService.ts @@ -29,6 +29,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati import { EditDataResultsInput } from 'sql/parts/editData/common/editDataResultsInput'; import { IEditorInput, IEditor } from 'vs/workbench/common/editor'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; const fs = require('fs'); @@ -61,7 +62,8 @@ export class QueryEditorService implements IQueryEditorService { @IEditorService private _editorService: IEditorService, @IEditorGroupsService private _editorGroupService: IEditorGroupsService, @INotificationService private _notificationService: INotificationService, - @IConnectionManagementService private _connectionManagementService: IConnectionManagementService + @IConnectionManagementService private _connectionManagementService: IConnectionManagementService, + @IConfigurationService private _configurationService: IConfigurationService ) { QueryEditorService.editorService = _editorService; QueryEditorService.instantiationService = _instantiationService; @@ -74,7 +76,7 @@ export class QueryEditorService implements IQueryEditorService { /** * Creates new untitled document for SQL query and opens in new editor tab */ - public newSqlEditor(sqlContent?: string, connectionProviderName?: string): Promise { + public newSqlEditor(sqlContent?: string, connectionProviderName?: string, isDirty?: boolean): Promise { return new Promise((resolve, reject) => { try { // Create file path and file URI @@ -86,6 +88,9 @@ export class QueryEditorService implements IQueryEditorService { fileInput.resolve().then(m => { if (sqlContent) { m.textEditorModel.setValue(sqlContent); + if (isDirty === false || (isDirty === undefined && !this._configurationService.getValue('sql.promptToSaveGeneratedFiles'))) { + m.setDirty(false); + } } }); diff --git a/src/vs/workbench/common/editor/editorGroup.ts b/src/vs/workbench/common/editor/editorGroup.ts index e0797d7e1e..42412a227f 100644 --- a/src/vs/workbench/common/editor/editorGroup.ts +++ b/src/vs/workbench/common/editor/editorGroup.ts @@ -16,6 +16,7 @@ import { ResourceMap } from 'vs/base/common/map'; // {{SQL CARBON EDIT}} import { QueryInput } from 'sql/parts/query/common/queryInput'; +import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; import * as CustomInputConverter from 'sql/parts/common/customInputConverter'; const EditorOpenPositioning = { @@ -631,6 +632,14 @@ export class EditorGroup extends Disposable { editors.forEach(e => { let factory = registry.getEditorInputFactory(e.getTypeId()); if (factory) { + + // {{SQL CARBON EDIT}} + // don't serialize unmodified unitited files + if (e instanceof UntitledEditorInput && !e.isDirty() + && !this.configurationService.getValue('sql.promptToSaveGeneratedFiles')) { + return; + } + let value = factory.serialize(e); if (typeof value === 'string') { serializedEditors.push({ id: e.getTypeId(), value }); diff --git a/src/vs/workbench/common/editor/untitledEditorModel.ts b/src/vs/workbench/common/editor/untitledEditorModel.ts index eaffc0526c..d72323d94f 100644 --- a/src/vs/workbench/common/editor/untitledEditorModel.ts +++ b/src/vs/workbench/common/editor/untitledEditorModel.ts @@ -115,7 +115,9 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin return this.dirty; } - private setDirty(dirty: boolean): void { + // {{SQL CARBON EDIT}} + // make property public + public setDirty(dirty: boolean): void { if (this.dirty === dirty) { return; }