From bc13a1a3b3d5212df339c9042ec2d9ef17a896e7 Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Sun, 11 Oct 2026 09:22:30 +0300 Subject: [PATCH] fix(connections): confirm before removing a connection and leave its workspace Remove connection deleted the connection at once from the context menu, and the workspace of the removed connection stayed open with the status bar still naming it. Removal now asks in a destructive QueryaConfirmDialog, and the shell goes back to the start screen when the removed connection was the open one. --- .../connections/connections_panel.dart | 27 +++++++++++++++++++ lib/features/main_screen/main_screen.dart | 6 +++++ 2 files changed, 33 insertions(+) diff --git a/lib/features/connections/connections_panel.dart b/lib/features/connections/connections_panel.dart index 1bcc9a0c..2b823f63 100644 --- a/lib/features/connections/connections_panel.dart +++ b/lib/features/connections/connections_panel.dart @@ -485,6 +485,7 @@ class ConnectionsPanel extends StatefulWidget { this.onSqliteObjectSelected, this.onSqliteOpenSqlWorkspace, this.onExtensionObjectSelected, + this.onConnectionRemoved, /// When true, [initState] does not call [_loadData]. Widget tests that seed /// SQLite in setUp should call [ConnectionsPanelState.reloadConnectionsFromDb] @@ -565,6 +566,10 @@ class ConnectionsPanel extends StatefulWidget { String name, )? onExtensionObjectSelected; + /// Called after a connection was removed, so the shell can leave its + /// workspace if it was the open one. + final void Function(int connectionId)? onConnectionRemoved; + final bool skipInitialDbLoadForTest; @override @@ -802,9 +807,31 @@ class ConnectionsPanelState extends State { ); } + /// Asks first: removing a connection deletes its saved settings and + /// password and closes its sessions. The database itself is not touched. Future _removeConnection(int id) async { + String? name; + for (final c in _connections) { + if (c.id == id) { + name = c.name; + break; + } + } + final confirmed = await QueryaConfirmDialog.show( + context: context, + title: 'Remove connection?', + message: name == null || name.isEmpty + ? 'The connection and its saved password are removed from Querya. ' + 'The database itself is not changed.' + : '"$name" and its saved password are removed from Querya. ' + 'The database itself is not changed.', + confirmLabel: 'Remove', + isDestructive: true, + ); + if (confirmed != true || !mounted) return; await _closeSessionsOf(id); await LocalDb.instance.removeConnection(id); + widget.onConnectionRemoved?.call(id); await _loadData(); } diff --git a/lib/features/main_screen/main_screen.dart b/lib/features/main_screen/main_screen.dart index 6eb95e71..c80f7c29 100644 --- a/lib/features/main_screen/main_screen.dart +++ b/lib/features/main_screen/main_screen.dart @@ -1754,6 +1754,12 @@ class _ConnectionsPanelSlotState extends State<_ConnectionsPanelSlot> { onSqliteObjectSelected: widget.onSqliteObjectSelected, onSqliteOpenSqlWorkspace: widget.onSqliteOpenSqlWorkspace, onExtensionObjectSelected: widget.onExtensionObjectSelected, + onConnectionRemoved: (id) { + // The open workspace belonged to the removed connection: go home. + if (widget.workspace.value.activeConnection?.id != id) return; + widget.workspace.value = MainScreenWorkspaceState.empty; + QueryaShellStatus.instance.clear(); + }, ); } }