Skip to content

Commit 528526d

Browse files
committed
debug: use clipboard service
microsoft#69104
1 parent 4184701 commit 528526d

5 files changed

Lines changed: 42 additions & 19 deletions

File tree

src/vs/workbench/contrib/debug/electron-browser/callStackView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export class CallStackView extends ViewletPanel {
294294
if (element.thread.session.capabilities.supportsRestartFrame) {
295295
actions.push(new RestartFrameAction(RestartFrameAction.ID, RestartFrameAction.LABEL, this.debugService, this.keybindingService));
296296
}
297-
actions.push(new CopyStackTraceAction(CopyStackTraceAction.ID, CopyStackTraceAction.LABEL));
297+
actions.push(this.instantiationService.createInstance(CopyStackTraceAction, CopyStackTraceAction.ID, CopyStackTraceAction.LABEL));
298298
} else {
299299
this.callStackItemType.reset();
300300
}

src/vs/workbench/contrib/debug/electron-browser/electronDebugActions.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ import * as nls from 'vs/nls';
77
import { Action } from 'vs/base/common/actions';
88
import { Variable } from 'vs/workbench/contrib/debug/common/debugModel';
99
import { IDebugService, IStackFrame } from 'vs/workbench/contrib/debug/common/debug';
10-
import { clipboard } from 'electron';
1110
import { isWindows } from 'vs/base/common/platform';
11+
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
1212

