-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(tabs): add database context rail #2113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0a307f7
feat(tabs): add database context rail
joelhy 8bb6ab6
fix(tabs): share one workspace context registry
joelhy 47db45a
fix(tabs): wire context rail into window grouping
joelhy 700915b
fix(tabs): make context close atomic and guard running queries
joelhy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,3 +168,4 @@ Libs/ios/ | |
| .analysis/ | ||
| .docs/ | ||
| /plans/reports | ||
| .worktrees/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
TablePro/Core/Services/Infrastructure/WorkspaceContextActivationCoordinator.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import AppKit | ||
| import Foundation | ||
|
|
||
| // WorkspaceContextActivationCoordinator.swift — reconnect/database/schema activation and visible-group switching | ||
| // Part of the Database Context Rail feature (Task 3 of the plan). | ||
|
|
||
| @MainActor | ||
| internal final class WorkspaceContextActivationCoordinator { | ||
| private var registry: WorkspaceContextRegistry | ||
|
|
||
| internal static let shared = WorkspaceContextActivationCoordinator() | ||
|
|
||
| internal init(registry: WorkspaceContextRegistry = .shared) { | ||
| self.registry = registry | ||
| } | ||
|
|
||
| internal func openOrActivate( | ||
| connection: DatabaseConnection, | ||
| databaseName: String?, | ||
| schemaName: String?, | ||
| initialQuery _: String? = nil | ||
| ) { | ||
| let key = WorkspaceContextResolver.resolve( | ||
| connection: connection, | ||
| databaseName: databaseName, | ||
| schemaName: schemaName, | ||
| session: DatabaseManager.shared.session(for: connection.id) | ||
| ) | ||
| activate(key) | ||
| } | ||
|
|
||
| internal func activate( | ||
| _ key: WorkspaceContextKey, | ||
| preferredWindowId: UUID? = nil, | ||
| sourceWindow _: NSWindow? = nil | ||
| ) { | ||
| guard let sequence = registry.beginActivation(for: key) else { return } | ||
|
|
||
| let window = windowToRaise(for: key, preferredWindowId: preferredWindowId) | ||
| if let window { | ||
| if let group = window.tabGroup, group.selectedWindow !== window { | ||
| group.selectedWindow = window | ||
| } | ||
| window.makeKeyAndOrderFront(nil) | ||
| NSApp.activate() | ||
| } | ||
|
|
||
| registry.commitActivation(key, request: sequence) | ||
| } | ||
|
|
||
| private func windowToRaise(for key: WorkspaceContextKey, preferredWindowId: UUID?) -> NSWindow? { | ||
| if let preferredWindowId, | ||
| let preferred = MainContentCoordinator.coordinator(for: preferredWindowId)?.contentWindow { | ||
| return preferred | ||
| } | ||
|
|
||
| let registered = registry.windowIds(for: key).compactMap { windowId in | ||
| MainContentCoordinator.coordinator(for: windowId)?.contentWindow | ||
| } | ||
| if let lastFocused = WindowLifecycleMonitor.shared.mostRecentWindow(for: key.connectionId), | ||
| registered.contains(where: { $0 === lastFocused }) { | ||
| return lastFocused | ||
| } | ||
| return registered.first | ||
| ?? WindowLifecycleMonitor.shared.mostRecentWindow(for: key.connectionId) | ||
| } | ||
| } | ||
79 changes: 79 additions & 0 deletions
79
TablePro/Core/Services/Infrastructure/WorkspaceContextCloseCoordinator.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import AppKit | ||
| import Foundation | ||
|
|
||
| // WorkspaceContextCloseCoordinator.swift — atomic preflight/save/discard/close of every window in one context | ||
| // Part of the Database Context Rail feature (Task 4 of the plan). | ||
|
|
||
| @MainActor | ||
| internal final class WorkspaceContextCloseCoordinator { | ||
| private let registry: WorkspaceContextRegistry | ||
| private let confirmWindow: (UUID) async -> Bool | ||
| private let closeWindow: (UUID) -> Void | ||
| private let activate: (WorkspaceContextKey) -> Void | ||
|
|
||
| internal static let shared = WorkspaceContextCloseCoordinator() | ||
|
|
||
| internal init( | ||
| registry: WorkspaceContextRegistry = .shared, | ||
| confirmWindow: ((UUID) async -> Bool)? = nil, | ||
| closeWindow: ((UUID) -> Void)? = nil, | ||
| activate: ((WorkspaceContextKey) -> Void)? = nil | ||
| ) { | ||
| self.registry = registry | ||
| self.confirmWindow = confirmWindow ?? WorkspaceContextCloseCoordinator.confirmRegisteredWindow | ||
| self.closeWindow = closeWindow ?? WorkspaceContextCloseCoordinator.commitRegisteredWindow | ||
| self.activate = activate ?? { key in | ||
| WorkspaceContextActivationCoordinator.shared.activate(key) | ||
| } | ||
| } | ||
|
|
||
| internal func close(key: WorkspaceContextKey, sourceWindow _: NSWindow?) async -> Bool { | ||
| let windowIds = registry.windowIds(for: key) | ||
|
|
||
| // Confirm every window before any close. A later cancel must leave earlier | ||
| // windows open and still registered. | ||
| for windowId in windowIds { | ||
| guard await confirmWindow(windowId) else { return false } | ||
| } | ||
|
|
||
| for windowId in windowIds { | ||
| closeWindow(windowId) | ||
| registry.unregister(windowId: windowId) | ||
| } | ||
|
|
||
| if registry.contains(key) { | ||
| registry.unregisterAll(for: key) | ||
| } | ||
|
|
||
| if let nextKey = registry.selectedKey { | ||
| activate(nextKey) | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| /// Unsaved SQL, pending grid edits, and a running query all prompt here. | ||
| /// Nothing is closed or unregistered until every window has agreed. | ||
| private static func confirmRegisteredWindow(_ windowId: UUID) async -> Bool { | ||
| guard let coordinator = MainContentCoordinator.coordinator(for: windowId) else { | ||
| return true | ||
| } | ||
| if let actions = coordinator.commandActions { | ||
| return await actions.confirmWindowClose() | ||
| } | ||
| // A live coordinator without command actions still has work that | ||
| // confirmWindowClose would have prompted for. Do not discard it. | ||
| if coordinator.hasAnyUnsavedWork() { return false } | ||
| if coordinator.toolbarState.isExecuting { return false } | ||
| return true | ||
| } | ||
|
|
||
| private static func commitRegisteredWindow(_ windowId: UUID) { | ||
| guard let coordinator = MainContentCoordinator.coordinator(for: windowId) else { return } | ||
| if let actions = coordinator.commandActions { | ||
| actions.commitWindowClose(asBatchSurvivor: false) | ||
| return | ||
| } | ||
| coordinator.contentWindow?.close() | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context activation only raises a window; it never reconnects or switches to
key.databaseName/key.schemaName, so the sidebar and subsequent tabs can remain bound to the previous scope. Switch scope first, then raise and commit only the latest activation request.