From 71ca37aa1efed933bd453c0d94b3d78aa9d3362a Mon Sep 17 00:00:00 2001 From: Monica Gupta Date: Fri, 30 Oct 2020 10:10:34 -0700 Subject: [PATCH 1/8] draft commit --- .../clipboard/browser/clipboardService.ts | 4 + .../query/browser/keyboardQueryActions.ts | 96 ++++++++++++++++++- .../query/browser/query.contribution.ts | 12 ++- .../services/query/common/gridDataProvider.ts | 3 +- .../clipboard/browser/clipboardService.ts | 4 + .../clipboard/common/clipboardService.ts | 4 + src/vs/platform/electron/common/electron.ts | 1 + .../electron-main/electronMainService.ts | 4 + .../electron-sandbox/clipboardService.ts | 4 + .../electron-browser/workbenchTestServices.ts | 1 + 10 files changed, 130 insertions(+), 3 deletions(-) diff --git a/src/sql/platform/clipboard/browser/clipboardService.ts b/src/sql/platform/clipboard/browser/clipboardService.ts index 6a724631ca9b..09673acd377c 100644 --- a/src/sql/platform/clipboard/browser/clipboardService.ts +++ b/src/sql/platform/clipboard/browser/clipboardService.ts @@ -25,6 +25,10 @@ export class BrowserClipboardService implements IClipboardService { this._notificationService.info(localize('imageCopyingNotSupported', "Copying images is not supported")); } + write(data: string): Promise { + return this._vsClipboardService.writeText(data); // throw not implem + } + writeText(text: string): Promise { return this._vsClipboardService.writeText(text); } diff --git a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts index fd0fd3624ffa..f7e44b8d06f3 100644 --- a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts +++ b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts @@ -2,13 +2,15 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ - import * as nls from 'vs/nls'; import { Action } from 'vs/base/common/actions'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +//import { DataService } from 'sql/workbench/services/query/common/dataService'; +//import QueryRunner from 'sql/workbench/services/query/common/queryRunner'; import * as azdata from 'azdata'; +//import { EOL } from 'os'; import { IQueryManagementService } from 'sql/workbench/services/query/common/queryManagement'; import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; @@ -21,6 +23,7 @@ import { EditDataEditor } from 'sql/workbench/contrib/editData/browser/editDataE import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { QueryEditorInput } from 'sql/workbench/common/editor/query/queryEditorInput'; +import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; const singleQuote = '\''; @@ -131,6 +134,97 @@ export class RunCurrentQueryKeyboardAction extends Action { } } +export class CopyCurrentQueryWithResultsKeyboardAction extends Action { + public static ID = 'copyCurrentQueryWithResultsKeyboardAction'; + public static LABEL = nls.localize('copyCurrentQueryWithResultsKeyboardAction', "Copy Query With Results"); + + constructor( + id: string, + label: string, + //private dataService: DataService, + //private _queryRunner: QueryRunner, + @IEditorService private _editorService: IEditorService, + @IClipboardService private _clipboardService: IClipboardService, + @IQueryModelService protected readonly queryModelService: IQueryModelService, + ) { + super(id, label); + this.enabled = true; + } + + public async run(): Promise { + const editor = this._editorService.activeEditorPane; + if (editor instanceof QueryEditor) { + //this._clipboardService.writeText(editor.getSelectionText()); + let queryrunner = this.queryModelService.getQueryRunner(editor.input.uri); + let allResults = ''; + + for (let i = 0; i < queryrunner.batchSets[0].resultSetSummaries.length; i++) { + let resultSummary = queryrunner.batchSets[0].resultSetSummaries[i]; + let result = await this.queryModelService.getQueryRunner(editor.input.uri).getQueryRows(0, resultSummary.rowCount, resultSummary.batchId, resultSummary.id); + let rows: Map> = new Map(); // Maps row index -> column index -> actual row value + + // Iterate over the rows to paste into the copy string + for (let rowIndex: number = 0; rowIndex < result.rows.length; rowIndex++) { + let row = result.rows[rowIndex]; + // Remove newlines if requested + let cells = row.map(x => x.displayValue); + + let idx = 0; + for (let cell of cells) { + let map = rows.get(rowIndex); + if (!map) { + map = new Map(); + rows.set(rowIndex, map); + } + + map.set(idx, cell); + idx++; + } + } + //this._queryRunner.getQueryRows(0, 10, 0, 0); + //editor.input.results.state.toString() + //let c = editor.input.results.state.gridPanelState.tableStates[0]; + let copyString = ''; + for (let rowEntry of rows) { + let rowMap = rowEntry[1]; + for (let rowIdx = 0; rowIdx < rowMap.size; rowIdx++) { + + let value = rowMap.get(rowIdx); + if (value) { + copyString = copyString.concat(value); + } + copyString = copyString.concat('\t'); + } + // Removes the tab seperator from the end of a row + copyString = copyString.slice(0, -1 * '\t'.length); + } + + allResults = allResults + copyString + '\n\n\n'; + } + + /*let tablesHtml = ''; + tableResults.forEach((tableResult, i) => { + // isChart is null for tables / false for tables that are dataset for charts + if (tableResult.isChart !== true) { + const tableHtml = generateTableHtml(tableResult, i); + tablesHtml += tableHtml; + } + });*/ + + this._clipboardService.writeText(editor.getAllText() + '\n' + allResults); + + let data = { + text: editor.getAllText() + '\n\n' + allResults, + html: '"


Table0
StartTimeEndTimeEpisodeIdEventIdStateEventTypeInjuriesDirectInjuriesIndirectDeathsDirectDeathsIndirectDamagePropertyDamageCropsSourceBeginLocationEndLocationBeginLatBeginLonEndLatEndLonEpisodeNarrativeEventNarrativeStormSummary
2007-09-29T08:11:00Z2007-09-29T08:11:00Z1109161032ATLANTIC SOUTHWaterspout000000Trained SpotterMELBOURNE BEACHMELBOURNE BEACH28.0393-80.604828.0393-80.6048Showers and thunderstorms lingering along the coast produced waterspouts in Brevard County.A waterspout formed in the Atlantic southeast of Melbourne Beach and briefly moved toward shore.{"TotalDamages":0,"StartTime":"2007-09-29T08:11:00.0000000Z","EndTime":"2007-09-29T08:11:00.0000000Z","Details":{"Description":"A waterspout formed in the Atlantic southeast of Melbourne Beach and briefly moved toward shore.","Location":"ATLANTIC SOUTH"}}
"' + }; + //`${}` + this._clipboardService.write(data); + //editor.runCurrentQuery(); + } + return Promise.resolve(null); + } +} + export class RunCurrentQueryWithActualPlanKeyboardAction extends Action { public static ID = 'runCurrentQueryWithActualPlanKeyboardAction'; public static LABEL = nls.localize('runCurrentQueryWithActualPlanKeyboardAction', "Run Current Query with Actual Plan"); diff --git a/src/sql/workbench/contrib/query/browser/query.contribution.ts b/src/sql/workbench/contrib/query/browser/query.contribution.ts index 39e06a419cad..647c3c74c38a 100644 --- a/src/sql/workbench/contrib/query/browser/query.contribution.ts +++ b/src/sql/workbench/contrib/query/browser/query.contribution.ts @@ -19,7 +19,7 @@ import { QueryResultsInput } from 'sql/workbench/common/editor/query/queryResult import * as queryContext from 'sql/workbench/contrib/query/common/queryContext'; import { RunQueryKeyboardAction, RunCurrentQueryKeyboardAction, CancelQueryKeyboardAction, RefreshIntellisenseKeyboardAction, ToggleQueryResultsKeyboardAction, - RunQueryShortcutAction, RunCurrentQueryWithActualPlanKeyboardAction, FocusOnCurrentQueryKeyboardAction, ParseSyntaxAction + RunQueryShortcutAction, RunCurrentQueryWithActualPlanKeyboardAction, CopyCurrentQueryWithResultsKeyboardAction, FocusOnCurrentQueryKeyboardAction, ParseSyntaxAction } from 'sql/workbench/contrib/query/browser/keyboardQueryActions'; import * as gridActions from 'sql/workbench/contrib/editData/browser/gridActions'; import * as gridCommands from 'sql/workbench/contrib/editData/browser/gridCommands'; @@ -139,6 +139,16 @@ actionRegistry.registerWorkbenchAction( RunCurrentQueryWithActualPlanKeyboardAction.LABEL ); +actionRegistry.registerWorkbenchAction( + SyncActionDescriptor.create( + CopyCurrentQueryWithResultsKeyboardAction, + CopyCurrentQueryWithResultsKeyboardAction.ID, + CopyCurrentQueryWithResultsKeyboardAction.LABEL, + { primary: KeyMod.CtrlCmd | KeyCode.KEY_M } + ), + CopyCurrentQueryWithResultsKeyboardAction.LABEL +); + actionRegistry.registerWorkbenchAction( SyncActionDescriptor.create( CancelQueryKeyboardAction, diff --git a/src/sql/workbench/services/query/common/gridDataProvider.ts b/src/sql/workbench/services/query/common/gridDataProvider.ts index 8984e48a2388..51532b3ae49c 100644 --- a/src/sql/workbench/services/query/common/gridDataProvider.ts +++ b/src/sql/workbench/services/query/common/gridDataProvider.ts @@ -49,7 +49,7 @@ export async function getResultsString(provider: IGridDataProvider, selection: S // create a mapping of the ranges to get promises let tasks: (() => Promise)[] = selection.map((range) => { - return async (): Promise => { + let a = async (): Promise => { let startCol = range.fromCell; let startRow = range.fromRow; @@ -86,6 +86,7 @@ export async function getResultsString(provider: IGridDataProvider, selection: S } } }; + return a; }); // Set the tasks gathered above to execute diff --git a/src/vs/platform/clipboard/browser/clipboardService.ts b/src/vs/platform/clipboard/browser/clipboardService.ts index 11b3e009a349..de143edfe66e 100644 --- a/src/vs/platform/clipboard/browser/clipboardService.ts +++ b/src/vs/platform/clipboard/browser/clipboardService.ts @@ -13,6 +13,10 @@ export class BrowserClipboardService implements IClipboardService { private readonly mapTextToType = new Map(); // unsupported in web (only in-memory) + async write(data: any, type?: string): Promise { + throw new Error('Not Implemented'); + } // throw not implemented + async writeText(text: string, type?: string): Promise { // With type: only in-memory is supported diff --git a/src/vs/platform/clipboard/common/clipboardService.ts b/src/vs/platform/clipboard/common/clipboardService.ts index eb3b4bffce14..22ebcdc9fafe 100644 --- a/src/vs/platform/clipboard/common/clipboardService.ts +++ b/src/vs/platform/clipboard/common/clipboardService.ts @@ -11,6 +11,10 @@ export const IClipboardService = createDecorator('clipboardSe export interface IClipboardService { readonly _serviceBrand: undefined; + /** + * Writes data to the system clipboard. + */ + write(data: any, type?: string): Promise; /** * Writes text to the system clipboard. diff --git a/src/vs/platform/electron/common/electron.ts b/src/vs/platform/electron/common/electron.ts index cfb5637f6614..9b0b9d048d35 100644 --- a/src/vs/platform/electron/common/electron.ts +++ b/src/vs/platform/electron/common/electron.ts @@ -93,6 +93,7 @@ export interface ICommonElectronService { writeClipboardText(text: string, type?: 'selection' | 'clipboard'): Promise; readClipboardFindText(): Promise; writeClipboardFindText(text: string): Promise; + writeClipboardData(data: any, type?: 'selection' | 'clipboard'): Promise; writeClipboardBuffer(format: string, buffer: Uint8Array, type?: 'selection' | 'clipboard'): Promise; readClipboardBuffer(format: string): Promise; hasClipboard(format: string, type?: 'selection' | 'clipboard'): Promise; diff --git a/src/vs/platform/electron/electron-main/electronMainService.ts b/src/vs/platform/electron/electron-main/electronMainService.ts index 354eaf5cb3b4..436602096a24 100644 --- a/src/vs/platform/electron/electron-main/electronMainService.ts +++ b/src/vs/platform/electron/electron-main/electronMainService.ts @@ -369,6 +369,10 @@ export class ElectronMainService implements IElectronMainService { return clipboard.writeText(text, type); } + async writeClipboardData(windowId: number | undefined, data: any, type?: 'selection' | 'clipboard'): Promise { + return clipboard.write(data, type); + } + async readClipboardFindText(windowId: number | undefined,): Promise { return clipboard.readFindText(); } diff --git a/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts b/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts index a54d546045df..9e8b1ebc2dab 100644 --- a/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts +++ b/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts @@ -20,6 +20,10 @@ export class NativeClipboardService implements IClipboardService { @IElectronService private readonly electronService: IElectronService ) { } + async write(data: any, type?: 'selection' | 'clipboard'): Promise { + return this.electronService.writeClipboardData(data, type); + } + async writeText(text: string, type?: 'selection' | 'clipboard'): Promise { return this.electronService.writeClipboardText(text, type); } diff --git a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts index 0f0459bd0631..aa55a92ea068 100644 --- a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts @@ -222,6 +222,7 @@ export class TestElectronService implements IElectronService { async toggleDevTools(): Promise { } async resolveProxy(url: string): Promise { return undefined; } async readClipboardText(type?: 'selection' | 'clipboard' | undefined): Promise { return ''; } + async writeClipboardData(data: any, type?: 'selection' | 'clipboard' | undefined): Promise { } async writeClipboardText(text: string, type?: 'selection' | 'clipboard' | undefined): Promise { } async readClipboardFindText(): Promise { return ''; } async writeClipboardFindText(text: string): Promise { } From bf69c1b881331ac1a37d100a5e8e2847beb60d03 Mon Sep 17 00:00:00 2001 From: Monica Gupta Date: Tue, 3 Nov 2020 11:44:38 -0800 Subject: [PATCH 2/8] few changes --- .../contrib/query/browser/keyboardQueryActions.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts index f7e44b8d06f3..0189b249975f 100644 --- a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts +++ b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts @@ -196,10 +196,10 @@ export class CopyCurrentQueryWithResultsKeyboardAction extends Action { copyString = copyString.concat('\t'); } // Removes the tab seperator from the end of a row - copyString = copyString.slice(0, -1 * '\t'.length); + copyString = copyString.slice(0, -1 * '\t'.length) + '\n'; } - allResults = allResults + copyString + '\n\n\n'; + allResults = allResults + copyString + '\n\n'; } /*let tablesHtml = ''; @@ -211,10 +211,10 @@ export class CopyCurrentQueryWithResultsKeyboardAction extends Action { } });*/ - this._clipboardService.writeText(editor.getAllText() + '\n' + allResults); + //this._clipboardService.writeText(editor.getAllText() + EOL + allResults); let data = { - text: editor.getAllText() + '\n\n' + allResults, + text: `${editor.getSelectionText() ? editor.getSelectionText() : editor.getAllText()} \n\n ${allResults}`, html: '"


Table0
StartTimeEndTimeEpisodeIdEventIdStateEventTypeInjuriesDirectInjuriesIndirectDeathsDirectDeathsIndirectDamagePropertyDamageCropsSourceBeginLocationEndLocationBeginLatBeginLonEndLatEndLonEpisodeNarrativeEventNarrativeStormSummary
2007-09-29T08:11:00Z2007-09-29T08:11:00Z1109161032ATLANTIC SOUTHWaterspout000000Trained SpotterMELBOURNE BEACHMELBOURNE BEACH28.0393-80.604828.0393-80.6048Showers and thunderstorms lingering along the coast produced waterspouts in Brevard County.A waterspout formed in the Atlantic southeast of Melbourne Beach and briefly moved toward shore.{"TotalDamages":0,"StartTime":"2007-09-29T08:11:00.0000000Z","EndTime":"2007-09-29T08:11:00.0000000Z","Details":{"Description":"A waterspout formed in the Atlantic southeast of Melbourne Beach and briefly moved toward shore.","Location":"ATLANTIC SOUTH"}}
"' }; //`${}` From e605508d318a783153fa4618640100ba78e3a322 Mon Sep 17 00:00:00 2001 From: Monica Gupta Date: Mon, 23 Nov 2020 16:57:20 -0800 Subject: [PATCH 3/8] Changes to copy query with results in plain and html formatting --- .../query/browser/keyboardQueryActions.ts | 101 +++++++----------- .../query/browser/query.contribution.ts | 10 +- 2 files changed, 44 insertions(+), 67 deletions(-) diff --git a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts index 0189b249975f..0676544e01c8 100644 --- a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts +++ b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts @@ -6,11 +6,9 @@ import * as nls from 'vs/nls'; import { Action } from 'vs/base/common/actions'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -//import { DataService } from 'sql/workbench/services/query/common/dataService'; -//import QueryRunner from 'sql/workbench/services/query/common/queryRunner'; import * as azdata from 'azdata'; -//import { EOL } from 'os'; +import { escape } from 'sql/base/common/strings'; import { IQueryManagementService } from 'sql/workbench/services/query/common/queryManagement'; import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; @@ -134,15 +132,13 @@ export class RunCurrentQueryKeyboardAction extends Action { } } -export class CopyCurrentQueryWithResultsKeyboardAction extends Action { - public static ID = 'copyCurrentQueryWithResultsKeyboardAction'; - public static LABEL = nls.localize('copyCurrentQueryWithResultsKeyboardAction', "Copy Query With Results"); +export class CopyQueryWithResultsKeyboardAction extends Action { + public static ID = 'copyQueryWithResultsKeyboardAction'; + public static LABEL = nls.localize('copyQueryWithResultsKeyboardAction', "Copy Query With Results"); constructor( id: string, label: string, - //private dataService: DataService, - //private _queryRunner: QueryRunner, @IEditorService private _editorService: IEditorService, @IClipboardService private _clipboardService: IClipboardService, @IQueryModelService protected readonly queryModelService: IQueryModelService, @@ -151,75 +147,56 @@ export class CopyCurrentQueryWithResultsKeyboardAction extends Action { this.enabled = true; } - public async run(): Promise { - const editor = this._editorService.activeEditorPane; - if (editor instanceof QueryEditor) { - //this._clipboardService.writeText(editor.getSelectionText()); - let queryrunner = this.queryModelService.getQueryRunner(editor.input.uri); - let allResults = ''; - - for (let i = 0; i < queryrunner.batchSets[0].resultSetSummaries.length; i++) { - let resultSummary = queryrunner.batchSets[0].resultSetSummaries[i]; - let result = await this.queryModelService.getQueryRunner(editor.input.uri).getQueryRows(0, resultSummary.rowCount, resultSummary.batchId, resultSummary.id); - let rows: Map> = new Map(); // Maps row index -> column index -> actual row value - - // Iterate over the rows to paste into the copy string - for (let rowIndex: number = 0; rowIndex < result.rows.length; rowIndex++) { - let row = result.rows[rowIndex]; - // Remove newlines if requested - let cells = row.map(x => x.displayValue); - - let idx = 0; - for (let cell of cells) { - let map = rows.get(rowIndex); - if (!map) { - map = new Map(); - rows.set(rowIndex, map); - } + public async getFormattedResults(editor): Promise { + let queryRunner = this.queryModelService.getQueryRunner(editor.input.uri); + let allResults = ''; + let allHtmlResults = ''; - map.set(idx, cell); - idx++; - } - } - //this._queryRunner.getQueryRows(0, 10, 0, 0); - //editor.input.results.state.toString() - //let c = editor.input.results.state.gridPanelState.tableStates[0]; - let copyString = ''; - for (let rowEntry of rows) { - let rowMap = rowEntry[1]; - for (let rowIdx = 0; rowIdx < rowMap.size; rowIdx++) { - - let value = rowMap.get(rowIdx); + if (queryRunner && queryRunner.batchSets.length > 0) { + for (let i = 0; i < queryRunner.batchSets[0].resultSetSummaries.length; i++) { + let resultSummary = queryRunner.batchSets[0].resultSetSummaries[i]; + let result = await queryRunner.getQueryRows(0, resultSummary.rowCount, resultSummary.batchId, resultSummary.id); + let tableHeaders = resultSummary.columnInfo.map((col, i) => (col.columnName)); + let htmlTableHeaders = resultSummary.columnInfo.map((col, i) => (`${escape(col.columnName)}`)); + let copyString = '\n'; + let htmlCopyString = ''; + + for (let rowEntry of result.rows) { + for (let colIdx = 0; colIdx < rowEntry.length; colIdx++) { + let value = rowEntry[colIdx].displayValue; if (value) { - copyString = copyString.concat(value); + copyString = `${copyString}${value}\t`; + htmlCopyString = `${htmlCopyString}${escape(value)}`; } - copyString = copyString.concat('\t'); } // Removes the tab seperator from the end of a row copyString = copyString.slice(0, -1 * '\t'.length) + '\n'; + htmlCopyString = htmlCopyString + ''; } - allResults = allResults + copyString + '\n\n'; + allResults = `${allResults}${tableHeaders.join('\t')}${copyString}\n`; + allHtmlResults = `${allHtmlResults}


+ + ${htmlTableHeaders.join('')}${htmlCopyString} +
`; } + } - /*let tablesHtml = ''; - tableResults.forEach((tableResult, i) => { - // isChart is null for tables / false for tables that are dataset for charts - if (tableResult.isChart !== true) { - const tableHtml = generateTableHtml(tableResult, i); - tablesHtml += tableHtml; - } - });*/ + return { result: allResults, html: allHtmlResults }; + } - //this._clipboardService.writeText(editor.getAllText() + EOL + allResults); + public async run(): Promise { + const editor = this._editorService.activeEditorPane; + if (editor instanceof QueryEditor) { + let allResults = await this.getFormattedResults(editor); + let queryText = editor.getAllText(); let data = { - text: `${editor.getSelectionText() ? editor.getSelectionText() : editor.getAllText()} \n\n ${allResults}`, - html: '"


Table0
StartTimeEndTimeEpisodeIdEventIdStateEventTypeInjuriesDirectInjuriesIndirectDeathsDirectDeathsIndirectDamagePropertyDamageCropsSourceBeginLocationEndLocationBeginLatBeginLonEndLatEndLonEpisodeNarrativeEventNarrativeStormSummary
2007-09-29T08:11:00Z2007-09-29T08:11:00Z1109161032ATLANTIC SOUTHWaterspout000000Trained SpotterMELBOURNE BEACHMELBOURNE BEACH28.0393-80.604828.0393-80.6048Showers and thunderstorms lingering along the coast produced waterspouts in Brevard County.A waterspout formed in the Atlantic southeast of Melbourne Beach and briefly moved toward shore.{"TotalDamages":0,"StartTime":"2007-09-29T08:11:00.0000000Z","EndTime":"2007-09-29T08:11:00.0000000Z","Details":{"Description":"A waterspout formed in the Atlantic southeast of Melbourne Beach and briefly moved toward shore.","Location":"ATLANTIC SOUTH"}}
"' + text: `${queryText}\n\n${allResults.result}`, + html: `${escape(queryText).replace(/\r\n|\n|\r/gm, '
')}${allResults.html}` }; - //`${}` + this._clipboardService.write(data); - //editor.runCurrentQuery(); } return Promise.resolve(null); } diff --git a/src/sql/workbench/contrib/query/browser/query.contribution.ts b/src/sql/workbench/contrib/query/browser/query.contribution.ts index 647c3c74c38a..e9191192476f 100644 --- a/src/sql/workbench/contrib/query/browser/query.contribution.ts +++ b/src/sql/workbench/contrib/query/browser/query.contribution.ts @@ -19,7 +19,7 @@ import { QueryResultsInput } from 'sql/workbench/common/editor/query/queryResult import * as queryContext from 'sql/workbench/contrib/query/common/queryContext'; import { RunQueryKeyboardAction, RunCurrentQueryKeyboardAction, CancelQueryKeyboardAction, RefreshIntellisenseKeyboardAction, ToggleQueryResultsKeyboardAction, - RunQueryShortcutAction, RunCurrentQueryWithActualPlanKeyboardAction, CopyCurrentQueryWithResultsKeyboardAction, FocusOnCurrentQueryKeyboardAction, ParseSyntaxAction + RunQueryShortcutAction, RunCurrentQueryWithActualPlanKeyboardAction, CopyQueryWithResultsKeyboardAction, FocusOnCurrentQueryKeyboardAction, ParseSyntaxAction } from 'sql/workbench/contrib/query/browser/keyboardQueryActions'; import * as gridActions from 'sql/workbench/contrib/editData/browser/gridActions'; import * as gridCommands from 'sql/workbench/contrib/editData/browser/gridCommands'; @@ -141,12 +141,12 @@ actionRegistry.registerWorkbenchAction( actionRegistry.registerWorkbenchAction( SyncActionDescriptor.create( - CopyCurrentQueryWithResultsKeyboardAction, - CopyCurrentQueryWithResultsKeyboardAction.ID, - CopyCurrentQueryWithResultsKeyboardAction.LABEL, + CopyQueryWithResultsKeyboardAction, + CopyQueryWithResultsKeyboardAction.ID, + CopyQueryWithResultsKeyboardAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_M } ), - CopyCurrentQueryWithResultsKeyboardAction.LABEL + CopyQueryWithResultsKeyboardAction.LABEL ); actionRegistry.registerWorkbenchAction( From 7be8c7078cd5a5326aeb3c06df45b24269be7d0a Mon Sep 17 00:00:00 2001 From: Monica Gupta Date: Mon, 23 Nov 2020 17:21:02 -0800 Subject: [PATCH 4/8] undo changes --- src/sql/workbench/services/query/common/gridDataProvider.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sql/workbench/services/query/common/gridDataProvider.ts b/src/sql/workbench/services/query/common/gridDataProvider.ts index 51532b3ae49c..8984e48a2388 100644 --- a/src/sql/workbench/services/query/common/gridDataProvider.ts +++ b/src/sql/workbench/services/query/common/gridDataProvider.ts @@ -49,7 +49,7 @@ export async function getResultsString(provider: IGridDataProvider, selection: S // create a mapping of the ranges to get promises let tasks: (() => Promise)[] = selection.map((range) => { - let a = async (): Promise => { + return async (): Promise => { let startCol = range.fromCell; let startRow = range.fromRow; @@ -86,7 +86,6 @@ export async function getResultsString(provider: IGridDataProvider, selection: S } } }; - return a; }); // Set the tasks gathered above to execute From bb176a1a7277c6d32eea41e33b5db15c8b86e153 Mon Sep 17 00:00:00 2001 From: Monica Gupta Date: Mon, 23 Nov 2020 17:22:34 -0800 Subject: [PATCH 5/8] undo unintended change --- src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts index 0676544e01c8..609725a07bcd 100644 --- a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts +++ b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts @@ -2,6 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ + import * as nls from 'vs/nls'; import { Action } from 'vs/base/common/actions'; From 7ef2528445287722caaafb0d7af076296f0515e8 Mon Sep 17 00:00:00 2001 From: Monica Gupta Date: Mon, 23 Nov 2020 17:25:23 -0800 Subject: [PATCH 6/8] remove comments --- src/sql/platform/clipboard/browser/clipboardService.ts | 2 +- src/vs/platform/clipboard/browser/clipboardService.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sql/platform/clipboard/browser/clipboardService.ts b/src/sql/platform/clipboard/browser/clipboardService.ts index 09673acd377c..4d47484abf26 100644 --- a/src/sql/platform/clipboard/browser/clipboardService.ts +++ b/src/sql/platform/clipboard/browser/clipboardService.ts @@ -26,7 +26,7 @@ export class BrowserClipboardService implements IClipboardService { } write(data: string): Promise { - return this._vsClipboardService.writeText(data); // throw not implem + return this._vsClipboardService.writeText(data); } writeText(text: string): Promise { diff --git a/src/vs/platform/clipboard/browser/clipboardService.ts b/src/vs/platform/clipboard/browser/clipboardService.ts index de143edfe66e..7b5e330fbfc5 100644 --- a/src/vs/platform/clipboard/browser/clipboardService.ts +++ b/src/vs/platform/clipboard/browser/clipboardService.ts @@ -15,7 +15,7 @@ export class BrowserClipboardService implements IClipboardService { async write(data: any, type?: string): Promise { throw new Error('Not Implemented'); - } // throw not implemented + } async writeText(text: string, type?: string): Promise { From 554055743533e9832f34276b7f6e41c50284b4dd Mon Sep 17 00:00:00 2001 From: Monica Gupta Date: Tue, 24 Nov 2020 15:16:16 -0800 Subject: [PATCH 7/8] Addressed comments --- .../platform/clipboard/browser/clipboardService.ts | 6 +++--- .../contrib/query/browser/keyboardQueryActions.ts | 8 +++----- .../contrib/query/browser/query.contribution.ts | 2 +- src/vs/platform/clipboard/browser/clipboardService.ts | 6 ++++-- src/vs/platform/clipboard/common/clipboardService.ts | 11 ++++++++++- .../clipboard/electron-sandbox/clipboardService.ts | 6 ++++-- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/sql/platform/clipboard/browser/clipboardService.ts b/src/sql/platform/clipboard/browser/clipboardService.ts index 4d47484abf26..a615f4f6f881 100644 --- a/src/sql/platform/clipboard/browser/clipboardService.ts +++ b/src/sql/platform/clipboard/browser/clipboardService.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { IClipboardService } from 'sql/platform/clipboard/common/clipboardService'; -import { IClipboardService as vsIClipboardService } from 'vs/platform/clipboard/common/clipboardService'; +import { ClipboardData, IClipboardService as vsIClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { URI } from 'vs/base/common/uri'; import { localize } from 'vs/nls'; @@ -25,8 +25,8 @@ export class BrowserClipboardService implements IClipboardService { this._notificationService.info(localize('imageCopyingNotSupported', "Copying images is not supported")); } - write(data: string): Promise { - return this._vsClipboardService.writeText(data); + write(data: ClipboardData): Promise { + return this._vsClipboardService.write(data); } writeText(text: string): Promise { diff --git a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts index 609725a07bcd..f23057dc6956 100644 --- a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts +++ b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts @@ -145,7 +145,6 @@ export class CopyQueryWithResultsKeyboardAction extends Action { @IQueryModelService protected readonly queryModelService: IQueryModelService, ) { super(id, label); - this.enabled = true; } public async getFormattedResults(editor): Promise { @@ -183,7 +182,7 @@ export class CopyQueryWithResultsKeyboardAction extends Action { } } - return { result: allResults, html: allHtmlResults }; + return { result: allResults, htmlResult: allHtmlResults }; } public async run(): Promise { @@ -194,12 +193,11 @@ export class CopyQueryWithResultsKeyboardAction extends Action { let data = { text: `${queryText}\n\n${allResults.result}`, - html: `${escape(queryText).replace(/\r\n|\n|\r/gm, '
')}${allResults.html}` + html: `${escape(queryText).replace(/\r\n|\n|\r/gm, '
')}${allResults.htmlResult}` }; - this._clipboardService.write(data); + await this._clipboardService.write(data); } - return Promise.resolve(null); } } diff --git a/src/sql/workbench/contrib/query/browser/query.contribution.ts b/src/sql/workbench/contrib/query/browser/query.contribution.ts index e9191192476f..dd292880d1f1 100644 --- a/src/sql/workbench/contrib/query/browser/query.contribution.ts +++ b/src/sql/workbench/contrib/query/browser/query.contribution.ts @@ -144,7 +144,7 @@ actionRegistry.registerWorkbenchAction( CopyQueryWithResultsKeyboardAction, CopyQueryWithResultsKeyboardAction.ID, CopyQueryWithResultsKeyboardAction.LABEL, - { primary: KeyMod.CtrlCmd | KeyCode.KEY_M } + { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_C } ), CopyQueryWithResultsKeyboardAction.LABEL ); diff --git a/src/vs/platform/clipboard/browser/clipboardService.ts b/src/vs/platform/clipboard/browser/clipboardService.ts index 7b5e330fbfc5..58d3873630e1 100644 --- a/src/vs/platform/clipboard/browser/clipboardService.ts +++ b/src/vs/platform/clipboard/browser/clipboardService.ts @@ -3,7 +3,8 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; +// {{SQL CARBON EDIT}} +import { ClipboardData, IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { URI } from 'vs/base/common/uri'; import { $ } from 'vs/base/browser/dom'; @@ -13,7 +14,8 @@ export class BrowserClipboardService implements IClipboardService { private readonly mapTextToType = new Map(); // unsupported in web (only in-memory) - async write(data: any, type?: string): Promise { + // {{SQL CARBON EDIT}} + async write(data: ClipboardData, type?: string): Promise { throw new Error('Not Implemented'); } diff --git a/src/vs/platform/clipboard/common/clipboardService.ts b/src/vs/platform/clipboard/common/clipboardService.ts index 22ebcdc9fafe..d6815681a657 100644 --- a/src/vs/platform/clipboard/common/clipboardService.ts +++ b/src/vs/platform/clipboard/common/clipboardService.ts @@ -8,13 +8,22 @@ import { URI } from 'vs/base/common/uri'; export const IClipboardService = createDecorator('clipboardService'); +// {{SQL CARBON EDIT}} +export interface ClipboardData { + text?: string; + html?: string; + rtf?: string; + bookmark?: string; +} + export interface IClipboardService { readonly _serviceBrand: undefined; /** * Writes data to the system clipboard. */ - write(data: any, type?: string): Promise; + // {{SQL CARBON EDIT}} + write(data: ClipboardData, type?: string): Promise; /** * Writes text to the system clipboard. diff --git a/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts b/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts index 9e8b1ebc2dab..c574ef68c49c 100644 --- a/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts +++ b/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts @@ -3,7 +3,8 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; +// {{SQL CARBON EDIT}} +import { ClipboardData, IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { URI } from 'vs/base/common/uri'; import { isMacintosh } from 'vs/base/common/platform'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; @@ -20,7 +21,8 @@ export class NativeClipboardService implements IClipboardService { @IElectronService private readonly electronService: IElectronService ) { } - async write(data: any, type?: 'selection' | 'clipboard'): Promise { + // {{SQL CARBON EDIT}} + async write(data: ClipboardData, type?: 'selection' | 'clipboard'): Promise { return this.electronService.writeClipboardData(data, type); } From feb51a8ece8b5ab8c458ef3af0274afd59a7aa1c Mon Sep 17 00:00:00 2001 From: Monica Gupta Date: Wed, 25 Nov 2020 17:56:47 -0800 Subject: [PATCH 8/8] Some clean up --- .../contrib/query/browser/keyboardQueryActions.ts | 10 +++++----- src/vs/platform/clipboard/browser/clipboardService.ts | 3 +-- src/vs/platform/clipboard/common/clipboardService.ts | 7 +++---- src/vs/platform/electron/common/electron.ts | 2 +- .../electron/electron-main/electronMainService.ts | 1 + .../clipboard/electron-sandbox/clipboardService.ts | 3 +-- .../test/electron-browser/workbenchTestServices.ts | 2 +- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts index f23057dc6956..f448dddf5690 100644 --- a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts +++ b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts @@ -22,7 +22,7 @@ import { EditDataEditor } from 'sql/workbench/contrib/editData/browser/editDataE import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { QueryEditorInput } from 'sql/workbench/common/editor/query/queryEditorInput'; -import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; +import { ClipboardData, IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; const singleQuote = '\''; @@ -147,7 +147,7 @@ export class CopyQueryWithResultsKeyboardAction extends Action { super(id, label); } - public async getFormattedResults(editor): Promise { + public async getFormattedResults(editor): Promise { let queryRunner = this.queryModelService.getQueryRunner(editor.input.uri); let allResults = ''; let allHtmlResults = ''; @@ -182,7 +182,7 @@ export class CopyQueryWithResultsKeyboardAction extends Action { } } - return { result: allResults, htmlResult: allHtmlResults }; + return { text: allResults, html: allHtmlResults }; } public async run(): Promise { @@ -192,8 +192,8 @@ export class CopyQueryWithResultsKeyboardAction extends Action { let queryText = editor.getAllText(); let data = { - text: `${queryText}\n\n${allResults.result}`, - html: `${escape(queryText).replace(/\r\n|\n|\r/gm, '
')}${allResults.htmlResult}` + text: `${queryText}\n\n${allResults.text}`, + html: `${escape(queryText).replace(/\r\n|\n|\r/gm, '
')}${allResults.html}` }; await this._clipboardService.write(data); diff --git a/src/vs/platform/clipboard/browser/clipboardService.ts b/src/vs/platform/clipboard/browser/clipboardService.ts index 58d3873630e1..792f0545930a 100644 --- a/src/vs/platform/clipboard/browser/clipboardService.ts +++ b/src/vs/platform/clipboard/browser/clipboardService.ts @@ -3,8 +3,7 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -// {{SQL CARBON EDIT}} -import { ClipboardData, IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; +import { ClipboardData, IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; // {{SQL CARBON EDIT}} import { URI } from 'vs/base/common/uri'; import { $ } from 'vs/base/browser/dom'; diff --git a/src/vs/platform/clipboard/common/clipboardService.ts b/src/vs/platform/clipboard/common/clipboardService.ts index d6815681a657..413b76af4242 100644 --- a/src/vs/platform/clipboard/common/clipboardService.ts +++ b/src/vs/platform/clipboard/common/clipboardService.ts @@ -8,8 +8,8 @@ import { URI } from 'vs/base/common/uri'; export const IClipboardService = createDecorator('clipboardService'); -// {{SQL CARBON EDIT}} -export interface ClipboardData { +// Added type https://www.electronjs.org/docs/api/clipboard#clipboardwritedata-type +export interface ClipboardData { // {{SQL CARBON EDIT}} text?: string; html?: string; rtf?: string; @@ -22,8 +22,7 @@ export interface IClipboardService { /** * Writes data to the system clipboard. */ - // {{SQL CARBON EDIT}} - write(data: ClipboardData, type?: string): Promise; + write(data: ClipboardData, type?: string): Promise; // {{SQL CARBON EDIT}} /** * Writes text to the system clipboard. diff --git a/src/vs/platform/electron/common/electron.ts b/src/vs/platform/electron/common/electron.ts index 9b0b9d048d35..90fc5c844557 100644 --- a/src/vs/platform/electron/common/electron.ts +++ b/src/vs/platform/electron/common/electron.ts @@ -93,7 +93,7 @@ export interface ICommonElectronService { writeClipboardText(text: string, type?: 'selection' | 'clipboard'): Promise; readClipboardFindText(): Promise; writeClipboardFindText(text: string): Promise; - writeClipboardData(data: any, type?: 'selection' | 'clipboard'): Promise; + writeClipboardData(data: any, type?: 'selection' | 'clipboard'): Promise; // {{SQL CARBON EDIT}} writeClipboardBuffer(format: string, buffer: Uint8Array, type?: 'selection' | 'clipboard'): Promise; readClipboardBuffer(format: string): Promise; hasClipboard(format: string, type?: 'selection' | 'clipboard'): Promise; diff --git a/src/vs/platform/electron/electron-main/electronMainService.ts b/src/vs/platform/electron/electron-main/electronMainService.ts index 436602096a24..8f1b6f036f48 100644 --- a/src/vs/platform/electron/electron-main/electronMainService.ts +++ b/src/vs/platform/electron/electron-main/electronMainService.ts @@ -369,6 +369,7 @@ export class ElectronMainService implements IElectronMainService { return clipboard.writeText(text, type); } + // {{SQL CARBON EDIT}} async writeClipboardData(windowId: number | undefined, data: any, type?: 'selection' | 'clipboard'): Promise { return clipboard.write(data, type); } diff --git a/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts b/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts index c574ef68c49c..81a478229507 100644 --- a/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts +++ b/src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts @@ -3,8 +3,7 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -// {{SQL CARBON EDIT}} -import { ClipboardData, IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; +import { ClipboardData, IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; // {{SQL CARBON EDIT}} import { URI } from 'vs/base/common/uri'; import { isMacintosh } from 'vs/base/common/platform'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; diff --git a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts index aa55a92ea068..da3472721680 100644 --- a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts @@ -222,7 +222,7 @@ export class TestElectronService implements IElectronService { async toggleDevTools(): Promise { } async resolveProxy(url: string): Promise { return undefined; } async readClipboardText(type?: 'selection' | 'clipboard' | undefined): Promise { return ''; } - async writeClipboardData(data: any, type?: 'selection' | 'clipboard' | undefined): Promise { } + async writeClipboardData(data: any, type?: 'selection' | 'clipboard' | undefined): Promise { } // {{SQL CARBON EDIT}} async writeClipboardText(text: string, type?: 'selection' | 'clipboard' | undefined): Promise { } async readClipboardFindText(): Promise { return ''; } async writeClipboardFindText(text: string): Promise { }