From b0903c059c2b86341697a12177bebbd96cda2e6a Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 4 Mar 2021 00:06:11 +0100 Subject: [PATCH 1/4] Enable Base --- Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj index 3dba69480..34c099ecf 100644 --- a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj +++ b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj @@ -365,6 +365,7 @@ hasScannedForEncodings = 1; knownRegions = ( en, + Base, ); mainGroup = 0867D691FE84028FC02AAC07 /* QueryKit */; productRefGroup = 034768DFFF38A50411DB9C8B /* Products */; From f75ea6ebe6bf3c7407e3c862aa9790b6cff9dc50 Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 4 Mar 2021 00:06:21 +0100 Subject: [PATCH 2/4] Convert window delegate to swift --- Source/Controllers/SPAppController.h | 3 + .../Controllers/Window/SPWindowController.h | 8 +- .../Controllers/Window/SPWindowController.m | 111 +----------------- .../Window/SPWindowController.swift | 78 ++++++++++-- Source/Sequel-Ace-Bridging-Header.h | 1 + 5 files changed, 79 insertions(+), 122 deletions(-) diff --git a/Source/Controllers/SPAppController.h b/Source/Controllers/SPAppController.h index 4e0fef72a..723cf1d43 100755 --- a/Source/Controllers/SPAppController.h +++ b/Source/Controllers/SPAppController.h @@ -29,6 +29,9 @@ // // More info at +#import +#import + @class SPPreferenceController; @class SPAboutController; @class SPDatabaseDocument; diff --git a/Source/Controllers/Window/SPWindowController.h b/Source/Controllers/Window/SPWindowController.h index 759e72aad..00503a5cf 100644 --- a/Source/Controllers/Window/SPWindowController.h +++ b/Source/Controllers/Window/SPWindowController.h @@ -34,16 +34,14 @@ @class SPDatabaseDocument; @protocol SPWindowControllerDelegate; -@interface SPWindowController : NSWindowController +@interface SPWindowController : NSWindowController { NSClipView *titleBarLineHidingView; - NSMenuItem *closeWindowMenuItem; - NSMenuItem *closeTabMenuItem; - NSMutableArray *managedDatabaseConnections; } - +@property (nonatomic, strong) NSMenuItem *closeWindowMenuItem; +@property (nonatomic, strong) NSMenuItem *closeTabMenuItem; @property (nonatomic, weak) id delegate; @property (nonatomic, strong) IBOutlet NSTabView *tabView; @property (nonatomic, strong) IBOutlet PSMTabBarControl *tabBarControl; diff --git a/Source/Controllers/Window/SPWindowController.m b/Source/Controllers/Window/SPWindowController.m index cec6d240c..36725f9d5 100644 --- a/Source/Controllers/Window/SPWindowController.m +++ b/Source/Controllers/Window/SPWindowController.m @@ -66,7 +66,7 @@ - (void)awakeFromNib { [super awakeFromNib]; [self setupAppearance]; -// [self setupConstraints]; FIXME: causes a crash + [self setupConstraints]; [self _switchOutSelectedTableDocument:nil]; @@ -85,8 +85,8 @@ - (void)awakeFromNib { // Retrieve references to the 'Close Window' and 'Close Tab' menus. These are updated as window focus changes. NSMenu *mainMenu = [NSApp mainMenu]; - closeWindowMenuItem = [[[mainMenu itemWithTag:SPMainMenuFile] submenu] itemWithTag:SPMainMenuFileClose]; - closeTabMenuItem = [[[mainMenu itemWithTag:SPMainMenuFile] submenu] itemWithTag:SPMainMenuFileCloseTab]; + _closeWindowMenuItem = [[[mainMenu itemWithTag:SPMainMenuFile] submenu] itemWithTag:SPMainMenuFileClose]; + _closeTabMenuItem = [[[mainMenu itemWithTag:SPMainMenuFile] submenu] itemWithTag:SPMainMenuFileCloseTab]; // Register for drag start and stop notifications - used to show/hide tab bars NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; @@ -483,111 +483,6 @@ - (void)_selectedTableDocumentDeallocd:(NSNotification *)notification [self _switchOutSelectedTableDocument:nil]; } -#pragma mark - SPWindowControllerDelegate - -/** - * Determine whether the window is permitted to close. - * Go through the tabs in this window, and ask the database connection view - * in each one if it can be closed, returning YES only if all can be closed. - */ -- (BOOL)windowShouldClose:(NSWindow *)sender { - for (NSTabViewItem *eachItem in [self.tabView tabViewItems]) { - SPDatabaseDocument *eachDocument = [eachItem databaseDocument]; - - if (![eachDocument parentTabShouldClose]) { - return NO; - } - } - - // Remove global session data if the last window of a session will be closed - if ([SPAppDelegate sessionURL] && [[SPAppDelegate windowControllers] count] == 1) { - [SPAppDelegate setSessionURL:nil]; - [SPAppDelegate setSpfSessionDocData:nil]; - } - [self.delegate windowControllerDidClose:self]; - return YES; -} - -/** - * When the window does close, close all tabs. - */ -- (void)windowWillClose:(NSNotification *)notification -{ - SPLog(@"windowWillClose, notification: %@", notification); - for (NSTabViewItem *eachItem in [self.tabView tabViewItems]) - { - [self.tabView removeTabViewItem:eachItem]; - } -} - -/** - * When the window becomes key, inform the selected tab and - * update menu items. - */ -- (void)windowDidBecomeKey:(NSNotification *)notification -{ - [self.selectedTableDocument tabDidBecomeKey]; - - // Update the "Close window" item - [closeWindowMenuItem setTitle:NSLocalizedString(@"Close Window", @"Close Window menu item")]; - [closeWindowMenuItem setKeyEquivalentModifierMask:(NSEventModifierFlagCommand | NSEventModifierFlagShift)]; - - // Ensure the "Close tab" item is enabled and has the standard shortcut - [closeTabMenuItem setEnabled:YES]; - [closeTabMenuItem setKeyEquivalent:@"w"]; - [closeTabMenuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand]; -} - -/** - * When the window resigns key, update menu items. - */ -- (void)windowDidResignKey:(NSNotification *)notification -{ - - // Disable the "Close tab" menu item - [closeTabMenuItem setEnabled:NO]; - [closeTabMenuItem setKeyEquivalent:@""]; - - // Update the "Close window" item to show only "Close" - [closeWindowMenuItem setTitle:NSLocalizedString(@"Close", @"Close menu item")]; - [closeWindowMenuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand]; -} - -/** - * Observe changes in main window status to update drawing state to match - */ -- (void)windowDidBecomeMain:(NSNotification *)notification -{ -} - -- (void)windowDidResignMain:(NSNotification *)notification -{ -} - -/** - * If the window is resized, notify all the tabs. - */ -- (void)windowDidResize:(NSNotification *)notification -{ - for (NSTabViewItem *eachItem in [self.tabView tabViewItems]) { - [[eachItem databaseDocument] tabDidResize]; - } -} - -/** - * If the window is entering fullscreen, update the front tab's titlebar status view visibility. - */ -- (void)windowWillEnterFullScreen:(NSNotification *)notification -{ -} - -/** - * If the window exits fullscreen, update the front tab's titlebar status view visibility. - */ -- (void)windowDidExitFullScreen:(NSNotification *)notification -{ -} - #pragma mark - #pragma mark Tab view delegate methods diff --git a/Source/Controllers/Window/SPWindowController.swift b/Source/Controllers/Window/SPWindowController.swift index ce6755626..dcf7bf031 100644 --- a/Source/Controllers/Window/SPWindowController.swift +++ b/Source/Controllers/Window/SPWindowController.swift @@ -11,19 +11,79 @@ import SnapKit extension SPWindowController { @objc func setupAppearance() { - // Here should ahppen all UI / layout setups + // Here should ahppen all UI / layout setups in the future ocne we remove .xib } @objc func setupConstraints() { - tabBarControl.snp.makeConstraints { - $0.top.equalToSuperview() - $0.leading.trailing.equalToSuperview() - $0.height.equalTo(25) + // Here we will set constraints in the future once we remove .xib, for now, commented out as it crashes +// tabBarControl.snp.makeConstraints { +// $0.top.equalToSuperview() +// $0.leading.trailing.equalToSuperview() +// $0.height.equalTo(25) +// } +// tabView.snp.makeConstraints { +// $0.top.equalTo(tabBarControl.snp.bottom) +// $0.leading.trailing.equalToSuperview() +// $0.bottom.equalToSuperview() +// } + } +} + +extension SPWindowController: NSWindowDelegate { + /// Determine whether the window is permitted to close. + /// Go through the tabs in this window, and ask the database connection view in each one if it can be closed, returning YES only if all can be closed. + /// - Parameter sender: NSWindow instance + /// - Returns: true or false + public func windowShouldClose(_ sender: NSWindow) -> Bool { + for tabItem in tabView.tabViewItems { + guard let document = tabItem.databaseDocument else { + continue + } + if !document.parentTabShouldClose() { + return false + } + } + + if let appDelegate = NSApp.delegate as? SPAppController, appDelegate.sessionURL() != nil, appDelegate.windowControllers.count == 1 { + appDelegate.setSessionURL(nil) + appDelegate.setSpfSessionDocData(nil) } - tabView.snp.makeConstraints { - $0.top.equalTo(tabBarControl.snp.bottom) - $0.leading.trailing.equalToSuperview() - $0.bottom.equalToSuperview() + delegate.windowControllerDidClose(self) + return true + } + + public func windowWillClose(_ notification: Notification) { + tabView.tabViewItems.forEach { + tabView.removeTabViewItem($0) + } + } + + public func windowDidBecomeKey(_ notification: Notification) { + selectedTableDocument.tabDidBecomeKey() + + // Update close tab + closeTabMenuItem.isEnabled = true + closeTabMenuItem.keyEquivalent = "w" + closeTabMenuItem.keyEquivalentModifierMask = .command + + // Update the "Close" item to show "Close window" + closeWindowMenuItem.title = NSLocalizedString("Close Window", comment: "Close Window menu item") + closeWindowMenuItem.keyEquivalentModifierMask = [.command, .shift] + } + + public func windowDidResignKey(_ notification: Notification) { + // Update close tab + closeTabMenuItem.isEnabled = true + closeTabMenuItem.keyEquivalentModifierMask = [.command, .shift] + + // Update the "Close window" item to show only "Close" + closeWindowMenuItem.title = NSLocalizedString("Close", comment: "Close menu item") + closeWindowMenuItem.keyEquivalentModifierMask = .command + } + + public func windowDidResize(_ notification: Notification) { + tabView.tabViewItems.forEach { + $0.databaseDocument?.tabDidResize() } } } diff --git a/Source/Sequel-Ace-Bridging-Header.h b/Source/Sequel-Ace-Bridging-Header.h index b0ac05a6b..1414d159a 100644 --- a/Source/Sequel-Ace-Bridging-Header.h +++ b/Source/Sequel-Ace-Bridging-Header.h @@ -27,6 +27,7 @@ // Use this file to import your target's public headers that you would like to expose to Swift. // +#import "SPAppController.h" #import "SPWindowController.h" #import "SPDatabaseDocument.h" #import "PSMTabBarControl.h" From d855f463ea97f7f77913431782e29291fc155ad2 Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 4 Mar 2021 00:08:02 +0100 Subject: [PATCH 3/4] Fix warning --- Resources/Localization/en.lproj/Localizable.strings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/Localization/en.lproj/Localizable.strings b/Resources/Localization/en.lproj/Localizable.strings index 7f451f07c..cc01e5387 100644 --- a/Resources/Localization/en.lproj/Localizable.strings +++ b/Resources/Localization/en.lproj/Localizable.strings @@ -3277,4 +3277,4 @@ "No Newer Release Available" = "No Newer Release Available"; /* Info alert message when there are Newer Releases Available */ -"You are currently running the latest release." = "You are currently running the latest release."' +"You are currently running the latest release." = "You are currently running the latest release."; From acffb8deaf4d771e29e3ba42e6154f07a67d106d Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 4 Mar 2021 00:16:44 +0100 Subject: [PATCH 4/4] Update PR template --- .github/pull_request_template.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index e50726155..578de4725 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -13,7 +13,7 @@ Please use one of these hashtags for your PR title: - ## Closes following issues: -- Closes +- Closes: ## Tested: - Processors: @@ -25,12 +25,12 @@ Please use one of these hashtags for your PR title: - [ ] 10.14.x (Mojave) - [ ] 10.15.x (Catalina) - [ ] 11.x (Big Sur) -- Xcode Version: - Localizations: - [ ] English - [ ] Spanish - [ ] Other (please specify) +- Xcode Version: + ## Screenshots: - ## Additional notes: