feat(connection): add copy connection name

This commit is contained in:
Terry Yao authored and GitHub committed 2026-07-24 23:48:52 +08:00
1 parent 7ee335e38a
commit f2ce70dd68
4 files changed
+49 -9

No files matched your search

@@ -11,7 +11,7 @@ import { filterSidebarSearchRootsByConnectionState, filterSidebarTree, filterSid
import { isCancelSearchShortcut, isCopySidebarSelectionShortcut, isEditSidebarConnectionShortcut, isPasteSidebarSelectionShortcut } from "@/lib/editor/keyboardShortcuts";
import { copyNameForTreeNode, objectSourceKindForTreeNode } from "@/lib/sidebar/treeNodeClick";
import { copyToClipboard } from "@/lib/common/clipboard";
import { connectionPasteTargetGroupId, selectedConnectionClipboardNodes, selectedConnectionEditTarget } from "@/lib/sidebar/sidebarConnectionSelection";
import { connectionPasteTargetGroupId, copySelectedConnectionsToClipboards, selectedConnectionEditTarget } from "@/lib/sidebar/sidebarConnectionSelection";
import { isEditableSidebarTypeSearchTarget, sidebarTypeSearchNextQuery } from "@/lib/sidebar/sidebarTypeSearch";
import { usesTreeSchemaMode } from "@/lib/database/databaseFeatureSupport";
import { connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection } from "@/lib/database/jdbcDialect";
@@ -1304,11 +1304,10 @@ function requestSelectedConnectionEdit(): boolean {
function copySelectedSidebarNames(): boolean {
const nodes = selectedSidebarNodesInVisibleOrder();
if (nodes.length === 0) return false;
const connectionNodes = selectedConnectionClipboardNodes(nodes);
if (connectionNodes.length > 0) {
const copiedCount = store.copyConnectionsToTreeClipboard(connectionNodes.map((node) => node.connectionId));
if (copiedCount > 0) toast(t("connection.copied"), 2000);
return copiedCount > 0;
const copiedCount = copySelectedConnectionsToClipboards(nodes, (connectionIds) => store.copyConnectionsToTreeClipboard(connectionIds), copyToClipboard);
if (copiedCount > 0) {
toast(t("connection.copied"), 2000);
return true;
}
const tableNodes = nodes.filter((node) => node.type === "table" && !!node.connectionId && !!node.database);
store.treeClipboard =
@@ -1285,7 +1285,14 @@ async function copySelectedNames() {
const connectionTargets = selectedConnectionClipboardTargets(activeNode.value, nodes);
if (connectionTargets.length > 0) {
const copiedCount = connectionStore.copyConnectionsToTreeClipboard(connectionTargets.map((node) => node.connectionId));
if (copiedCount > 0) toast(t("connection.copied"), 2000);
if (copiedCount > 0) {
try {
await copyToClipboard(connectionTargets.map(copyNameForTreeNode).join("\n"));
} catch {
/* system clipboard copy is best-effort */
}
toast(t("connection.copied"), 2000);
}
return;
}
updateTreeClipboardForNodes(nodes);
@@ -3504,6 +3511,9 @@ function buildConnectionSidebarMenu(context: SidebarMenuFactoryContext): boolean
} else {
items.push({ label: t("contextMenu.closeConnection"), action: disconnectConnection, icon: Unplug });
}
items.push({ label: "", separator: true });
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });
items.push({ label: "", separator: true });
items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });
if (currentDatabaseType() === "redis") {
items.push({ label: t("contextMenu.instanceInfo"), action: openRedisInstanceInfo, icon: Info });