Skip to content

Commit ab214b4

Browse files
Allow right click -> copy for all tree items (#1101)
## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? -->
1 parent ea7b079 commit ab214b4

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

packages/databricks-vscode/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@
269269
"title": "Show bundle logs",
270270
"enablement": "databricks.context.activated",
271271
"category": "Databricks"
272+
},
273+
{
274+
"command": "databricks.utils.copy",
275+
"title": "Copy",
276+
"enablement": "databricks.context.activated",
277+
"category": "Databricks"
272278
}
273279
],
274280
"viewsContainers": {
@@ -434,6 +440,10 @@
434440
"command": "databricks.bundle.cancelRun",
435441
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.*.cancellable.*$/ && databricks.context.bundle.deploymentState == idle",
436442
"group": "inline@0"
443+
},
444+
{
445+
"command": "databricks.utils.copy",
446+
"when": "view == dabsResourceExplorerView || view == configurationView"
437447
}
438448
],
439449
"editor/title": [
@@ -509,7 +519,7 @@
509519
"label": "Run on Databricks",
510520
"icon": {
511521
"dark": "resources/dark/databricks-run-icon.svg",
512-
"light": "resources/light/logo.svg"
522+
"light": "resources/light/databricks-run-icon.svg"
513523
}
514524
}
515525
],

packages/databricks-vscode/src/configuration/ui/ClusterComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class ClusterComponent extends BaseComponent {
162162
return [];
163163
}
164164
const cluster = this.connectionManager.cluster;
165-
const children: TreeItem[] = [
165+
const children: ConfigurationTreeItem[] = [
166166
{
167167
label: "Cluster ID",
168168
description: cluster.id,

packages/databricks-vscode/src/configuration/ui/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import {TreeItem} from "vscode";
22

33
export interface ConfigurationTreeItem extends TreeItem {
44
url?: string;
5+
copyText?: string;
56
}

packages/databricks-vscode/src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ export async function activate(
653653
utilCommands.openExternalCommand(),
654654
utilCommands
655655
),
656+
telemetry.registerCommand(
657+
"databricks.utils.copy",
658+
utilCommands.copyToClipboardCommand(),
659+
utilCommands
660+
),
656661
telemetry.registerCommand("databricks.call", (fn) => {
657662
if (fn) {
658663
fn();

packages/databricks-vscode/src/utils/UtilsCommands.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Disposable, window} from "vscode";
1+
import {Disposable, window, env} from "vscode";
22
import {openExternal} from "./urlUtils";
33

44
export class UtilsCommands implements Disposable {
@@ -24,6 +24,40 @@ export class UtilsCommands implements Disposable {
2424
};
2525
}
2626

27+
copyToClipboardCommand() {
28+
return async (value: any | undefined) => {
29+
let text: string | undefined;
30+
31+
if (value?.copyText instanceof Promise) {
32+
text = await value.copyText;
33+
} else if (value.copyText !== undefined) {
34+
text = value.copyText;
35+
}
36+
37+
if (text === undefined && value?.getTreeItem !== undefined) {
38+
const treeItem = value.getTreeItem();
39+
if (treeItem instanceof Promise) {
40+
value = await treeItem;
41+
} else {
42+
value = treeItem;
43+
}
44+
}
45+
46+
if (text === undefined) {
47+
text = value?.copyText ?? value?.description ?? value?.label;
48+
}
49+
50+
if (text === undefined) {
51+
window.showErrorMessage(
52+
"Databricks: Can't copy to clipboard. No text found."
53+
);
54+
return;
55+
}
56+
window.showInformationMessage("Copied to clipboard");
57+
await env.clipboard.writeText(text);
58+
};
59+
}
60+
2761
dispose() {
2862
this.disposables.forEach((d) => d.dispose());
2963
}

0 commit comments

Comments
 (0)