1313
export class CopyValueAction extends Action {
1414
static readonly ID = 'workbench.debug.viewlet.action.copyValue';
1515
static LABEL = nls.localize('copyValue', "Copy Value");
1616

17-
constructor(id: string, label: string, private value: any, private context: string, @IDebugService private readonly debugService: IDebugService) {
17+
constructor(
18+
id: string, label: string, private value: any, private context: string,
19+
@IDebugService private readonly debugService: IDebugService,
20+
@IClipboardService private readonly clipboardService: IClipboardService
21+
) {
1822
super(id, label, 'debug-action copy-value');
1923
this._enabled = typeof this.value === 'string' || (this.value instanceof Variable && !!this.value.evaluateName);
2024
}
@@ -25,11 +29,11 @@ export class CopyValueAction extends Action {
2529

2630
if (this.value instanceof Variable && stackFrame && session && this.value.evaluateName) {
2731
return session.evaluate(this.value.evaluateName, stackFrame.frameId, this.context).then(result => {
28-
clipboard.writeText(result.body.result);
29-
}, err => clipboard.writeText(this.value.value));
32+
this.clipboardService.writeText(result.body.result);
33+
}, err => this.clipboardService.writeText(this.value.value));
3034
}
3135

32-
clipboard.writeText(this.value);
36+
this.clipboardService.writeText(this.value);
3337
return Promise.resolve(undefined);
3438
}
3539
}
@@ -38,13 +42,16 @@ export class CopyEvaluatePathAction extends Action {
3842
static readonly ID = 'workbench.debug.viewlet.action.copyEvaluatePath';
3943
static LABEL = nls.localize('copyAsExpression', "Copy as Expression");
4044

41-
constructor(id: string, label: string, private value: Variable) {
45+
constructor(
46+
id: string, label: string, private value: Variable,
47+
@IClipboardService private readonly clipboardService: IClipboardService
48+
) {
4249
super(id, label);
4350
this._enabled = this.value && !!this.value.evaluateName;
4451
}
4552

4653
public run(): Promise<any> {
47-
clipboard.writeText(this.value.evaluateName!);
54+
this.clipboardService.writeText(this.value.evaluateName!);
4855
return Promise.resolve(undefined);
4956
}
5057
}
@@ -53,8 +60,15 @@ export class CopyAction extends Action {
5360
static readonly ID = 'workbench.debug.action.copy';
5461
static LABEL = nls.localize('copy', "Copy");
5562

63+
constructor(
64+
id: string, label: string,
65+
@IClipboardService private readonly clipboardService: IClipboardService
66+
) {
67+
super(id, label);
68+
}
69+
5670
public run(): Promise<any> {
57-
clipboard.writeText(window.getSelection().toString());
71+
this.clipboardService.writeText(window.getSelection().toString());
5872
return Promise.resolve(undefined);
5973
}
6074
}
@@ -65,8 +79,15 @@ export class CopyStackTraceAction extends Action {
6579
static readonly ID = 'workbench.action.debug.copyStackTrace';
6680
static LABEL = nls.localize('copyStackTrace', "Copy Call Stack");
6781

82+
constructor(
83+
id: string, label: string,
84+
@IClipboardService private readonly clipboardService: IClipboardService
85+
) {
86+
super(id, label);
87+
}
88+
6889
public run(frame: IStackFrame): Promise<any> {
69-
clipboard.writeText(frame.thread.getCallStack().map(sf => sf.toString()).join(lineDelimiter));
90+
this.clipboardService.writeText(frame.thread.getCallStack().map(sf => sf.toString()).join(lineDelimiter));
7091
return Promise.resolve(undefined);
7192
}
7293
}

src/vs/workbench/contrib/debug/electron-browser/repl.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { IInstantiationService, createDecorator } from 'vs/platform/instantiatio
2525
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
2626
import { Panel } from 'vs/workbench/browser/panel';
2727
import { IThemeService } from 'vs/platform/theme/common/themeService';
28-
import { clipboard } from 'electron';
2928
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
3029
import { memoize } from 'vs/base/common/decorators';
3130
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
@@ -66,6 +65,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
6665
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
6766
import { FuzzyScore, createMatches } from 'vs/base/common/filters';
6867
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
68+
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
6969

7070
const $ = dom.$;
7171

@@ -120,7 +120,8 @@ export class Repl extends Panel implements IPrivateReplService, IHistoryNavigati
120120
@IListService private readonly listService: IListService,
121121
@IConfigurationService private readonly configurationService: IConfigurationService,
122122
@ITextResourcePropertiesService private readonly textResourcePropertiesService: ITextResourcePropertiesService,
123-
@IKeybindingService private readonly keybindingService: IKeybindingService
123+
@IKeybindingService private readonly keybindingService: IKeybindingService,
124+
@IClipboardService private readonly clipboardService: IClipboardService
124125
) {
125126
super(REPL_ID, telemetryService, themeService, storageService);
126127

@@ -455,9 +456,9 @@ export class Repl extends Panel implements IPrivateReplService, IHistoryNavigati
455456

456457
private onContextMenu(e: ITreeContextMenuEvent<IReplElement>): void {
457458
const actions: IAction[] = [];
458-
actions.push(new CopyAction(CopyAction.ID, CopyAction.LABEL));
459+
actions.push(new CopyAction(CopyAction.ID, CopyAction.LABEL, this.clipboardService));
459460
actions.push(new Action('workbench.debug.action.copyAll', nls.localize('copyAll', "Copy All"), undefined, true, () => {
460-
clipboard.writeText(this.getVisibleContent());
461+
this.clipboardService.writeText(this.getVisibleContent());
461462
return Promise.resolve(undefined);
462463
}));
463464
actions.push(new ReplCollapseAllAction(this.tree, this.replInput));
@@ -823,7 +824,8 @@ class ReplCopyAllAction extends EditorAction {
823824
}
824825

825826
run(accessor: ServicesAccessor, editor: ICodeEditor): void | Promise<void> {
826-
clipboard.writeText(accessor.get(IPrivateReplService).getVisibleContent());
827+
const clipboardService = accessor.get(IClipboardService);
828+
clipboardService.writeText(accessor.get(IPrivateReplService).getVisibleContent());
827829
}
828830
}
829831

src/vs/workbench/contrib/debug/electron-browser/variablesView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ export class VariablesView extends ViewletPanel {
140140
const actions: IAction[] = [];
141141
const variable = element as Variable;
142142
actions.push(new SetValueAction(SetValueAction.ID, SetValueAction.LABEL, variable, this.debugService, this.keybindingService));
143-
actions.push(new CopyValueAction(CopyValueAction.ID, CopyValueAction.LABEL, variable, 'variables', this.debugService));
144-
actions.push(new CopyEvaluatePathAction(CopyEvaluatePathAction.ID, CopyEvaluatePathAction.LABEL, variable));
143+
actions.push(this.instantiationService.createInstance(CopyValueAction, CopyValueAction.ID, CopyValueAction.LABEL, variable, 'variables'));
144+
actions.push(this.instantiationService.createInstance(CopyEvaluatePathAction, CopyEvaluatePathAction.ID, CopyEvaluatePathAction.LABEL, variable));
145145
actions.push(new Separator());
146146
actions.push(new AddToWatchExpressionsAction(AddToWatchExpressionsAction.ID, AddToWatchExpressionsAction.LABEL, variable, this.debugService, this.keybindingService));
147147

src/vs/workbench/contrib/debug/electron-browser/watchExpressionsView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class WatchExpressionsView extends ViewletPanel {
152152
actions.push(new AddWatchExpressionAction(AddWatchExpressionAction.ID, AddWatchExpressionAction.LABEL, this.debugService, this.keybindingService));
153153
actions.push(new EditWatchExpressionAction(EditWatchExpressionAction.ID, EditWatchExpressionAction.LABEL, this.debugService, this.keybindingService));
154154
if (!expression.hasChildren) {
155-
actions.push(new CopyValueAction(CopyValueAction.ID, CopyValueAction.LABEL, expression.value, 'watch', this.debugService));
155+
actions.push(this.instantiationService.createInstance(CopyValueAction, CopyValueAction.ID, CopyValueAction.LABEL, expression.value, 'watch', this.debugService));
156156
}
157157
actions.push(new Separator());
158158

@@ -163,7 +163,7 @@ export class WatchExpressionsView extends ViewletPanel {
163163
if (element instanceof Variable) {
164164
const variable = element as Variable;
165165
if (!variable.hasChildren) {
166-
actions.push(new CopyValueAction(CopyValueAction.ID, CopyValueAction.LABEL, variable, 'watch', this.debugService));
166+
actions.push(this.instantiationService.createInstance(CopyValueAction, CopyValueAction.ID, CopyValueAction.LABEL, variable, 'watch', this.debugService));
167167
}
168168
actions.push(new Separator());
169169
}

0 commit comments

Comments
 (0)