TestFileCellView.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // TeseCaseCell.swift
  3. // KdanAuto
  4. //
  5. // Created by 朱东勇 on 2022/11/21.
  6. //
  7. import Foundation
  8. import AppKit
  9. protocol TestFileCellViewDelegate : NSObjectProtocol {
  10. func fileCellNeedReplace(_ cell:TestFileCellView, fileName:String)
  11. }
  12. class TestFileCellView : NSTableCellView {
  13. @IBOutlet var _titleLbl : NSTextField!
  14. @IBOutlet var _sepLine : NSView!
  15. @IBOutlet var _replaceBtn : NSButton!
  16. var _title : String!
  17. var _isExpad: Bool!
  18. var _typeInfo : NSDictionary!
  19. weak public var _delegate : (TestFileCellViewDelegate)?
  20. class func shared() -> TestFileCellView? {
  21. var objects : NSArray!
  22. Bundle.main.loadNibNamed("TestFileCellView", owner: nil, topLevelObjects: &objects)
  23. for tView in objects {
  24. if let tv = tView as? TestFileCellView {
  25. return tv
  26. }
  27. }
  28. return nil
  29. }
  30. override func awakeFromNib() {
  31. _sepLine.wantsLayer = true;
  32. _sepLine.layer?.backgroundColor = NSColor.lightGray.cgColor
  33. }
  34. // Setter & Getter
  35. public func setTitle(_ title:String) {
  36. _title = title;
  37. _titleLbl.stringValue = _title ?? ""
  38. }
  39. public func title() -> String? {
  40. return _title
  41. }
  42. public func fileType() -> String? {
  43. return _title
  44. }
  45. public func setNeedReplaceBtn(_ needReplace:Bool) {
  46. _replaceBtn.isHidden = !needReplace
  47. }
  48. public func setTypeInfo(_ typeInfo:NSDictionary) {
  49. _typeInfo = typeInfo
  50. self.setTitle(_typeInfo["Type"] as! String)
  51. }
  52. public func typeInfo() -> NSDictionary? {
  53. return _typeInfo
  54. }
  55. @IBAction func replaceAction(_ sender:NSButton) {
  56. if _delegate != nil {
  57. _delegate?.fileCellNeedReplace(self, fileName: _title)
  58. }
  59. }
  60. }