From 88d81f343ec81ed079903b9e1164f250aca94429 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 11 Jul 2019 08:30:46 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Move=20window=20logic=20to?= =?UTF-8?q?=20VC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/AppDelegate.swift | 11 +---------- phpmon/View Controllers/LogViewController.swift | 13 +++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/phpmon/AppDelegate.swift b/phpmon/AppDelegate.swift index 666452c..bfb90c4 100644 --- a/phpmon/AppDelegate.swift +++ b/phpmon/AppDelegate.swift @@ -107,16 +107,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate { // MARK: - Callable via Obj-C (#selector) @objc func openOutput() { - if (App.shared.windowController == nil) { - let vc = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "logWindow") as! LogViewController - Shell.shared.delegate = vc - let window = NSWindow(contentViewController: vc) - window.title = "Terminal Output" - window.delegate = self - App.shared.windowController = NSWindowController(window: window) - } - App.shared.windowController!.showWindow(self) - NSApp.activate(ignoringOtherApps: true) + LogViewController.show(delegate: self) } @objc func updatePhpVersionInStatusBar() { diff --git a/phpmon/View Controllers/LogViewController.swift b/phpmon/View Controllers/LogViewController.swift index 73be213..f67a9ff 100644 --- a/phpmon/View Controllers/LogViewController.swift +++ b/phpmon/View Controllers/LogViewController.swift @@ -10,6 +10,19 @@ import Cocoa class LogViewController: NSViewController, ShellDelegate { + public static func show(delegate: NSWindowDelegate? = nil) { + if (App.shared.windowController == nil) { + let vc = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "logWindow") as! LogViewController + Shell.shared.delegate = vc + let window = NSWindow(contentViewController: vc) + window.title = "Terminal Output" + window.delegate = delegate + App.shared.windowController = NSWindowController(window: window) + } + App.shared.windowController!.showWindow(self) + NSApp.activate(ignoringOtherApps: true) + } + @IBOutlet var textView: NSTextView! public func appendHistoryItem(_ historyItem: ShellHistoryItem) {