From 78702ae3254da62597e9be05a0de15bb55882c7c Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Mon, 8 Jul 2019 08:40:29 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Adds=20window=20to=20view=20term?= =?UTF-8?q?inal=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon.xcodeproj/project.pbxproj | 8 +-- phpmon/AppDelegate.swift | 14 +++++ .../Base.lproj/Main.storyboard | 56 +++++++++++++++++-- ...ntroller.swift => LogViewController.swift} | 8 ++- 4 files changed, 75 insertions(+), 11 deletions(-) rename phpmon/View Controllers/{ViewController.swift => LogViewController.swift} (51%) diff --git a/phpmon.xcodeproj/project.pbxproj b/phpmon.xcodeproj/project.pbxproj index 75b2821..039ffbe 100644 --- a/phpmon.xcodeproj/project.pbxproj +++ b/phpmon.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */; }; - C41C1B3922B0097F00E7CF16 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B3822B0097F00E7CF16 /* ViewController.swift */; }; + C41C1B3922B0097F00E7CF16 /* LogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B3822B0097F00E7CF16 /* LogViewController.swift */; }; C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3A22B0098000E7CF16 /* Assets.xcassets */; }; C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3C22B0098000E7CF16 /* Main.storyboard */; }; C41C1B4722B009A400E7CF16 /* Shell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4622B009A400E7CF16 /* Shell.swift */; }; @@ -22,7 +22,7 @@ /* Begin PBXFileReference section */ C41C1B3322B0097F00E7CF16 /* phpmon.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = phpmon.app; sourceTree = BUILT_PRODUCTS_DIR; }; C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - C41C1B3822B0097F00E7CF16 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + C41C1B3822B0097F00E7CF16 /* LogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogViewController.swift; sourceTree = ""; }; C41C1B3A22B0098000E7CF16 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; C41C1B3D22B0098000E7CF16 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; C41C1B3F22B0098000E7CF16 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -116,7 +116,7 @@ isa = PBXGroup; children = ( C41C1B3C22B0098000E7CF16 /* Main.storyboard */, - C41C1B3822B0097F00E7CF16 /* ViewController.swift */, + C41C1B3822B0097F00E7CF16 /* LogViewController.swift */, ); path = "View Controllers"; sourceTree = ""; @@ -195,7 +195,7 @@ C41C1B4722B009A400E7CF16 /* Shell.swift in Sources */, C41C1B4D22B0215A00E7CF16 /* Services.swift in Sources */, C41C1B4922B00A9800E7CF16 /* ImageGenerator.swift in Sources */, - C41C1B3922B0097F00E7CF16 /* ViewController.swift in Sources */, + C41C1B3922B0097F00E7CF16 /* LogViewController.swift in Sources */, C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */, C41C1B4B22B019FF00E7CF16 /* PhpVersion.swift in Sources */, C476FF9822B0DD830098105B /* Alert.swift in Sources */, diff --git a/phpmon/AppDelegate.swift b/phpmon/AppDelegate.swift index 202a7f3..b026e3b 100644 --- a/phpmon/AppDelegate.swift +++ b/phpmon/AppDelegate.swift @@ -18,6 +18,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { var version: PhpVersion? = nil var availablePhpVersions : [String] = [] var busy: Bool = false + var log: String = "" + var windowController: NSWindowController? = nil // MARK: - Lifecycle @@ -90,6 +92,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { menu.addItem(NSMenuItem(title: "Switching PHP versions...", action: nil, keyEquivalent: "")) menu.addItem(NSMenuItem.separator()) } + menu.addItem(NSMenuItem(title: "View terminal output...", action: #selector(self.openOutput), keyEquivalent: "")) menu.addItem(NSMenuItem(title: "About phpmon", action: #selector(self.openAbout), keyEquivalent: "")) menu.addItem(NSMenuItem(title: "Quit phpmon", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")) DispatchQueue.main.async { @@ -100,6 +103,17 @@ class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - Callable via Obj-C (#selector) + @objc func openOutput() { + if (self.windowController == nil) { + let vc = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "logWindow") as! LogViewController + let window = NSWindow(contentViewController: vc) + window.title = "Terminal Output" + self.windowController = NSWindowController(window: window) + } + self.windowController!.showWindow(self) + // TODO: Send window to front (if possible) + } + @objc func updatePhpVersionInStatusBar() { self.version = PhpVersion() if (self.busy) { diff --git a/phpmon/View Controllers/Base.lproj/Main.storyboard b/phpmon/View Controllers/Base.lproj/Main.storyboard index 5d2ce08..7716961 100644 --- a/phpmon/View Controllers/Base.lproj/Main.storyboard +++ b/phpmon/View Controllers/Base.lproj/Main.storyboard @@ -52,20 +52,66 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/phpmon/View Controllers/ViewController.swift b/phpmon/View Controllers/LogViewController.swift similarity index 51% rename from phpmon/View Controllers/ViewController.swift rename to phpmon/View Controllers/LogViewController.swift index 52830ea..13bab06 100644 --- a/phpmon/View Controllers/ViewController.swift +++ b/phpmon/View Controllers/LogViewController.swift @@ -8,6 +8,10 @@ import Cocoa -class ViewController: NSViewController { - +class LogViewController: NSViewController { + + @IBAction func pressed(_ sender: Any) { + self.view.window?.windowController?.close() + } + }