//
// 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(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)
}
}