mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
respect include header option (#17134)
* respect include header option * use correct option for copying * check for setting when copying * add dependency injection * use instantiation service Co-authored-by: chgagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -8,6 +8,8 @@ import { DataService } from 'sql/workbench/services/query/common/dataService';
|
|||||||
import { GridActionProvider } from 'sql/workbench/contrib/editData/browser/gridActions';
|
import { GridActionProvider } from 'sql/workbench/contrib/editData/browser/gridActions';
|
||||||
import { localize } from 'vs/nls';
|
import { localize } from 'vs/nls';
|
||||||
import { IAction, Action } from 'vs/base/common/actions';
|
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 {
|
export class EditDataGridActionProvider extends GridActionProvider {
|
||||||
|
|
||||||
@@ -15,9 +17,11 @@ export class EditDataGridActionProvider extends GridActionProvider {
|
|||||||
dataService: DataService,
|
dataService: DataService,
|
||||||
selectAllCallback: (index: number) => void,
|
selectAllCallback: (index: number) => void,
|
||||||
private _deleteRowCallback: (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
|
* Return actions given a click on an edit data grid
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import { DataService } from 'sql/workbench/services/query/common/dataService';
|
|||||||
import { localize } from 'vs/nls';
|
import { localize } from 'vs/nls';
|
||||||
import { IAction, Action } from 'vs/base/common/actions';
|
import { IAction, Action } from 'vs/base/common/actions';
|
||||||
import { SaveFormat } from 'sql/workbench/services/query/common/resultSerializer';
|
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_SAVECSV_ID = 'grid.saveAsCsv';
|
||||||
export const GRID_SAVEJSON_ID = 'grid.saveAsJson';
|
export const GRID_SAVEJSON_ID = 'grid.saveAsJson';
|
||||||
@@ -30,7 +32,9 @@ export class GridActionProvider {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected _dataService: DataService,
|
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[] {
|
public getGridActions(): IAction[] {
|
||||||
const actions: IAction[] = [];
|
const actions: IAction[] = [];
|
||||||
actions.push(new SaveResultAction(SaveResultAction.SAVECSV_ID, SaveResultAction.SAVECSV_LABEL, SaveFormat.CSV, this._dataService));
|
actions.push(this._instantiationService.createInstance(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(this._instantiationService.createInstance(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(this._instantiationService.createInstance(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(this._instantiationService.createInstance(SaveResultAction, SaveResultAction.SAVEXML_ID, SaveResultAction.SAVEXML_LABEL, SaveFormat.XML, this._dataService));
|
||||||
actions.push(new SelectAllGridAction(SelectAllGridAction.ID, SelectAllGridAction.LABEL, this._selectAllCallback));
|
actions.push(this._instantiationService.createInstance(SelectAllGridAction, SelectAllGridAction.ID, SelectAllGridAction.LABEL, this._selectAllCallback));
|
||||||
actions.push(new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false, this._dataService));
|
actions.push(this._instantiationService.createInstance(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(CopyResultAction, CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, true, this._dataService));
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
@@ -95,13 +99,15 @@ class CopyResultAction extends Action {
|
|||||||
id: string,
|
id: string,
|
||||||
label: string,
|
label: string,
|
||||||
private copyHeader: boolean,
|
private copyHeader: boolean,
|
||||||
private dataService: DataService
|
private dataService: DataService,
|
||||||
|
@IConfigurationService private configurationService: IConfigurationService
|
||||||
) {
|
) {
|
||||||
super(id, label);
|
super(id, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async run(gridInfo: IGridInfo): Promise<void> {
|
public override async run(gridInfo: IGridInfo): Promise<void> {
|
||||||
this.dataService.copyResults(gridInfo.selection, gridInfo.batchIndex, gridInfo.resultSetNumber, this.copyHeader);
|
const includeHeader = this.configurationService.getValue<boolean>('queryEditor.results.copyIncludeHeaders') || this.copyHeader;
|
||||||
|
this.dataService.copyResults(gridInfo.selection, gridInfo.batchIndex, gridInfo.resultSetNumber, includeHeader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ export class CopyResultAction extends Action {
|
|||||||
constructor(
|
constructor(
|
||||||
id: string,
|
id: string,
|
||||||
label: string,
|
label: string,
|
||||||
|
private configurationService: IConfigurationService,
|
||||||
private copyHeader: boolean,
|
private copyHeader: boolean,
|
||||||
private accountForNumberColumn = true
|
private accountForNumberColumn = true
|
||||||
) {
|
) {
|
||||||
@@ -113,7 +114,8 @@ export class CopyResultAction extends Action {
|
|||||||
|
|
||||||
public override async run(context: IGridActionContext): Promise<void> {
|
public override async run(context: IGridActionContext): Promise<void> {
|
||||||
const selection = this.accountForNumberColumn ? mapForNumberColumn(context.selection) : context.selection;
|
const selection = this.accountForNumberColumn ? mapForNumberColumn(context.selection) : context.selection;
|
||||||
await context.gridDataProvider.copyResults(selection, this.copyHeader, context.table.getData());
|
const includeHeader = this.configurationService.getValue<boolean>('queryEditor.results.copyIncludeHeaders') || this.copyHeader;
|
||||||
|
await context.gridDataProvider.copyResults(selection, includeHeader, context.table.getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -388,7 +388,6 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
this.options = { ...defaultGridTableOptions, ...options };
|
this.options = { ...defaultGridTableOptions, ...options };
|
||||||
|
|
||||||
let config = this.configurationService.getValue<{ rowHeight: number }>('resultsGrid');
|
let config = this.configurationService.getValue<{ rowHeight: number }>('resultsGrid');
|
||||||
this.rowHeight = config && config.rowHeight ? config.rowHeight : ROW_HEIGHT;
|
this.rowHeight = config && config.rowHeight ? config.rowHeight : ROW_HEIGHT;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
@@ -479,7 +478,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
|||||||
this.rowNumberColumn = new RowNumberColumn({ numberOfRows: this.resultSet.rowCount });
|
this.rowNumberColumn = new RowNumberColumn({ numberOfRows: this.resultSet.rowCount });
|
||||||
let copyHandler = new CopyKeybind<T>();
|
let copyHandler = new CopyKeybind<T>();
|
||||||
copyHandler.onCopy(e => {
|
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());
|
this.columns.unshift(this.rowNumberColumn.getColumnDefinition());
|
||||||
let tableOptions: Slick.GridOptions<T> = {
|
let tableOptions: Slick.GridOptions<T> = {
|
||||||
@@ -815,8 +814,8 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
|||||||
actions.push(new Separator());
|
actions.push(new Separator());
|
||||||
}
|
}
|
||||||
actions.push(
|
actions.push(
|
||||||
new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false),
|
new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, this.configurationService, false),
|
||||||
new CopyResultAction(CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, true)
|
new CopyResultAction(CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, this.configurationService, true)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.state.canBeMaximized) {
|
if (this.state.canBeMaximized) {
|
||||||
@@ -840,16 +839,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private renderGridDataRowsRange(startIndex: number, count: number): void {
|
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);
|
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 {
|
private invalidateRange(start: number, end: number): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user