diff --git a/Squirrel Designer/AppDelegate.swift b/Squirrel Designer/AppDelegate.swift index 5e2297f..acb4172 100644 --- a/Squirrel Designer/AppDelegate.swift +++ b/Squirrel Designer/AppDelegate.swift @@ -11,8 +11,6 @@ import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { - - func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application } @@ -20,6 +18,27 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } + + func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { + if ViewController.currentInstance == nil { + let storyboard = NSStoryboard(name: "Main", bundle: nil) + let windowController = storyboard.instantiateController(withIdentifier: "Main Window Controller") as! NSWindowController + if let mainWindow = windowController.window { + windowController.showWindow(sender) + if let frame = mainWindowFrame { + mainWindow.setFrameOrigin(frame.origin) + } + if let codeView = CodeViewController.currentInstance { + (mainWindow.contentViewController as! ViewController).childWindow = codeView.view.window?.windowController + (mainWindow.contentViewController as! ViewController).generateCodeButton.title = NSLocalizedString("Hide Code", comment: "Hide Code") + } + if preview.isVisible { + (mainWindow.contentViewController as! ViewController).showPreviewButton.title = NSLocalizedString("Hide Preview", comment: "Hide Preview") + } + } + } + return false + } // MARK: - Core Data stack diff --git a/Squirrel Designer/ViewController.swift b/Squirrel Designer/ViewController.swift index 38035eb..093be4d 100644 --- a/Squirrel Designer/ViewController.swift +++ b/Squirrel Designer/ViewController.swift @@ -12,6 +12,7 @@ import Cocoa var layout = SquirrelLayout(new: false) var inputSource = InputSource(new: false) let preview = SquirrelPanel(position: NSZeroRect) +var mainWindowFrame: NSRect? class FontPopUpButton: NSPopUpButton { weak var fontTraits: NSPopUpButton? @@ -923,10 +924,12 @@ class ViewController: NSViewController { NSColorPanel.shared.mode = .RGB Self.currentInstance = self } + override func viewDidDisappear() { NSColorPanel.shared.showsAlpha = false NSColorPanel.shared.mode = .wheel Self.currentInstance = nil + mainWindowFrame = view.window!.convertToScreen(view.frame) } override var representedObject: Any? {