Fix window size resetting on new tab

This commit is contained in:
Shadowfacts 2020-08-11 22:27:08 -04:00
parent 31962b43a3
commit 1ab9d53006
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 14 additions and 9 deletions

View File

@ -16,9 +16,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var serverConnectWindowController: ServerConnectWindowController?
func applicationDidFinishLaunching(_ aNotification: Notification) {
let wc = DatabaseWindowController()
windowControllers.append(wc)
wc.showWindow(nil)
newWindow(mongoController: nil)
}
func applicationWillTerminate(_ aNotification: Notification) {
@ -31,7 +29,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
windowControllers.append(wc)
if addToTabGroup,
let tabGroup = windowControllers.first(where: { $0.window!.isKeyWindow })?.window?.tabGroup {
let existing = windowControllers.first(where: { $0.window!.isKeyWindow })?.window,
let tabGroup = existing.tabGroup {
tabGroup.addWindow(wc.window!)
tabGroup.selectedWindow = wc.window!
} else {

View File

@ -41,10 +41,14 @@ class DatabaseWindowController: NSWindowController {
.receive(on: DispatchQueue.main)
.sink { self.updateStatusText(manager: $0) }
connectionStatusChangeHandler = mongoController.$status
.receive(on: DispatchQueue.main)
.filter { $0 == .connected }
.sink { (_) in self.initializeUI() }
if mongoController.client != nil {
initializeUI()
} else {
connectionStatusChangeHandler = mongoController.$status
.receive(on: DispatchQueue.main)
.filter { $0 == .connected }
.sink { (_) in self.initializeUI() }
}
if setupMongo {
mongoController.setup()
@ -89,8 +93,10 @@ class DatabaseWindowController: NSWindowController {
private func initializeUI() {
databaseViewController = DatabaseViewController(mongoController: mongoController)
// otherwise the VC size uses the size from the nib, potentially changing the window size
databaseViewController.view.frame = CGRect(origin: .zero, size: window!.frame.size)
contentViewController = databaseViewController
if let initialCollection = initialCollection {
databaseViewController.showCollection(initialCollection)
}