57 lines
1.6 KiB
Swift
57 lines
1.6 KiB
Swift
//
|
|
// DatabaseWindowController.swift
|
|
// MongoView
|
|
//
|
|
// Created by Shadowfacts on 1/9/20.
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
|
|
class DatabaseWindowController: NSWindowController {
|
|
|
|
private var titleObservation: NSKeyValueObservation?
|
|
|
|
var mongoController: MongoController!
|
|
var initialCollection: DatabaseCollection?
|
|
|
|
private var databaseViewController: DatabaseViewController!
|
|
|
|
convenience init() {
|
|
self.init(windowNibName: "DatabaseWindowController")
|
|
}
|
|
|
|
override func windowDidLoad() {
|
|
super.windowDidLoad()
|
|
|
|
if mongoController == nil {
|
|
mongoController = MongoController(connectionString: "mongodb://localhost:27017")
|
|
mongoController.setup()
|
|
}
|
|
|
|
databaseViewController = DatabaseViewController(mongoController: mongoController)
|
|
contentViewController = databaseViewController
|
|
|
|
if let initialCollection = initialCollection {
|
|
databaseViewController.showCollection(initialCollection)
|
|
}
|
|
|
|
titleObservation = observe(\.contentViewController?.title) { [unowned self] (_, _) in
|
|
self.updateWindowTitle()
|
|
}
|
|
updateWindowTitle()
|
|
|
|
window!.tabbingMode = .preferred
|
|
window!.tabbingIdentifier = mongoController.connectionString
|
|
}
|
|
|
|
override func newWindowForTab(_ sender: Any?) {
|
|
(NSApplication.shared.delegate as! AppDelegate).newWindow(mongoController: mongoController)
|
|
}
|
|
|
|
private func updateWindowTitle() {
|
|
window?.title = databaseViewController.title ?? "MongoView"
|
|
}
|
|
|
|
}
|