Skip to content

Commit

Permalink
Allow right click -> copy for all tree items (#1101)
Browse files Browse the repository at this point in the history
## Changes
<!-- Summary of your changes that are easy to understand -->

## Tests
<!-- How is this tested? -->
  • Loading branch information
kartikgupta-db authored Feb 28, 2024
1 parent ea7b079 commit ab214b4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
12 changes: 11 additions & 1 deletion packages/databricks-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@
"title": "Show bundle logs",
"enablement": "databricks.context.activated",
"category": "Databricks"
},
{
"command": "databricks.utils.copy",
"title": "Copy",
"enablement": "databricks.context.activated",
"category": "Databricks"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -434,6 +440,10 @@
"command": "databricks.bundle.cancelRun",
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.*.cancellable.*$/ && databricks.context.bundle.deploymentState == idle",
"group": "inline@0"
},
{
"command": "databricks.utils.copy",
"when": "view == dabsResourceExplorerView || view == configurationView"
}
],
"editor/title": [
Expand Down Expand Up @@ -509,7 +519,7 @@
"label": "Run on Databricks",
"icon": {
"dark": "resources/dark/databricks-run-icon.svg",
"light": "resources/light/logo.svg"
"light": "resources/light/databricks-run-icon.svg"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class ClusterComponent extends BaseComponent {
return [];
}
const cluster = this.connectionManager.cluster;
const children: TreeItem[] = [
const children: ConfigurationTreeItem[] = [
{
label: "Cluster ID",
description: cluster.id,
Expand Down
1 change: 1 addition & 0 deletions packages/databricks-vscode/src/configuration/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import {TreeItem} from "vscode";

export interface ConfigurationTreeItem extends TreeItem {
url?: string;
copyText?: string;
}
5 changes: 5 additions & 0 deletions packages/databricks-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ export async function activate(
utilCommands.openExternalCommand(),
utilCommands
),
telemetry.registerCommand(
"databricks.utils.copy",
utilCommands.copyToClipboardCommand(),
utilCommands
),
telemetry.registerCommand("databricks.call", (fn) => {
if (fn) {
fn();
Expand Down
36 changes: 35 additions & 1 deletion packages/databricks-vscode/src/utils/UtilsCommands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Disposable, window} from "vscode";
import {Disposable, window, env} from "vscode";
import {openExternal} from "./urlUtils";

export class UtilsCommands implements Disposable {
Expand All @@ -24,6 +24,40 @@ export class UtilsCommands implements Disposable {
};
}

copyToClipboardCommand() {
return async (value: any | undefined) => {
let text: string | undefined;

if (value?.copyText instanceof Promise) {
text = await value.copyText;
} else if (value.copyText !== undefined) {
text = value.copyText;
}

if (text === undefined && value?.getTreeItem !== undefined) {
const treeItem = value.getTreeItem();
if (treeItem instanceof Promise) {
value = await treeItem;
} else {
value = treeItem;
}
}

if (text === undefined) {
text = value?.copyText ?? value?.description ?? value?.label;
}

if (text === undefined) {
window.showErrorMessage(
"Databricks: Can't copy to clipboard. No text found."
);
return;
}
window.showInformationMessage("Copied to clipboard");
await env.clipboard.writeText(text);
};
}

dispose() {
this.disposables.forEach((d) => d.dispose());
}
Expand Down

0 comments on commit ab214b4

Please sign in to comment.