123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- //
- // KMAlertWindowController.swift
- // PDF Reader Pro
- //
- // Created by kdanmobile on 2023/10/27.
- //
- import Cocoa
- typealias alertConfirmCallback = () -> ()
- let kShowRemoveAllFilesHintinterfaceKey = "kShowRemoveAllFilesHintinterfaceKey"
- class KMAlertWindowController: NSWindowController{
- var alertConfirmCallback: alertConfirmCallback?
-
- @IBOutlet var titleLabel: NSTextField!
-
- @IBOutlet var alertCheckButton: NSButton!
-
- @IBOutlet var cancelButton: NSButton!
-
- @IBOutlet var actionButton: NSButton!
-
- @objc class func swiftLoad() {
- let dict: NSDictionary = UserDefaults.standard.dictionaryRepresentation() as NSDictionary
- var X = false
- for key in dict.allKeys {
- if let data = key as? String, data == kShowRemoveAllFilesHintinterfaceKey{
- X = true
- }
- }
- if !X {
- UserDefaults().set(true, forKey: kShowRemoveAllFilesHintinterfaceKey)
- }
- }
- override func windowDidLoad() {
- super.windowDidLoad()
- self.titleLabel.stringValue = NSLocalizedString("Remove All", comment: "")
- self.alertCheckButton.title = NSLocalizedString("No longer prompt", comment: "")
- self.cancelButton.title = NSLocalizedString("Cancel", comment: "")
- self.actionButton.title = NSLocalizedString("Remove All", comment: "")
- }
-
- @IBAction func buttonClicked_Cancel(_ sender: NSButton) {
- self.setNeedShowRemoveAllFilesHint()
- self.dismissSheet(sender)
- }
-
- @IBAction func buttonClicked_OK(_ sender: NSButton) {
- self.setNeedShowRemoveAllFilesHint()
- setNeedShowRemoveAllFilesHint()
- self.alertConfirmCallback?()
- self.dismissSheet(sender)
- }
-
- func setNeedShowRemoveAllFilesHint() {
- UserDefaults.standard.set(self.alertCheckButton.state == .on ? false : true, forKey: kShowRemoveAllFilesHintinterfaceKey)
- UserDefaults.standard.synchronize()
- }
-
- func dismissSheet(_ sender: NSButton) {
- if #available(macOS 10.13, *) {
- self.window?.endSheet(sender.window!)
- } else {
- NSApp.endSheet(self.window!)
- }
- self.window?.orderOut(self)
- }
-
- class func needShowRemoveAllFilesHint() -> Bool {
- return UserDefaults().bool(forKey: kShowRemoveAllFilesHintinterfaceKey)
- }
-
- }
|