123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- //
- // KMPageEditSplitSettingView.swift
- // Cisdem PDFMaster
- //
- // Created by tangchao on 2023/1/12.
- //
- class KMPageEditSplitSettingView: KMPageEditSettingBaseView {
- @IBOutlet weak var typeLabel: NSTextField!
-
- @IBOutlet weak var oneFileForOnePageRadio: NSButton!
- @IBOutlet weak var oneFileForOnePageView: NSView!
- @IBOutlet weak var oneFileForOnePageOtherLabel: NSTextField!
-
- private var oneFileForOnePageVC: KMDesignButton?
- private var oneFileForOnePageStepperView: KMDesignStepperView?
-
- @IBOutlet weak var splitMuitiFileRadio: NSButton!
- @IBOutlet weak var splitMuitiFileView: NSView!
- @IBOutlet weak var splitMuitiFileOtherLabel: NSTextField!
-
- private var splitMuitiFileVC: KMDesignButton?
- private var splitMuitiFileStepperView: KMDesignStepperView?
-
- @IBOutlet weak var pageRangeRadio: NSButton!
- @IBOutlet weak var pageRangeComboBox: NSComboBox!
-
- private var pageRangeVC: KMDesignButton?
- private var pageRangeComboVC: KMDesignSelect?
-
- @IBOutlet weak var nameLabel: NSTextField!
- @IBOutlet weak var nameView: NSView!
- @IBOutlet weak var nameViewLabel: NSTextField!
- @IBOutlet weak var prefixForOrigFileNameCheck: NSButton!
- @IBOutlet weak var tagCheck: NSButton!
- @IBOutlet weak var sepCheck: NSButton!
- @IBOutlet weak var tagView: NSView!
- @IBOutlet weak var sepView: NSView!
-
- private var prefixForOrigFileNameVC: KMDesignButton?
- private var tagVC: KMDesignButton?
- private var sepVC: KMDesignButton?
-
- private var tTextField: KMDesignTextField?
- private var sTextField: KMDesignTextField?
-
- var type: Int {
- get {
- -1
- }
- set {
- if (newValue == 0) {
- self.safe_selectRadio(sender: self.oneFileForOnePageVC)
- } else if (newValue == 1) {
- self.safe_selectRadio(sender: self.splitMuitiFileVC)
- } else if (newValue == 2) {
- self.safe_selectRadio(sender: self.pageRangeVC)
- }
- }
- }
-
- var pageCount: Int = 0 {
- didSet {
- self.oneFileForOnePageStepperView?.maxValue = Double(self.pageCount)
- self.splitMuitiFileStepperView?.maxValue = Double(self.pageCount)
- }
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- self.typeLabel.stringValue = NSLocalizedString("Split Method", comment: "")
- self.typeLabel.textColor = KMAppearance.subtitleColor()
- self.typeLabel.font = .SFProTextSemiboldFont(12)
-
- self.oneFileForOnePageOtherLabel.stringValue = NSLocalizedString("page(s)", comment: "")
-
- self.oneFileForOnePageVC = KMDesignButton(withType: .RadioButton)
- self.oneFileForOnePageRadio.addSubview(self.oneFileForOnePageVC!.view)
- self.oneFileForOnePageVC?.view.frame = self.oneFileForOnePageRadio.bounds
- self.oneFileForOnePageVC?.view.autoresizingMask = [.width, .height]
- self.oneFileForOnePageVC?.target = self
- self.oneFileForOnePageVC?.action = #selector(oneFileForOnePageAction)
- self.oneFileForOnePageVC?.stringValue = NSLocalizedString("Split by every", comment: "")
- self.oneFileForOnePageVC?.checkbox_radio()
-
- self.oneFileForOnePageStepperView = KMDesignStepperView()
- self.oneFileForOnePageStepperView?.minValue = 1
- self.oneFileForOnePageStepperView?.kmValue = 1
- self.oneFileForOnePageStepperView?.delegate = self
- self.oneFileForOnePageView.addSubview(self.oneFileForOnePageStepperView!)
- self.oneFileForOnePageStepperView?.frame = self.oneFileForOnePageView.bounds
- self.oneFileForOnePageStepperView?.autoresizingMask = [.width, .height]
-
- self.splitMuitiFileStepperView = KMDesignStepperView()
- self.splitMuitiFileStepperView?.minValue = 1
- self.splitMuitiFileStepperView?.kmValue = 1
- self.splitMuitiFileStepperView?.delegate = self
- self.splitMuitiFileView.addSubview(self.splitMuitiFileStepperView!)
- self.splitMuitiFileStepperView?.frame = self.splitMuitiFileView.bounds
- self.splitMuitiFileStepperView?.autoresizingMask = [.width, .height]
-
- self.splitMuitiFileOtherLabel.stringValue = NSLocalizedString("files", comment: "")
-
- self.splitMuitiFileVC = KMDesignButton(withType: .RadioButton)
- self.splitMuitiFileRadio.addSubview(self.splitMuitiFileVC!.view)
- self.splitMuitiFileVC?.view.frame = self.splitMuitiFileRadio.bounds
- self.splitMuitiFileVC?.view.autoresizingMask = [.width, .height]
- self.splitMuitiFileVC?.target = self
- self.splitMuitiFileVC?.action = #selector(splitMuitiFileAction)
- self.splitMuitiFileVC?.stringValue = NSLocalizedString("Split averagely to", comment: "")
- self.splitMuitiFileVC?.checkbox_radio()
-
- self.pageRangeComboBox.isEnabled = false
- self.pageRangeComboVC = KMDesignSelect(withType: .Combox)
- self.pageRangeComboBox.addSubview(self.pageRangeComboVC!.view)
- self.pageRangeComboVC?.view.frame = self.pageRangeComboBox.bounds
- self.pageRangeComboVC?.view.autoresizingMask = [.width, .height]
- self.pageRangeComboVC?.delete = self
- self.pageRangeComboVC?.addItems(withObjectValues: [KMTools.pageRangeTypeString(pageRange: .odd),
- KMTools.pageRangeTypeString(pageRange: .even),
- KMTools.pageRangeTypeString(pageRange: .custom)])
- self.pageRangeComboVC?.placeholderString = KMTools.pageRangePlaceholderString()
-
- self.pageRangeVC = KMDesignButton(withType: .RadioButton)
- self.pageRangeRadio.addSubview(self.pageRangeVC!.view)
- self.pageRangeVC?.view.frame = self.pageRangeRadio.bounds
- self.pageRangeVC?.view.autoresizingMask = [.width, .height]
- self.pageRangeVC?.target = self
- self.pageRangeVC?.action = #selector(pageRangeAction)
- self.pageRangeVC?.stringValue = NSLocalizedString("Split by page range", comment: "")
- self.pageRangeVC?.checkbox_radio()
-
- self.safe_selectRadio(sender: self.oneFileForOnePageVC)
-
- self.nameLabel.stringValue = NSLocalizedString("File Name", comment: "")
- self.nameLabel.textColor = KMAppearance.subtitleColor()
- self.nameLabel.font = .SFProTextSemiboldFont(12)
-
- self.nameView.wantsLayer = true
- self.nameView.layer?.backgroundColor = KMAppearance.view_bg_dis_color().cgColor
- self.nameView.layer?.borderWidth = 1
- self.nameView.layer?.borderColor = KMAppearance.view_border_dis_color().cgColor
- self.nameView.layer?.cornerRadius = 4
- self.nameViewLabel.textColor = KMAppearance.titleColor()
- self.nameViewLabel.font = .SFProTextRegularFont(14)
- self.nameViewLabel.lineBreakMode = .byTruncatingTail
-
- self.prefixForOrigFileNameVC = KMDesignButton(withType: .CheckBox)
- self.prefixForOrigFileNameCheck.addSubview(self.prefixForOrigFileNameVC!.view)
- self.prefixForOrigFileNameVC?.view.frame = self.prefixForOrigFileNameCheck.bounds
- self.prefixForOrigFileNameVC?.view.autoresizingMask = [.width, .height]
- self.prefixForOrigFileNameVC?.target = self
- self.prefixForOrigFileNameVC?.action = #selector(prefixForOrigFileNameAction)
- self.prefixForOrigFileNameVC?.stringValue = NSLocalizedString("Show original file name in front", comment: "")
- self.prefixForOrigFileNameVC?.checkbox_radio()
- self.safe_selectCheck(sender: self.prefixForOrigFileNameVC)
-
- self.tagVC = KMDesignButton(withType: .CheckBox)
- self.tagCheck.addSubview(self.tagVC!.view)
- self.tagVC?.view.frame = self.tagCheck.bounds
- self.tagVC?.view.autoresizingMask = [.width, .height]
- self.tagVC?.target = self
- self.tagVC?.action = #selector(tagAction)
- self.tagVC?.stringValue = NSLocalizedString("Label", comment: "")
- self.tagVC?.checkbox_radio()
- self.safe_selectCheck(sender: self.tagVC)
-
- self.tTextField = KMDesignTextField(designSize: .medium)
- self.tagView.addSubview(self.tTextField!)
- self.tTextField?.frame = self.tagView.bounds
- self.tTextField?.autoresizingMask = [.width, .height]
- self.tTextField?.stringValue = "part"
- self.tTextField?.delegate = self
- self.sTextField = KMDesignTextField(designSize: .medium)
- self.sepView.addSubview(self.sTextField!)
- self.sTextField?.frame = self.sepView.bounds
- self.sTextField?.autoresizingMask = [.width, .height]
- self.sTextField?.stringValue = "-"
- self.sTextField?.delegate = self
-
- self.sepVC = KMDesignButton(withType: .CheckBox)
- self.sepCheck.addSubview(self.sepVC!.view)
- self.sepVC?.view.frame = self.sepCheck.bounds
- self.sepVC?.view.autoresizingMask = [.width, .height]
- self.sepVC?.target = self
- self.sepVC?.action = #selector(sepAction)
- self.sepVC?.stringValue = NSLocalizedString("Separator", comment: "")
- self.sepVC?.checkbox_radio()
- self.safe_selectCheck(sender: self.sepVC)
-
- for view in [self.oneFileForOnePageView, self.splitMuitiFileView] {
- view?.wantsLayer = true
- view?.layer?.backgroundColor = NSColor(white: 238.0/255.0, alpha: 1.0).cgColor
- view?.layer?.cornerRadius = 2
- }
- }
-
- @objc private func oneFileForOnePageAction() {
- self.safe_selectRadio(sender: self.oneFileForOnePageVC)
-
- guard let callback = self.itemClick else {
- return
- }
-
- callback(1, 0)
- }
-
- @objc private func splitMuitiFileAction() {
- self.safe_selectRadio(sender: self.splitMuitiFileVC)
-
- guard let callback = self.itemClick else {
- return
- }
-
- callback(1, 1)
- }
-
- @objc private func pageRangeAction() {
- self.safe_selectRadio(sender: self.pageRangeVC)
-
- guard let callback = self.itemClick else {
- return
- }
-
- callback(1, 2)
- }
-
- @objc private func prefixForOrigFileNameAction() {
- self.safe_selectCheck(sender: self.prefixForOrigFileNameVC)
-
- guard let callback = self.itemClick else {
- return
- }
- var value = false
- if let sender = self.prefixForOrigFileNameVC {
- value = sender.state == .Checked
- }
-
- callback(6, value)
- }
-
- @objc private func tagAction() {
- self.safe_selectCheck(sender: self.tagVC)
-
- guard let callback = self.itemClick else {
- return
- }
- var value = false
- if let sender = self.tagVC {
- value = sender.state == .Checked
- }
- callback(7, value)
- }
-
- @objc private func sepAction() {
- self.safe_selectCheck(sender: self.sepVC)
-
- guard let callback = self.itemClick else {
- return
- }
- var value = false
- if let sender = self.sepVC {
- value = sender.state == .Checked
- }
- callback(8, value)
- }
-
- public func setPageRangeString(_ string: String) {
- self.pageRangeComboVC?.stringValue = string
- self.pageRangeComboVC?.editable = true
-
- self.window?.makeFirstResponder(self.pageRangeComboVC?.textField)
- }
-
- public func updateName(_ name: String) {
- self.nameViewLabel.stringValue = name
- }
-
- func selectCheck(sender: KMDesignButton) {
- sender.state = sender.state == .Checked ? .Norm : .Checked
-
- if (sender.isEqual(to: self.tagVC)) {
- self.tTextField?.kmEnabled = sender.state == .Checked
- } else if (sender.isEqual(to: self.sepVC)) {
- self.sTextField?.kmEnabled = sender.state == .Checked
- }
- }
-
- // MARK: Private Methods
-
- private func selectRadio(sender: KMDesignButton) {
- for radioVC in [self.oneFileForOnePageVC, self.splitMuitiFileVC, self.pageRangeVC] {
- if (sender.isEqual(to: radioVC)) {
- radioVC?.state = .Checked
- } else {
- radioVC?.state = .Norm
- }
- }
-
- if let state = self.oneFileForOnePageVC?.state, state == .Checked {
- self.oneFileForOnePageStepperView?.kmEnabled = true
- } else {
- self.oneFileForOnePageStepperView?.kmEnabled = false
- }
-
- if let state = self.splitMuitiFileVC?.state, state == .Checked {
- self.splitMuitiFileStepperView?.kmEnabled = true
- } else {
- self.splitMuitiFileStepperView?.kmEnabled = false
- }
-
- if let state = self.pageRangeVC?.state, state == .Checked {
- self.pageRangeComboVC?.enabled = true
- self.pageRangeComboVC?.editable = true
- self.window?.makeFirstResponder(self.pageRangeComboVC?.textField)
- } else {
- self.pageRangeComboVC?.enabled = false
- self.pageRangeComboVC?.editable = false
- self.window?.makeFirstResponder(nil)
- }
- }
-
- private func safe_selectRadio(sender: KMDesignButton?) {
- if let _radioVC = sender {
- self.selectRadio(sender: _radioVC)
- }
- }
-
- private func safe_selectCheck(sender: KMDesignButton?) {
- if let _checkVC = sender {
- self.selectCheck(sender: _checkVC)
- }
- }
- }
- extension KMPageEditSplitSettingView: KMTextFieldDelegate {
- func km_controlTextDidChange(textField: AnyObject) {
- if (textField.isEqual(to: self.tTextField)) {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(9, self.tTextField!.stringValue as Any)
- } else if (textField.isEqual(to: self.sTextField)) {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(10, self.sTextField!.stringValue as Any)
- } else if (textField.isEqual(to: self.oneFileForOnePageStepperView)) {
- guard let callback = self.itemClick else {
- return
- }
-
- var value: Int = 0
- if let _value = self.oneFileForOnePageStepperView?.kmValue {
- value = Int(_value)
- }
- callback(2, value)
- } else if (textField.isEqual(to: self.splitMuitiFileStepperView)) {
- guard let callback = self.itemClick else {
- return
- }
-
- var value: Int = 0
- if let _value = self.splitMuitiFileStepperView?.kmValue {
- value = Int(_value)
- }
- callback(3, value)
- }
- }
- }
- extension KMPageEditSplitSettingView: KMSelectPopButtonDelegate {
- func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
- if (obj.isEqual(to: self.pageRangeComboVC)) {
- var index = self.pageRangeComboVC!.indexOfSelectedItem
- if (index < 0) {
- index = 0
- }
-
- if index == obj.numberOfItems-1 {
- self.pageRangeComboVC?.editable = true
- DispatchQueue.main.async {
- self.pageRangeComboVC?.stringValue = ""
- }
- self.window?.makeFirstResponder(self.pageRangeComboVC?.textField)
- } else {
- self.window?.makeFirstResponder(nil)
- self.pageRangeComboVC?.editable = false
- }
-
- guard let callback = self.itemClick else {
- return
- }
-
- callback(4, index)
- }
- }
-
- func km_controlTextDidChange(_ obj: KMDesignSelect) {
- if (obj.isEqual(to: self.pageRangeComboVC)) {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(5, self.pageRangeComboVC!.stringValue)
- }
- }
- }
|