123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //
- // KMConvertPageRangeSettingItemView.swift
- // PDF Master
- //
- // Created by tangchao on 2022/12/6.
- //
- import Cocoa
- typealias KMConvertPageRangeSettingItemViewTextDidEndEditing = (_ textString: String) -> ()
- class KMConvertPageRangeSettingItemView: KMConvertBaseView {
-
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var pageSizeComboBox: NSComboBox!
- @IBOutlet weak var pageSizeBox: NSBox!
- @IBOutlet weak var pagesizeBoxHeight: NSLayoutConstraint!
-
- var pageSizeVC: KMDesignSelect?
- var pageRangeValue: String = ""
-
- var itemClick: KMCommonClickBlock?
- var textDidEndEditingCallback: KMConvertPageRangeSettingItemViewTextDidEndEditing?
-
- var isTextDidEndCallback: Bool = false
- var pageCount = 0
-
- override func initSubViews() {
- super.initSubViews()
-
- self.pageSizeVC = KMDesignSelect.init(withType: .Combox)
- self.pageSizeBox.contentView = self.pageSizeVC!.view
- self.pageSizeVC?.removeAllItems()
- self.pageSizeVC?.addItems(withObjectValues: [KMTools.pageRangeTypeString(pageRange: .all),
- KMTools.pageRangeTypeString(pageRange: .current),
- KMTools.pageRangeTypeString(pageRange: .odd),
- KMTools.pageRangeTypeString(pageRange: .even),
- KMTools.pageRangeTypeString(pageRange: .custom)])
- self.pageSizeVC?.selectItem(at: 0)
- self.pageSizeVC?.editable = false //默认属性,初始化可不设置
- self.pageSizeVC?.delete = self
- self.pageSizeVC?.placeholderString = NSLocalizedString("eg. 1,3-5,10", comment: "")
- self.pageSizeVC?.updateUI()
- }
-
- override func initDefaultVlaue() {
- super.initDefaultVlaue()
-
- self.pageSizeBox.fillColor = .clear
-
- self.titleLabel.stringValue = NSLocalizedString("Page Range", comment: "")
- self.titleLabel.textColor = NSColor.km_init(hex: "#616469")
- self.titleLabel.font = .SFProTextSemiboldFont(12)
- }
- }
- extension KMConvertPageRangeSettingItemView: KMSelectPopButtonDelegate {
- func km_controlTextDidChange(_ obj: KMDesignSelect) {
- if let vc = self.pageSizeVC {
- self.pageRangeValue = vc.stringValue
- }
- }
-
- func km_controlTextDidEndEditing(_ obj: KMDesignSelect) {
- guard let vc = self.pageSizeVC else {
- return
- }
-
- if (!self.isTextDidEndCallback) {
- return
- }
- if (vc.indexOfSelectedItem != (vc.numberOfItems-1)) {
- /// 其他item切换
- return
- }
- guard let callback = self.textDidEndEditingCallback else {
- return
- }
- callback(vc.stringValue)
- }
-
- func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
- guard let vc = self.pageSizeVC else {
- return
- }
- let index = vc.indexOfSelectedItem
- if index < 0 {
- return
- }
- if index == vc.numberOfItems-1 {
- self.pageSizeVC?.editable = true
- DispatchQueue.main.async {
- self.pageSizeVC?.stringValue = ""
- }
- self.window?.makeFirstResponder(self.pageSizeVC?.textField)
- } else {
- self.window?.makeFirstResponder(nil)
- self.pageSizeVC?.editable = false
- }
- guard let callback = self.itemClick else {
- return
- }
- callback(index)
- }
-
- func km_SelectPopoverWillShow(_ obj: KMDesignSelect) {
- if (self.pageCount <= 1) {
- self.pageSizeVC?.disItems = [KMTools.pageRangeTypeString(pageRange: .even)]
- } else {
- self.pageSizeVC?.disItems = []
- }
- }
- }
|