diff --git a/src/sql/workbench/contrib/editData/browser/editDataGridActions.ts b/src/sql/workbench/contrib/editData/browser/editDataGridActions.ts index 3c34bf56d9..f4281e9769 100644 --- a/src/sql/workbench/contrib/editData/browser/editDataGridActions.ts +++ b/src/sql/workbench/contrib/editData/browser/editDataGridActions.ts @@ -8,6 +8,8 @@ import { DataService } from 'sql/workbench/services/query/common/dataService'; import { GridActionProvider } from 'sql/workbench/contrib/editData/browser/gridActions'; import { localize } from 'vs/nls'; import { IAction, Action } from 'vs/base/common/actions'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; export class EditDataGridActionProvider extends GridActionProvider { @@ -15,9 +17,11 @@ export class EditDataGridActionProvider extends GridActionProvider { dataService: DataService, selectAllCallback: (index: number) => void, private _deleteRowCallback: (index: number) => void, - private _revertRowCallback: () => void + private _revertRowCallback: () => void, + @IConfigurationService configurationService: IConfigurationService, + @IInstantiationService instantiationService: IInstantiationService ) { - super(dataService, selectAllCallback); + super(dataService, selectAllCallback, instantiationService, configurationService); } /** * Return actions given a click on an edit data grid diff --git a/src/sql/workbench/contrib/editData/browser/gridActions.ts b/src/sql/workbench/contrib/editData/browser/gridActions.ts index 258052dc10..33f3e6fb1f 100644 --- a/src/sql/workbench/contrib/editData/browser/gridActions.ts +++ b/src/sql/workbench/contrib/editData/browser/gridActions.ts @@ -9,6 +9,8 @@ import { DataService } from 'sql/workbench/services/query/common/dataService'; import { localize } from 'vs/nls'; import { IAction, Action } from 'vs/base/common/actions'; import { SaveFormat } from 'sql/workbench/services/query/common/resultSerializer'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; export const GRID_SAVECSV_ID = 'grid.saveAsCsv'; export const GRID_SAVEJSON_ID = 'grid.saveAsJson'; @@ -30,7 +32,9 @@ export class GridActionProvider { constructor( protected _dataService: DataService, - protected _selectAllCallback: (index: number) => void + protected _selectAllCallback: (index: number) => void, + @IInstantiationService protected _instantiationService: IInstantiationService, + @IConfigurationService protected _configurationService: IConfigurationService, ) { } @@ -40,13 +44,13 @@ export class GridActionProvider { */ public getGridActions(): IAction[] { const actions: IAction[] = []; - actions.push(new SaveResultAction(SaveResultAction.SAVECSV_ID, SaveResultAction.SAVECSV_LABEL, SaveFormat.CSV, this._dataService)); - actions.push(new SaveResultAction(SaveResultAction.SAVEJSON_ID, SaveResultAction.SAVEJSON_LABEL, SaveFormat.JSON, this._dataService)); - actions.push(new SaveResultAction(SaveResultAction.SAVEEXCEL_ID, SaveResultAction.SAVEEXCEL_LABEL, SaveFormat.EXCEL, this._dataService)); - actions.push(new SaveResultAction(SaveResultAction.SAVEXML_ID, SaveResultAction.SAVEXML_LABEL, SaveFormat.XML, this._dataService)); - actions.push(new SelectAllGridAction(SelectAllGridAction.ID, SelectAllGridAction.LABEL, this._selectAllCallback)); - actions.push(new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false, this._dataService)); - actions.push(new CopyResultAction(CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, true, this._dataService)); + actions.push(this._instantiationService.createInstance(SaveResultAction, SaveResultAction.SAVECSV_ID, SaveResultAction.SAVECSV_LABEL, SaveFormat.CSV, this._dataService)); + actions.push(this._instantiationService.createInstance(SaveResultAction, SaveResultAction.SAVEJSON_ID, SaveResultAction.SAVEJSON_LABEL, SaveFormat.JSON, this._dataService)); + actions.push(this._instantiationService.createInstance(SaveResultAction, SaveResultAction.SAVEEXCEL_ID, SaveResultAction.SAVEEXCEL_LABEL, SaveFormat.EXCEL, this._dataService)); + actions.push(this._instantiationService.createInstance(SaveResultAction, SaveResultAction.SAVEXML_ID, SaveResultAction.SAVEXML_LABEL, SaveFormat.XML, this._dataService)); + actions.push(this._instantiationService.createInstance(SelectAllGridAction, SelectAllGridAction.ID, SelectAllGridAction.LABEL, this._selectAllCallback)); + actions.push(this._instantiationService.createInstance(CopyResultAction, CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false, this._dataService)); + actions.push(this._instantiationService.createInstance(CopyResultAction, CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, true, this._dataService)); return actions; } @@ -95,13 +99,15 @@ class CopyResultAction extends Action { id: string, label: string, private copyHeader: boolean, - private dataService: DataService + private dataService: DataService, + @IConfigurationService private configurationService: IConfigurationService ) { super(id, label); } public override async run(gridInfo: IGridInfo): Promise { - this.dataService.copyResults(gridInfo.selection, gridInfo.batchIndex, gridInfo.resultSetNumber, this.copyHeader); + const includeHeader = this.configurationService.getValue('queryEditor.results.copyIncludeHeaders') || this.copyHeader; + this.dataService.copyResults(gridInfo.selection, gridInfo.batchIndex, gridInfo.resultSetNumber, includeHeader); } } diff --git a/src/sql/workbench/contrib/query/browser/actions.ts b/src/sql/workbench/contrib/query/browser/actions.ts index 6949ee5363..1ae1b4365e 100644 --- a/src/sql/workbench/contrib/query/browser/actions.ts +++ b/src/sql/workbench/contrib/query/browser/actions.ts @@ -105,6 +105,7 @@ export class CopyResultAction extends Action { constructor( id: string, label: string, + private configurationService: IConfigurationService, private copyHeader: boolean, private accountForNumberColumn = true ) { @@ -113,7 +114,8 @@ export class CopyResultAction extends Action { public override async run(context: IGridActionContext): Promise { const selection = this.accountForNumberColumn ? mapForNumberColumn(context.selection) : context.selection; - await context.gridDataProvider.copyResults(selection, this.copyHeader, context.table.getData()); + const includeHeader = this.configurationService.getValue('queryEditor.results.copyIncludeHeaders') || this.copyHeader; + await context.gridDataProvider.copyResults(selection, includeHeader, context.table.getData()); } } diff --git a/src/sql/workbench/contrib/query/browser/gridPanel.ts b/src/sql/workbench/contrib/query/browser/gridPanel.ts index e79d7f5957..34b5bb2542 100644 --- a/src/sql/workbench/contrib/query/browser/gridPanel.ts +++ b/src/sql/workbench/contrib/query/browser/gridPanel.ts @@ -388,7 +388,6 @@ export abstract class GridTableBase extends Disposable implements IView { super(); this.options = { ...defaultGridTableOptions, ...options }; - let config = this.configurationService.getValue<{ rowHeight: number }>('resultsGrid'); this.rowHeight = config && config.rowHeight ? config.rowHeight : ROW_HEIGHT; this.state = state; @@ -479,7 +478,7 @@ export abstract class GridTableBase extends Disposable implements IView { this.rowNumberColumn = new RowNumberColumn({ numberOfRows: this.resultSet.rowCount }); let copyHandler = new CopyKeybind(); copyHandler.onCopy(e => { - new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false).run(this.generateContext()); + new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, this.configurationService, false).run(this.generateContext()); }); this.columns.unshift(this.rowNumberColumn.getColumnDefinition()); let tableOptions: Slick.GridOptions = { @@ -815,8 +814,8 @@ export abstract class GridTableBase extends Disposable implements IView { actions.push(new Separator()); } actions.push( - new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false), - new CopyResultAction(CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, true) + new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, this.configurationService, false), + new CopyResultAction(CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, this.configurationService, true) ); if (this.state.canBeMaximized) { @@ -840,16 +839,7 @@ export abstract class GridTableBase extends Disposable implements IView { } private renderGridDataRowsRange(startIndex: number, count: number): void { - // let editor = this.table.getCellEditor(); - // let oldValue = editor ? editor.getValue() : undefined; - // let wasValueChanged = editor ? editor.isValueChanged() : false; this.invalidateRange(startIndex, startIndex + count); - // let activeCell = this._grid.getActiveCell(); - // if (editor && activeCell.row >= startIndex && activeCell.row < startIndex + count) { - // if (oldValue && wasValueChanged) { - // editor.setValue(oldValue); - // } - // } } private invalidateRange(start: number, end: number): void {