123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- //
- // KMNExtractPDFWindowController.swift
- // PDF Reader Pro
- //
- // Created by 丁林圭 on 2024/10/24.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNExtractPDFWindowController: KMNBaseWindowController {
- @IBOutlet var titleLabel: NSTextField!
-
- @IBOutlet var eachButton: ComponentCheckBox!
- @IBOutlet var deleteButton: ComponentCheckBox!
- @IBOutlet var cancelButton: ComponentButton!
- @IBOutlet var extractButton: ComponentButton!
- @IBOutlet var cancelWidthButton:NSLayoutConstraint!
- @IBOutlet var extractWidthButton:NSLayoutConstraint!
- private var orgDocument:CPDFDocument?
- private var selectionIndexPaths: Set<IndexPath> = []
-
- var callback: ((Bool, Bool)->Void)?
-
- override func updateUIThemeColor() {
- super.updateUIThemeColor()
- window?.contentView?.wantsLayer = true
- window?.contentView?.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/popup").cgColor
- titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
-
- deleteButton.reloadData()
- eachButton.reloadData()
-
- cancelButton.reloadData()
- extractButton.reloadData()
- }
-
- override func updateUILanguage() {
- super.updateUILanguage()
-
- titleLabel.stringValue = KMLocalizedString("Extract")
- eachButton.properties.text = KMLocalizedString("Each page in a separate file")
- deleteButton.properties.text = KMLocalizedString("Delete pages after extraction")
-
- deleteButton.reloadData()
- eachButton.reloadData()
- cancelButton.properties.buttonText = KMLocalizedString("Cancel")
- extractButton.properties.buttonText = KMLocalizedString("Extract")
-
- cancelButton.reloadData()
- extractButton.reloadData()
-
- cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
- extractWidthButton.constant = extractButton.properties.propertyInfo.viewWidth
- }
-
- override func initContentView() {
- super.initContentView()
- titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
-
- eachButton.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: KMLocalizedString("Each page in a separate file"),
- checkboxType: .normal)
-
- deleteButton.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: KMLocalizedString("Delete pages after extraction"),
- checkboxType: .normal)
-
- extractButton.properties = ComponentButtonProperty(type: .primary,
- size: .s,
- state: .normal,
- isDisable: false,
- buttonText: KMLocalizedString("Extract"),keepPressState: false)
- extractButton.setTarget(self, action: #selector(extractButtonClicked(_ :)))
-
- cancelButton.properties = ComponentButtonProperty(type: .default_tertiary,
- size: .s,
- state: .normal,
- buttonText: KMLocalizedString("Cancel"))
- cancelButton.setTarget(self, action: #selector(cancelButtonClicked(_ :)))
-
- eachButton.setTarget(self, action: #selector(eachPDFAction(_:)))
- deleteButton.setTarget(self, action: #selector(deletePDFAction(_:)))
- }
- override func windowDidLoad() {
- super.windowDidLoad()
-
- if(selectionIndexPaths.count == orgDocument?.pageCount ?? 0) {
- deleteButton.properties.isDisabled = true
- deleteButton.reloadData()
- }
- }
-
- convenience init(_ document: CPDFDocument?, selectionIndexPaths: Set<IndexPath>) {
- self.init(windowNibName: "KMNExtractPDFWindowController")
- orgDocument = document
- self.selectionIndexPaths = selectionIndexPaths // 修正此行
- }
- convenience init(_ filePath: String,password:String?) {
- self.init(windowNibName: "KMNExtractPDFWindowController")
- let document = CPDFDocument.init(url: URL(fileURLWithPath: filePath))
- if password != nil {
- document?.unlock(withPassword: password as String?)
- }
- orgDocument = document
- selectionIndexPaths = [IndexPath(item: 0, section: 0)] // 修正此行
- }
-
- //MARK: - Action
- @objc func cancelButtonClicked(_ sender: NSView) {
- own_closeEndSheet()
- }
-
- @objc func extractButtonClicked(_ sender: NSView) {
-
- callback?(eachButton.properties.checkboxType == .selected,deleteButton.properties.checkboxType == .selected)
- }
- @objc func eachPDFAction(_ sender: NSView) {
- }
-
- @objc func deletePDFAction(_ sender: NSView) {
-
- }
-
-
- }
|