feat(sidebar): add shortcut to disconnect connections
This commit is contained in:
1 parent
30a4131bb2
commit
3a3eb7dd7c
19 files changed
+93
-5
No files matched your search
@@ -30,12 +30,12 @@ import { needsSidebarObjectGroupDiscovery } from "@/lib/sidebar/sidebarSearchDis
|
||||
import { isSidebarSearchPrunedDatabaseNode, resolveSidebarSearchDatabaseScope } from "@/lib/sidebar/sidebarSearchDatabaseScope";
|
||||
import { createSidebarSearchExpansionState } from "@/lib/sidebar/sidebarSearchExpansionState";
|
||||
import { createSidebarSearchLoadingTracker } from "@/lib/sidebar/sidebarSearchLoadingTracker";
|
||||
import { isCancelSearchShortcut, isCopySidebarSelectionShortcut, isEditSidebarConnectionShortcut, isPasteSidebarSelectionShortcut, isViewTableDdlShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { isCancelSearchShortcut, isCopySidebarSelectionShortcut, isDisconnectSidebarConnectionShortcut, isEditSidebarConnectionShortcut, isPasteSidebarSelectionShortcut, isViewTableDdlShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { sidebarNodeSupportsDdlView } from "@/lib/sidebar/sidebarTreeDdlShortcut";
|
||||
import { objectSourceTargetForTreeNode } from "@/lib/sidebar/treeNodeClick";
|
||||
import { supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
|
||||
import { copyToClipboard } from "@/lib/common/clipboard";
|
||||
import { connectionPasteTargetGroupId, copySelectedConnectionsToClipboards, selectedConnectionEditTarget } from "@/lib/sidebar/sidebarConnectionSelection";
|
||||
import { connectionPasteTargetGroupId, copySelectedConnectionsToClipboards, selectedConnectionDisconnectTargets, selectedConnectionEditTarget } from "@/lib/sidebar/sidebarConnectionSelection";
|
||||
import { formatSidebarTableCopyText } from "@/lib/sidebar/sidebarTableNameCopy";
|
||||
import { pruneTreeSelectionToVisibleNodeIds } from "@/lib/sidebar/sidebarTreeSelection";
|
||||
import { isEditableSidebarTypeSearchTarget, sidebarTypeSearchNextQuery } from "@/lib/sidebar/sidebarTypeSearch";
|
||||
@@ -2407,6 +2407,13 @@ function onWindowKeydown(event: KeyboardEvent) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sidebarShortcutTargetAllowsAppShortcut(event.target) && isDisconnectConnectionShortcut(event)) {
|
||||
if (requestSelectedConnectionDisconnect()) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sidebarShortcutTargetAllowsAppShortcut(event.target) && isCopySidebarSelectionShortcut(event, settingsStore.editorSettings.shortcuts)) {
|
||||
if (copySelectedSidebarNames()) {
|
||||
event.preventDefault();
|
||||
@@ -2467,6 +2474,10 @@ function isEditConnectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isEditSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
|
||||
function isDisconnectConnectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isDisconnectSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
|
||||
function requestSelectedConnectionEdit(): boolean {
|
||||
const selectedNodeId = store.selectedTreeNodeId;
|
||||
const currentNode = selectedNodeId ? flatTreeIndex.value.nodeById.get(selectedNodeId) : null;
|
||||
@@ -2477,6 +2488,26 @@ function requestSelectedConnectionEdit(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
function requestSelectedConnectionDisconnect(): boolean {
|
||||
const selectedNodeId = store.selectedTreeNodeId;
|
||||
const currentNode = selectedNodeId ? flatTreeIndex.value.nodeById.get(selectedNodeId) : null;
|
||||
if (!currentNode) return false;
|
||||
const targets = selectedConnectionDisconnectTargets(currentNode, selectedSidebarNodesInVisibleOrder());
|
||||
const connectedTargets = targets.filter((target) => store.connectedIds.has(target.connectionId));
|
||||
if (connectedTargets.length > 0) {
|
||||
const connectionIds = connectedTargets.map((target) => target.connectionId);
|
||||
void disconnectSidebarConnections(connectionIds, (connectionId) => store.disconnect(connectionId)).then((result) => {
|
||||
if (result.succeeded > 0 && result.failed === 0) {
|
||||
toast(connectionIds.length > 1 ? t("connection.disconnectedSelected", { count: connectionIds.length }) : t("connection.disconnected"), 2000);
|
||||
} else if (result.failed > 0) {
|
||||
toast(t("connection.disconnectSelectedPartial", { succeeded: result.succeeded, failed: result.failed }), 5000);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function copySelectedSidebarNames(): boolean {
|
||||
const nodes = selectedSidebarNodesInVisibleOrder();
|
||||
if (nodes.length === 0) return false;
|
||||
|
||||
@@ -145,7 +145,7 @@ import { copyDisplayPathForTreeNode, copyNameForTreeNode, isDirectNavigationTree
|
||||
import { customTypeCapabilities, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
|
||||
import { mongoCollectionTableTypeFromNode, mongoCreateDatabasePreview, mongoDropIndexFailureCount } from "@/lib/sidebar/mongoCollectionMutation";
|
||||
import { dataTabOpenModeFromTreeClick, type DataTabOpenMode } from "@/lib/sidebar/dataTabOpenPolicy";
|
||||
import { isCopySidebarSelectionShortcut, isEditSidebarConnectionShortcut, isModRShortcut, isPasteSidebarSelectionShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { isCopySidebarSelectionShortcut, isDisconnectSidebarConnectionShortcut, isEditSidebarConnectionShortcut, isModRShortcut, isPasteSidebarSelectionShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { handleSidebarTreeDeleteShortcut } from "@/lib/sidebar/sidebarTreeDeleteShortcut";
|
||||
import { dataTableDoubleClickAction } from "@/lib/tabs/dataTabActivation";
|
||||
import { attachedDatabaseNameFromPath, buildCreateDatabaseSql, buildDuckDbAttachDatabaseSql, buildSqliteAttachDatabaseSql, supportsCreateDatabaseCharset, supportsCreateDatabaseLocale, uniqueAttachedDatabaseName } from "@/lib/database/createDatabaseSql";
|
||||
@@ -1266,6 +1266,12 @@ function onKeydown(event: KeyboardEvent) {
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (isDisconnectConnectionShortcut(event)) {
|
||||
if (!requestDisconnectSelectedConnection()) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (isSidebarTreeArrowKey(event) && handleSidebarTreeArrowKey(event)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
@@ -1334,6 +1340,10 @@ function isEditConnectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isEditSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
|
||||
function isDisconnectConnectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isDisconnectSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
|
||||
function isCopyTreeSelectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isCopySidebarSelectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
@@ -1529,6 +1539,18 @@ function requestEditSelectedConnection(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
function requestDisconnectSelectedConnection(): boolean {
|
||||
if (canDisconnectConnection()) {
|
||||
void disconnectConnection();
|
||||
return true;
|
||||
}
|
||||
if (canDisconnectConnectionGroup()) {
|
||||
void disconnectConnectionGroup();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function requestDeleteSelectedNode(): boolean {
|
||||
claimTreeItemDialogOwnership();
|
||||
ensureDangerDialogRouting();
|
||||
@@ -5484,6 +5506,8 @@ const shortcutOpenDataInNewTab = computed(() => settingsStore.editorSettings.sho
|
||||
|
||||
const shortcutEditConnection = computed(() => settingsStore.editorSettings.shortcuts.editSidebarConnection);
|
||||
|
||||
const shortcutDisconnectConnection = computed(() => settingsStore.editorSettings.shortcuts.disconnectSidebarConnection);
|
||||
|
||||
const shortcutRename = "F2";
|
||||
|
||||
const shortcutRefresh = "F5";
|
||||
@@ -5624,7 +5648,7 @@ function buildConnectionSidebarMenu(context: SidebarMenuFactoryContext): boolean
|
||||
if (isConnecting.value) {
|
||||
items.push({ label: t("connection.cancelConnecting"), action: cancelConnectionAttempt, icon: X });
|
||||
} else if (canDisconnectConnection()) {
|
||||
items.push({ label: connectionDisconnectMenuLabel(), action: disconnectConnection, icon: Unplug });
|
||||
items.push({ label: connectionDisconnectMenuLabel(), action: disconnectConnection, icon: Unplug, shortcut: shortcutDisconnectConnection.value });
|
||||
// save_password=false 且本次运行期已输入密码:提供"断开并忘记本次密码",
|
||||
// 清除会话凭据后下次连接需重新输入。
|
||||
if (canForgetSessionCredential()) {
|
||||
@@ -5816,6 +5840,7 @@ function buildConnectionSidebarMenu(context: SidebarMenuFactoryContext): boolean
|
||||
action: disconnectConnectionGroup,
|
||||
icon: Unplug,
|
||||
disabled: !canDisconnectConnectionGroup(),
|
||||
shortcut: shortcutDisconnectConnection.value,
|
||||
});
|
||||
items.push({ label: "", separator: true });
|
||||
items.push({
|
||||
|
||||
Reference in new issue
Block a user