handle copy in all profiler tables (#6134)

* handle copy in all profiler tables

* use camel casing
This commit is contained in:
Alan Ren
2019-06-24 17:01:19 -07:00
committed by GitHub
parent 9a3daabeb4
commit a906a9c862
3 changed files with 63 additions and 2 deletions

View File

@@ -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);
}
}

View File

@@ -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"),

View File

@@ -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();