From c459bd1a4ea7e9419f4c89c927aa5ef10292a08c Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 16 Nov 2017 18:23:07 -0800 Subject: [PATCH] Add Panic Button UI. --- Evergreen.xcodeproj/project.pbxproj | 16 +++ Evergreen/AppDelegate.swift | 14 +++ Evergreen/Base.lproj/Main.storyboard | 10 +- .../MainWindow/MainWindowController.swift | 5 + .../PanicButton/PanicButtonWindow.xib | 115 ++++++++++++++++++ .../PanicButtonWindowController.swift | 43 +++++++ 6 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 Evergreen/MainWindow/PanicButton/PanicButtonWindow.xib create mode 100644 Evergreen/MainWindow/PanicButton/PanicButtonWindowController.swift diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index 4ce95aa7d..01bf30dfb 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -67,6 +67,8 @@ 849C64761ED37A5D003D8FC0 /* EvergreenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849C64751ED37A5D003D8FC0 /* EvergreenTests.swift */; }; 84A6B6941FB8D43C006754AC /* DinosaursWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84A6B6931FB8D43C006754AC /* DinosaursWindow.xib */; }; 84A6B6961FB8DBD2006754AC /* DinosaursWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A6B6951FB8DBD2006754AC /* DinosaursWindowController.swift */; }; + 84AFBB3C1FBE76D800BA41CF /* PanicButtonWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AFBB3B1FBE76D800BA41CF /* PanicButtonWindowController.swift */; }; + 84AFBB3E1FBE770200BA41CF /* PanicButtonWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84AFBB3D1FBE770200BA41CF /* PanicButtonWindow.xib */; }; 84B06FAE1ED37DBD00F0B54B /* RSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84B06FA91ED37DAD00F0B54B /* RSCore.framework */; }; 84B06FAF1ED37DBD00F0B54B /* RSCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84B06FA91ED37DAD00F0B54B /* RSCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84B06FB21ED37DBD00F0B54B /* RSDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84B06F9D1ED37DA000F0B54B /* RSDatabase.framework */; }; @@ -449,6 +451,8 @@ 849C64771ED37A5D003D8FC0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 84A6B6931FB8D43C006754AC /* DinosaursWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DinosaursWindow.xib; sourceTree = ""; }; 84A6B6951FB8DBD2006754AC /* DinosaursWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DinosaursWindowController.swift; sourceTree = ""; }; + 84AFBB3B1FBE76D800BA41CF /* PanicButtonWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PanicButtonWindowController.swift; sourceTree = ""; }; + 84AFBB3D1FBE770200BA41CF /* PanicButtonWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PanicButtonWindow.xib; sourceTree = ""; }; 84B06F961ED37DA000F0B54B /* RSDatabase.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSDatabase.xcodeproj; path = Frameworks/RSDatabase/RSDatabase.xcodeproj; sourceTree = ""; }; 84B06FA21ED37DAC00F0B54B /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = Frameworks/RSCore/RSCore.xcodeproj; sourceTree = ""; }; 84B06FB61ED37E8B00F0B54B /* RSWeb.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSWeb.xcodeproj; path = Frameworks/RSWeb/RSWeb.xcodeproj; sourceTree = ""; }; @@ -525,6 +529,7 @@ 849A97811ED9EC63007D329B /* Status Bar */, 849A97551ED9EAC3007D329B /* Add Feed */, 849A97411ED9EAA9007D329B /* Add Folder */, + 84AFBB3A1FBE76D800BA41CF /* PanicButton */, ); name = MainWindow; path = Evergreen/MainWindow; @@ -779,6 +784,15 @@ path = Evergreen/Dinosaurs; sourceTree = ""; }; + 84AFBB3A1FBE76D800BA41CF /* PanicButton */ = { + isa = PBXGroup; + children = ( + 84AFBB3D1FBE770200BA41CF /* PanicButtonWindow.xib */, + 84AFBB3B1FBE76D800BA41CF /* PanicButtonWindowController.swift */, + ); + path = PanicButton; + sourceTree = ""; + }; 84B06F971ED37DA000F0B54B /* Products */ = { isa = PBXGroup; children = ( @@ -1208,6 +1222,7 @@ 849A978F1ED9EE72007D329B /* DefaultFeeds.plist in Resources */, 849A979D1ED9EFEB007D329B /* template.html in Resources */, 849A97A91ED9F9AA007D329B /* AddFeedSheet.xib in Resources */, + 84AFBB3E1FBE770200BA41CF /* PanicButtonWindow.xib in Resources */, 842E45E71ED8C747000A8B52 /* DB5.plist in Resources */, 849A97AC1ED9F9BC007D329B /* AddFolderSheet.xib in Resources */, 849A97AF1ED9FA08007D329B /* FeedList.storyboard in Resources */, @@ -1252,6 +1267,7 @@ 849A979F1ED9F130007D329B /* SidebarCell.swift in Sources */, 849A97651ED9EB96007D329B /* SidebarTreeControllerDelegate.swift in Sources */, 849A97671ED9EB96007D329B /* UnreadCountView.swift in Sources */, + 84AFBB3C1FBE76D800BA41CF /* PanicButtonWindowController.swift in Sources */, 84E95D241FB1087500552D99 /* ArticlePasteboardWriter.swift in Sources */, 84A6B6961FB8DBD2006754AC /* DinosaursWindowController.swift in Sources */, 849A975B1ED9EB0D007D329B /* ArticleUtilities.swift in Sources */, diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index 4eef8689c..a738f1d2b 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -33,6 +33,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { var keyboardShortcutsWindowController: WebViewWindowController? var inspectorWindowController: InspectorWindowController? var logWindowController: LogWindowController? + var panicButtonWindowController: PanicButtonWindowController? + let log = Log() let themeLoader = VSThemeLoader() private let appNewsURLString = "https://ranchero.com/evergreen/feed.json" @@ -75,6 +77,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { addFolderWindowController!.runSheetOnWindow(window) } + func hitPanicButton(with window: NSWindow) { + + panicButtonWindowController = PanicButtonWindowController() + panicButtonWindowController!.runSheetOnWindow(window) + } + // MARK: - NSApplicationDelegate func applicationDidFinishLaunching(_ note: Notification) { @@ -355,6 +363,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { Browser.open("https://ranchero.com/evergreen/help/1.0/", inBackground: false) } + + @IBAction func hitPanicButton(_ sender: Any?) { + + createAndShowMainWindow() + hitPanicButton(with: mainWindowController!.window!) + } } private extension AppDelegate { diff --git a/Evergreen/Base.lproj/Main.storyboard b/Evergreen/Base.lproj/Main.storyboard index cc27e2a4f..d4d23bd64 100644 --- a/Evergreen/Base.lproj/Main.storyboard +++ b/Evergreen/Base.lproj/Main.storyboard @@ -1,7 +1,7 @@ - + - + @@ -426,6 +426,12 @@ + + + + + + diff --git a/Evergreen/MainWindow/MainWindowController.swift b/Evergreen/MainWindow/MainWindowController.swift index a5e9e8ec6..781426de2 100644 --- a/Evergreen/MainWindow/MainWindowController.swift +++ b/Evergreen/MainWindow/MainWindowController.swift @@ -158,6 +158,11 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { splitViewController!.toggleSidebar(sender) } + + @IBAction func hitPanicButton(_ sender: Any?) { + + appDelegate.hitPanicButton(with: window!) + } } // MARK: - Private diff --git a/Evergreen/MainWindow/PanicButton/PanicButtonWindow.xib b/Evergreen/MainWindow/PanicButton/PanicButtonWindow.xib new file mode 100644 index 000000000..dafa7fed1 --- /dev/null +++ b/Evergreen/MainWindow/PanicButton/PanicButtonWindow.xib @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Evergreen/MainWindow/PanicButton/PanicButtonWindowController.swift b/Evergreen/MainWindow/PanicButton/PanicButtonWindowController.swift new file mode 100644 index 000000000..59bb0f135 --- /dev/null +++ b/Evergreen/MainWindow/PanicButton/PanicButtonWindowController.swift @@ -0,0 +1,43 @@ +// +// PanicButtonWindowController.swift +// Evergreen +// +// Created by Brent Simmons on 11/16/17. +// Copyright © 2017 Ranchero Software. All rights reserved. +// + +import Cocoa + +final class PanicButtonWindowController: NSWindowController { + + var hostWindow: NSWindow? + + convenience init() { + + self.init(windowNibName: NSNib.Name(rawValue: "PanicButtonWindow")) + } + + func runSheetOnWindow(_ w: NSWindow) { + + hostWindow = w + hostWindow!.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in + } + } + + private func closeSheet(_ response: NSApplication.ModalResponse) { + + hostWindow!.endSheet(window!, returnCode: response) + } + + // MARK: - Actions + + @IBAction func cancel(_ sender: AnyObject) { + + closeSheet(.cancel) + } + + @IBAction func performPanic(_ sender: AnyObject) { + + closeSheet(.OK) + } +}