123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // KMHistoryFileDeleteWindowController.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2022/11/8.
- //
- import Cocoa
- typealias historyFileDeleteCallback = (_ indexPaths: [URL], _ windowController: KMHistoryFileDeleteWindowController) -> Void
- class KMHistoryFileDeleteWindowController: KMBaseWindowController {
- @IBOutlet weak var deleteOptionsLabel: NSTextField!
- @IBOutlet weak var noLongerPromptView: NSView!
- @IBOutlet weak var cancelBox: NSBox!
- @IBOutlet weak var deleteBox: NSBox!
- @IBOutlet weak var iconImageView: NSImageView!
-
- var cancelVC: KMDesignButton!
- var deleteVC: KMDesignButton!
- var noLongerPromptVC: KMDesignButton!
-
- var deleteCallback: historyFileDeleteCallback?
- var indexPaths: [URL] = []
-
- override func windowDidLoad() {
- super.windowDidLoad()
-
- self.cancelVC = KMDesignButton.init(withType: .Text)
- self.deleteVC = KMDesignButton.init(withType: .Text)
- self.noLongerPromptVC = KMDesignButton.init(withType: .CheckBox)
-
- initLocalization()
- initializeUI()
- }
-
- // MARK: Init
-
- func initializeUI() {
- self.window?.backgroundColor = .white
- deleteOptionsLabel.font = NSFont(name: "PingFangSC-Semibold", size: 15)
- deleteOptionsLabel.textColor = KMAppearance.Layout.h0Color()
-
- cancelBox.fillColor = NSColor.km_init(hex: "#F5F5F5")
- cancelBox.cornerRadius = 5.0
- cancelBox.contentView = cancelVC.view
- cancelVC.target = self
- cancelVC.action = #selector(cancelAction(_:))
- cancelVC.updateUI()
-
- deleteBox.fillColor = .clear
- deleteBox.contentView = deleteVC.view
- deleteVC.target = self
- deleteVC.action = #selector(deleteAction(_:))
- deleteVC.button(type: .Cta, size: .m)
-
- noLongerPromptView.addSubview(noLongerPromptVC.view)
- noLongerPromptVC.view.mas_makeConstraints { (make) in
- make?.top.bottom().offset()(0)
- make?.centerX.offset()(0)
- }
- noLongerPromptVC.target = self
- noLongerPromptVC.action = #selector(deleteHistoryFileAction(_:))
- noLongerPromptVC.checkbox_radio()
- noLongerPromptVC.textColor = KMAppearance.Layout.h0Color()
- noLongerPromptVC.textColor_custom = KMAppearance.Layout.h0Color()
- noLongerPromptVC.textColor_none = KMAppearance.Layout.h0Color()
- noLongerPromptVC.textColor_hov = KMAppearance.Layout.h0Color()
- noLongerPromptVC.updateUI()
- }
-
- func initLocalization() {
- let firstPath = indexPaths.first?.path.lastPathComponent ?? ""
- // deleteOptionsLabel.stringValue = String(format: NSLocalizedString("Remove\"%@\"from your Recent Files?", comment: ""), firstPath)
- let urls: Array<URL> = NSDocumentController.shared.recentDocumentURLs
- if urls.count == indexPaths.count {
- deleteOptionsLabel.stringValue = NSLocalizedString("Clear All Recents", comment: "")
- } else {
- deleteOptionsLabel.stringValue = NSLocalizedString("Remove from Recents", comment: "")
- }
- noLongerPromptVC.stringValue = NSLocalizedString("Do not show this message again", comment: "")
- cancelVC.stringValue = NSLocalizedString("Cancel", comment: "")
- deleteVC.stringValue = NSLocalizedString("Delete", comment: "")
-
- let mainBundle = Bundle.main
- if let infoDictionary = mainBundle.infoDictionary {
- if let iconFileName: String = infoDictionary["CFBundleIconName"] as? String {
- let iconImage = NSImage(named: iconFileName)
- self.iconImageView.image = iconImage
- }
- }
- }
-
- // MARK: Private Methods
-
- @objc func cancelAction(_ sender: NSButton) -> Void {
- NSApp.mainWindow!.endSheet(self.window!)
- self.window?.orderOut(self)
- }
-
- @objc func deleteAction(_ sender: NSButton) -> Void {
- if let callback = deleteCallback {
- callback(indexPaths, self)
- }
- NSApp.mainWindow!.endSheet(self.window!)
- self.window?.orderOut(self)
- }
-
- // MARK: Action Methods
-
-
- @IBAction func deleteHistoryFileAction(_ sender: NSButton) {
- if noLongerPromptVC.state != .Checked {
- noLongerPromptVC.state = .Checked
- UserDefaults.standard.setValue(true, forKey: "kHistoryDeleteNOReminderKey")
- } else {
- noLongerPromptVC.state = .Norm
- UserDefaults.standard.setValue(false, forKey: "kHistoryDeleteNOReminderKey")
- }
- UserDefaults.standard.synchronize()
- }
- }
|