123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //
- // KMSubscribeSuccessWindowController.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2023/6/26.
- //
- import Cocoa
- var subscribeSuccessController: KMSubscribeSuccessWindowController?
- var subscribeSuccessMainWindow: NSWindow?
- typealias KMSubscribeSuccessWindowControllerCloseAction = (_ controller: KMSubscribeSuccessWindowController) -> Void
- class KMSubscribeSuccessWindowController: NSWindowController {
-
- @IBOutlet weak var successView: KMSubscribeSuccessView!
- var closeAction: KMSubscribeSuccessWindowControllerCloseAction?
-
- deinit {
- KMPrint("KMSubscribeSuccessWindowController 释放")
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- self.setup()
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- }
-
- //MARK: 打开文件
- static func show(window: NSWindow) -> KMSubscribeSuccessWindowController {
- if let controller: KMSubscribeSuccessWindowController = KMSubscribeSuccessWindowController.fetchSampleController() {
- return controller
- } else {
- let subscribeSuccessWindowController: KMSubscribeSuccessWindowController = KMSubscribeSuccessWindowController.init(windowNibName: "KMSubscribeSuccessWindowController")
- window.beginSheet(subscribeSuccessWindowController.window!)
- subscribeSuccessWindowController.window?.center()
-
- subscribeSuccessWindowController.closeAction = { controller in
- controller.closeWindow()
- }
-
- subscribeSuccessController = subscribeSuccessWindowController
- subscribeSuccessMainWindow = window
- return subscribeSuccessWindowController
- }
- }
-
- func setup() {
- self.window?.contentView?.backgroundColor(NSColor.km_init(hex: "#FFFFFF"))
- self.successView.doneAction = { [weak self] view in
-
- guard let callBack = self?.closeAction else { return }
-
-
- callBack((self!))
- }
- }
-
- func closeWindow() {
- if subscribeSuccessMainWindow != nil {
- subscribeSuccessMainWindow?.endSheet((subscribeSuccessController?.window)!)
- }
-
- if subscribeSuccessController != nil {
- subscribeSuccessController?.window?.close()
- }
- subscribeSuccessController = nil
- subscribeSuccessMainWindow = nil
- }
-
- static func fetchSampleController() -> KMSubscribeSuccessWindowController? {
- for window in NSApp.windows {
- let controller = window.windowController
- if controller is KMSubscribeSuccessWindowController {
- return controller as! KMSubscribeSuccessWindowController
- }
- }
-
- return nil
- }
- }
|