// // KMRedactPageRangeContentView.swift // PDF Master // // Created by tangchao on 2023/1/19. // import Cocoa class KMRedactPageRangeContentView: KMRedactContentBaseView { @IBOutlet weak var currentPageRadio: NSButton! @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 totalNumberLabel: NSTextField! var pageCount: Int { get { -1 } set { self.totalNumberLabel.stringValue = "/\(newValue)" } } override func awakeFromNib() { super.awakeFromNib() self.currentPageRadio.title = NSLocalizedString("Mark current page", comment: "") self.allPageRadio.title = NSLocalizedString("Mark all pages", comment: "") self.oddPageRadio.title = NSLocalizedString("Mark odd pages", comment: "") self.evenPageRadio.title = NSLocalizedString("Mark even pages", comment: "") self.customPageRadio.title = NSLocalizedString("Mark specific page range", comment: "") for radio in [self.currentPageRadio, self.allPageRadio, self.oddPageRadio, self.evenPageRadio, self.customPageRadio] { radio?.target = self radio?.action = #selector(radioAction) } selectRadio(self.currentPageRadio) 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.currentPageRadio, 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.currentPageRadio, 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 KMRedactPageRangeContentView: NSTextFieldDelegate { func controlTextDidChange(_ obj: Notification) { if ((self.inputTextField.isEqual(to: obj.object)) == false) { return } guard let callback = self.itemClick else { return } callback(6, self.inputTextField.stringValue) } }