123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //
- // KMConvertHtmlSettingView.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/10/29.
- //
- import Cocoa
- import KMComponentLibrary
- class KMConvertHtmlSettingView: KMConvertSettingView {
- @IBOutlet weak var box: NSBox!
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var pageBox: NSBox!
- @IBOutlet weak var ocrBox: NSBox!
- @IBOutlet weak var pageRangeBox: NSBox!
-
- var pageIndex = 0
-
- private lazy var pageSelect_: ComponentSelect = {
- let view = ComponentSelect()
-
- view.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: "")
- view.delegate = self
- return view
- }()
-
- static func html_createFromNib(in bundle: Bundle = Bundle.main) -> Self? {
- let nibName = "KMConvertHtmlSettingView"
- var topLevelArray: NSArray? = nil
- bundle.loadNibNamed(NSNib.Name(nibName), owner: nil, topLevelObjects: &topLevelArray)
- guard let results = topLevelArray else { return nil }
- let views = Array<Any>(results).filter { $0 is Self }
- return views.last as? Self
- }
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- override func initSubViews() {
- super.initSubViews()
-
- self.pageBox.contentView = self.pageSelect_
- var menuItemArr: [ComponentMenuitemProperty] = []
- let strings: [String] = [NSLocalizedString("Single Page", comment: ""), NSLocalizedString("Single Page with Outlines", comment: ""),
- NSLocalizedString("Multiple Pages", comment: ""), NSLocalizedString("Multiple Pages with Outlines", comment: "")]
- for string in strings {
- let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: string)
- menuItemArr.append(itemProperty)
- }
-
- pageSelect_.updateMenuItemsArr(menuItemArr)
-
- pageSelect_.selectItemAtIndex(0)
- pageSelect_.properties.text = NSLocalizedString("Single Page", comment: "")
- pageSelect_.properties.creatable = false
- pageSelect_.reloadData()
- }
-
- override func initDefaultVlaue() {
- super.initDefaultVlaue()
-
- self.titleLabel.stringValue = NSLocalizedString("Page Options", comment: "")
- self.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
-
- self.box.borderWidth = 0
- self.pageBox.borderWidth = 0
- self.ocrBox.borderWidth = 0
- self.pageRangeBox.borderWidth = 0
- }
-
- override func viewDidMoveToWindow() {
- super.viewDidMoveToWindow()
-
- if (ocrItemView == nil) {
- ocrItemView = KMConvertOCRSettingItemView.createFromNib()
- ocrBox.contentView = self.ocrItemView
-
- ocrItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
- updateViewColor()
- }
- self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
- if (self.pageRangeItemView == nil) {
- self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
- self.pageRangeBox.contentView = self.pageRangeItemView
-
- pageRangeItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
- }
- }
-
- override func updateViewColor() {
- super.updateViewColor()
-
- KMMainThreadExecute {
- self.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
- }
- }
- }
- extension KMConvertHtmlSettingView: ComponentSelectDelegate {
- func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
- guard let index = view?.indexOfSelect(), index >= 0 else {
- return
- }
-
- self.pageIndex = max(0, index)
- }
- }
|