Skip to content

Commit

Permalink
Handle reopen
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Apr 11, 2021
1 parent 645ba79 commit 4fd444a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Squirrel Designer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,34 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {



func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}

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

Expand Down
3 changes: 3 additions & 0 deletions Squirrel Designer/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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? {
Expand Down

0 comments on commit 4fd444a

Please sign in to comment.