12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //
- // KMHeaderFooterDateInfoView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2022/12/27.
- //
- import Cocoa
- class KMHeaderFooterDateInfoView: KMHeaderFooterAdjectiveInfoBaseView {
- var comboBox = NSComboBox()
-
- override func initSubviews() {
- super.initSubviews()
-
- self.addSubview(self.comboBox)
-
- self.titleLabel.stringValue = NSLocalizedString("Date:", comment: "")
-
- self.comboBox.addItems(withObjectValues: KMWatermarkAdjectiveTools.getDateFormats())
- self.comboBox.isEditable = false
- self.comboBox.delegate = self
- }
-
- override func layout() {
- super.layout()
-
- self.comboBox.frame = NSMakeRect(self.contentInset.left, self.titleLabel.frame.maxY+10, NSWidth(self.bounds)-self.contentInset.left-self.contentInset.right, 22)
- }
-
- override var model: KMHeaderFooterAdjectiveModel {
- get {
- return super.model
- }
- set {
- super.model = newValue
-
- let myModel: KMHeaderFooterObject = newValue as! KMHeaderFooterObject
- if (myModel.dateFormatString.isEmpty) {
- self.comboBox.stringValue = KMWatermarkAdjectiveTools.getDateFormats().first!
- } else {
- self.comboBox.stringValue = myModel.dateFormatString
- }
- }
- }
- }
- extension KMHeaderFooterDateInfoView: NSComboBoxDelegate {
- func comboBoxSelectionDidChange(_ notification: Notification) {
- if (self.comboBox.isEqual(to: notification.object)) {
- guard let callback = self.itemClick else {
- return
- }
-
- var index: Int = self.comboBox.indexOfSelectedItem
- if (index < 0) {
- index = 0
- }
-
- callback(1, KMWatermarkAdjectiveTools.getDateFormats()[index])
- }
- }
- }
|