123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- //
- // KMHeaderFooterTableCellView.swift
- // PDF Reader Pro
- //
- // Created by liujiajie on 2023/11/7.
- //
- import Cocoa
- typealias HeaderFooterTableCellViewCallback = (_ type: KMBatchModifyTemplateType) -> ()
- class KMHeaderFooterTableCellView: NSTableCellView {
- var headerFooterTableCellViewCallback: HeaderFooterTableCellViewCallback?
- @IBOutlet var textFiled1: NSTextField!
- @IBOutlet var textFiled2: NSTextField!
- @IBOutlet var textFiled3: NSTextField!
- @IBOutlet var textFiled4: NSTextField!
- @IBOutlet var textFiled5: NSTextField!
- @IBOutlet var textFiled6: NSTextField!
- @IBOutlet var titleTextFiled: NSTextField!
- @IBOutlet var auxiliaryView: NSView!
- @IBOutlet var editButton: KMButton!
- @IBOutlet var deleteButtonl: KMButton!
-
- override func prepareForReuse() {
- super.prepareForReuse()
- self.textFiled1.stringValue = ""
- self.textFiled2.stringValue = ""
- self.textFiled3.stringValue = ""
- self.textFiled4.stringValue = ""
- self.textFiled5.stringValue = ""
- self.textFiled5.stringValue = ""
- self.titleTextFiled.stringValue = ""
- self.auxiliaryView.isHidden = true
- }
- override func awakeFromNib() {
- super.awakeFromNib()
- self.titleTextFiled.textColor = KMAppearance.Layout.h0Color()
- self.textFiled1.textColor = KMAppearance.Layout.h0Color()
- self.textFiled2.textColor = KMAppearance.Layout.h0Color()
- self.textFiled3.textColor = KMAppearance.Layout.h0Color()
- self.textFiled4.textColor = KMAppearance.Layout.h0Color()
- self.textFiled5.textColor = KMAppearance.Layout.h0Color()
- self.textFiled6.textColor = KMAppearance.Layout.h1Color()
-
- self.textFiled1.stringValue = ""
- self.textFiled2.stringValue = ""
- self.textFiled3.stringValue = ""
- self.textFiled4.stringValue = ""
- self.textFiled5.stringValue = ""
- self.textFiled6.stringValue = ""
- self.titleTextFiled.stringValue = ""
- self.auxiliaryView.isHidden = true
-
- self.wantsLayer = true
-
- self.editButton.mouseMoveCallback = {[weak self] mouseEntered in
- if mouseEntered {
- self?.editButton.image = NSImage(named: KMImageNameUXIconBtnEditHov)
- } else {
- self?.editButton.image = NSImage(named: KMImageNameUXIconBtnEditNor)
- }
- }
- self.deleteButtonl.mouseMoveCallback = {[weak self] mouseEntered in
- if mouseEntered {
- self?.deleteButtonl.image = NSImage(named: KMImageNameUXIconBtnCloseHov)
- } else {
- self?.deleteButtonl.image = NSImage(named: KMImageNameUXIconBtnCloseNor)
- }
- }
- self.newTrackingArea()
- }
- func newTrackingArea() {
- let trackingArea = NSTrackingArea(rect: self.bounds, options: [.mouseEnteredAndExited, .inVisibleRect, .activeAlways, .mouseMoved], owner: self, userInfo: nil)
- self.addTrackingArea(trackingArea)
- }
- func appendBaseString(_ string: String) -> String {
- var appendString = string
- return appendString
- }
- func updateInterface(_ obj: KMHeaderFooterObject) {
- var arr = NSMutableArray()
- if obj.topLeftString.count > 0 {
- arr.add(appendBaseString(NSLocalizedString("Left Header Text", comment: ""), withString: appendBaseString(obj.topLeftString)))
- }
- if obj.topCenterString.count > 0 {
- arr.add(appendBaseString(NSLocalizedString("Center Header Text", comment: ""), withString: appendBaseString(obj.topCenterString)))
- }
- if obj.topRightString.count > 0 {
- arr.add(appendBaseString(NSLocalizedString("Right Header Text", comment: ""), withString: appendBaseString(obj.topRightString)))
- }
- if obj.bottomLeftString.count > 0 {
- arr.add(appendBaseString(NSLocalizedString("Left Footer Text", comment: ""), withString: appendBaseString(obj.bottomLeftString)))
- }
- if obj.bottomCenterString.count > 0 {
- arr.add(appendBaseString(NSLocalizedString("Center Footer Text", comment: ""), withString: appendBaseString(obj.bottomCenterString)))
- }
- if obj.bottomRightString.count > 0 {
- arr.add(appendBaseString(NSLocalizedString("Right Footer Text", comment: ""), withString: appendBaseString(obj.bottomRightString)))
- }
- for i in 0..<arr.count {
- switch i {
- case 0:
- self.textFiled1.stringValue = arr[i] as! String
- case 1:
- self.textFiled2.stringValue = arr[i] as! String
- case 2:
- self.textFiled3.stringValue = arr[i] as! String
- case 3:
- self.textFiled4.stringValue = arr[i] as! String
- case 4:
- self.textFiled5.stringValue = arr[i] as! String
- case 5:
- self.textFiled6.stringValue = arr[i] as! String
- default:
- break
- }
- }
- // self.titleTextFiled.stringValue = obj.id
- }
- func appendBaseString(_ prefixString: String, withString suffixString: String) -> String {
- return "\(prefixString): \(suffixString)"
- }
- override func mouseEntered(with event: NSEvent) {
- super.mouseEntered(with: event)
- self.auxiliaryView.isHidden = false
- self.layer?.backgroundColor = KMAppearance.Status.selColor().cgColor
- }
- override func mouseExited(with event: NSEvent) {
- super.mouseExited(with: event)
- self.auxiliaryView.isHidden = true
-
- self.layer?.backgroundColor = NSColor.clear.cgColor
- }
- @IBAction func buttonClicked_Edit(_ sender: Any) {
- if let callback = self.headerFooterTableCellViewCallback {
- callback(.Edit)
- }
- }
- @IBAction func buttonClicked_Delete(_ sender: Any) {
- if let callback = self.headerFooterTableCellViewCallback {
- callback(.Delete)
- }
- }
- }
|