From a906a9c8623bfc3e73648a35dc7bcfce072a4e1d Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Mon, 24 Jun 2019 17:01:19 -0700 Subject: [PATCH] handle copy in all profiler tables (#6134) * handle copy in all profiler tables * use camel casing --- .../profiler/browser/profilerCopyHandler.ts | 26 +++++++++++++++++++ .../parts/profiler/browser/profilerEditor.ts | 22 +++++++++++++++- .../profiler/browser/profilerTableEditor.ts | 17 +++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/sql/workbench/parts/profiler/browser/profilerCopyHandler.ts diff --git a/src/sql/workbench/parts/profiler/browser/profilerCopyHandler.ts b/src/sql/workbench/parts/profiler/browser/profilerCopyHandler.ts new file mode 100644 index 0000000000..fcf325e091 --- /dev/null +++ b/src/sql/workbench/parts/profiler/browser/profilerCopyHandler.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +import * as os from 'os'; +import { IClipboardService } from 'sql/platform/clipboard/common/clipboardService'; + +export function handleCopyRequest(clipboardService: IClipboardService, range: Slick.Range, getCellValue: (row, cell) => string): void { + if (range) { + let results = ''; + for (let i = range.fromRow; i <= range.toRow; i++) { + for (let j = range.fromCell; j <= range.toCell; j++) { + let value = getCellValue(i, j); + if (j !== range.toCell) { + value += '\t'; + } + results += value; + } + + if (i !== range.toRow) { + results += os.EOL; + } + } + clipboardService.writeText(results); + } +} \ No newline at end of file diff --git a/src/sql/workbench/parts/profiler/browser/profilerEditor.ts b/src/sql/workbench/parts/profiler/browser/profilerEditor.ts index 0f86613059..b66b4bb9f1 100644 --- a/src/sql/workbench/parts/profiler/browser/profilerEditor.ts +++ b/src/sql/workbench/parts/profiler/browser/profilerEditor.ts @@ -46,6 +46,10 @@ import { IWorkbenchThemeService, VS_DARK_THEME, VS_HC_THEME } from 'vs/workbench import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { Event, Emitter } from 'vs/base/common/event'; import { clamp } from 'vs/base/common/numbers'; +import { CopyKeybind } from 'sql/base/browser/ui/table/plugins/copyKeybind.plugin'; +import { IClipboardService } from 'sql/platform/clipboard/common/clipboardService'; +import { CellSelectionModel } from 'sql/base/browser/ui/table/plugins/cellSelectionModel.plugin'; +import { handleCopyRequest } from 'sql/workbench/parts/profiler/browser/profilerCopyHandler'; class BasicView implements IView { public get element(): HTMLElement { @@ -156,7 +160,8 @@ export class ProfilerEditor extends BaseEditor { @IContextKeyService private _contextKeyService: IContextKeyService, @IContextViewService private _contextViewService: IContextViewService, @IEditorService editorService: IEditorService, - @IStorageService storageService: IStorageService + @IStorageService storageService: IStorageService, + @IClipboardService private _clipboardService: IClipboardService ) { super(ProfilerEditor.ID, telemetryService, themeService, storageService); this._profilerEditorContextKey = CONTEXT_PROFILER_EDITOR.bindTo(this._contextKeyService); @@ -383,6 +388,21 @@ export class ProfilerEditor extends BaseEditor { this._detailTable.updateRowCount(); }); + const detailTableCopyKeybind = new CopyKeybind(); + detailTableCopyKeybind.onCopy((ranges: Slick.Range[]) => { + // we always only get 1 item in the ranges + if (ranges && ranges.length === 1) { + handleCopyRequest(this._clipboardService, ranges[0], (row, cell) => { + const item = this._detailTableData.getItem(row); + // only 2 columns in this table + return cell === 0 ? item.label : item.value; + }); + } + }); + this._detailTable.setSelectionModel(new CellSelectionModel()); + this._detailTable.registerPlugin(detailTableCopyKeybind); + + this._tabbedPanel.pushTab({ identifier: 'detailTable', title: nls.localize('details', "Details"), diff --git a/src/sql/workbench/parts/profiler/browser/profilerTableEditor.ts b/src/sql/workbench/parts/profiler/browser/profilerTableEditor.ts index 2146077d7f..0885840e21 100644 --- a/src/sql/workbench/parts/profiler/browser/profilerTableEditor.ts +++ b/src/sql/workbench/parts/profiler/browser/profilerTableEditor.ts @@ -29,6 +29,9 @@ import { textFormatter, slickGridDataItemColumnValueExtractor } from 'sql/base/b import { IStorageService } from 'vs/platform/storage/common/storage'; import { IStatusbarService, StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar'; import { localize } from 'vs/nls'; +import { CopyKeybind } from 'sql/base/browser/ui/table/plugins/copyKeybind.plugin'; +import { IClipboardService } from 'sql/platform/clipboard/common/clipboardService'; +import { handleCopyRequest } from 'sql/workbench/parts/profiler/browser/profilerCopyHandler'; export interface ProfilerTableViewState { scrollTop: number; @@ -62,7 +65,8 @@ export class ProfilerTableEditor extends BaseEditor implements IProfilerControll @IContextKeyService private _contextKeyService: IContextKeyService, @IInstantiationService private _instantiationService: IInstantiationService, @IStorageService storageService: IStorageService, - @IStatusbarService private _statusbarService: IStatusbarService + @IStatusbarService private _statusbarService: IStatusbarService, + @IClipboardService private _clipboardService: IClipboardService ) { super(ProfilerTableEditor.ID, telemetryService, _themeService, storageService); this._actionMap[ACTION_IDS.FIND_NEXT] = this._instantiationService.createInstance(ProfilerFindNext, this); @@ -89,6 +93,17 @@ export class ProfilerTableEditor extends BaseEditor implements IProfilerControll dataItemColumnValueExtractor: slickGridDataItemColumnValueExtractor }); this._profilerTable.setSelectionModel(new RowSelectionModel()); + const copyKeybind = new CopyKeybind(); + copyKeybind.onCopy((e) => { + // in context of this table, the selection mode is row selection, copy the whole row will get a lot of unwanted data + // ignore the passed in range and create a range so that it only copies the currently selected cell value. + const activeCell = this._profilerTable.activeCell; + handleCopyRequest(this._clipboardService, new Slick.Range(activeCell.row, activeCell.cell), (row, cell) => { + const fieldName = this._input.columns[cell].field; + return this._input.data.getItem(row)[fieldName]; + }); + }); + this._profilerTable.registerPlugin(copyKeybind); attachTableStyler(this._profilerTable, this._themeService); this._findState = new FindReplaceState();