12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- //
- // KMBatesPrefixInfoView.swift
- // PDF Master
- //
- // Created by tangchao on 2022/12/28.
- //
- import Cocoa
- class KMBatesPrefixInfoView: KMHeaderFooterAdjectiveInfoBaseView {
- var preFixBox = NSView()
- var preFixTextField = NSTextField()
- var sufFixLabel = NSTextField(labelWithString: "")
- var sufFixBox = NSView()
- var sufFixTextField = NSTextField()
-
- override func initSubviews() {
- super.initSubviews()
-
- self.addSubview(self.preFixBox)
- self.addSubview(self.preFixTextField)
- self.addSubview(self.sufFixLabel)
- self.addSubview(self.sufFixBox)
- self.addSubview(self.sufFixTextField)
-
- self.titleLabel.stringValue = NSLocalizedString("Prefix:", comment: "")
- self.sufFixLabel.stringValue = NSLocalizedString("Suffix:", comment: "")
- for box in [self.preFixBox, self.sufFixBox] {
- box.wantsLayer = true
- box.layer?.borderWidth = 1
- box.layer?.borderColor = NSColor.black.cgColor
- }
-
- for textField in [self.preFixTextField, self.sufFixTextField] {
- textField.focusRingType = .none
- textField.backgroundColor = NSColor.clear
- textField.cell?.isBordered = false
- textField.delegate = self
- }
- }
-
- override func layout() {
- super.layout()
-
- let leftMargin: CGFloat = self.contentInset.left
- let contentWidth: CGFloat = NSWidth(self.bounds)-leftMargin-self.contentInset.right
-
- let boxH: CGFloat = 30
- let textFieldH: CGFloat = 20
-
- self.preFixBox.frame = NSMakeRect(leftMargin, self.titleLabel.frame.maxY+2, contentWidth, boxH)
- self.preFixTextField.frame = NSMakeRect(leftMargin+4, self.preFixBox.frame.minY+5, contentWidth, textFieldH)
-
- self.sufFixLabel.frame = NSMakeRect(leftMargin, self.preFixBox.frame.maxY+12, contentWidth, 18)
- self.sufFixBox.frame = NSMakeRect(leftMargin, self.sufFixLabel.frame.maxY+2, contentWidth, boxH)
- self.sufFixTextField.frame = NSMakeRect(leftMargin+4, self.sufFixBox.frame.minY+5, contentWidth, textFieldH)
- }
-
- override var model: KMHeaderFooterAdjectiveModel {
- get {
- return super.model
- }
- set {
- super.model = newValue
-
- let myModel: KMBatesModel = newValue as! KMBatesModel
- self.preFixTextField.stringValue = myModel.prefixString
- self.sufFixTextField.stringValue = myModel.suffixString
- }
- }
- }
- extension KMBatesPrefixInfoView: NSTextFieldDelegate {
- func controlTextDidChange(_ obj: Notification) {
- if (self.preFixTextField.isEqual(to:obj.object ) || self.sufFixTextField.isEqual(to: obj.object)) {
- guard let callback = self.itemClick else {
- return
- }
-
- var index: Int = 1
- var sender = self.preFixTextField
- if (self.sufFixTextField.isEqual(to: obj.object)) {
- index = 2
- sender = self.sufFixTextField
- }
-
- callback(index, sender.stringValue)
- }
- }
- }
|