// // KMRedactMutilPageFlagContentView.swift // PDF Master // // Created by tangchao on 2023/1/19. // import Cocoa class KMRedactMutilPageFlagContentView: KMRedactContentBaseView { @IBOutlet weak var allPageRadio: NSButton! @IBOutlet weak var oddPageRadio: NSButton! @IBOutlet weak var evenPageRadio: NSButton! @IBOutlet weak var customPageRadio: NSButton! @IBOutlet weak var inputView: NSView! @IBOutlet weak var inputTextField: NSTextField! @IBOutlet weak var totalPageNumberLabel: NSTextField! var pageCount: Int { get { -1 } set { self.totalPageNumberLabel.stringValue = "/\(newValue)" } } override func awakeFromNib() { super.awakeFromNib() self.allPageRadio.title = NSLocalizedString("All Pages", comment: "") self.oddPageRadio.title = NSLocalizedString("Odd Pages", comment: "") self.evenPageRadio.title = NSLocalizedString("Even Pages", comment: "") self.customPageRadio.title = NSLocalizedString("Customized", comment: "") for radio in [self.allPageRadio, self.oddPageRadio, self.evenPageRadio, self.customPageRadio] { radio?.target = self radio?.action = #selector(radioAction) } selectRadio(self.allPageRadio) self.inputView.wantsLayer = true self.inputView.layer?.backgroundColor = NSColor(white: 238.0/255.0, alpha: 1.0).cgColor self.inputTextField.placeholderString = NSLocalizedString("e.g. 1,3-5,10", comment: "") self.inputTextField.focusRingType = .none self.inputTextField.delegate = self } @objc private func radioAction(sender: NSButton) { selectRadio(sender) guard let callback = self.itemClick else { return } var index: Int = 1 for radio in [self.allPageRadio, self.oddPageRadio, self.evenPageRadio, self.customPageRadio] { if ((radio?.isEqual(to: sender))!) { break } index += 1 } callback(index, nil) } private func selectRadio(_ selectedRadio: NSButton) { for radio in [self.allPageRadio, self.oddPageRadio, self.evenPageRadio, self.customPageRadio] { if ((radio?.isEqual(to: selectedRadio))!) { radio?.state = .on } else { radio?.state = .off } } if (customPageRadio.state == .on) { self.inputTextField.isEditable = true } else { self.inputTextField.isEditable = false } } } extension KMRedactMutilPageFlagContentView: NSTextFieldDelegate { func controlTextDidChange(_ obj: Notification) { if ((self.inputTextField.isEqual(to: obj.object)) == false) { return } guard let callback = self.itemClick else { return } callback(5, self.inputTextField.stringValue) } }