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