KMRedactBaseWindowController.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // KMRedactBaseWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/1/17.
  6. //
  7. import Cocoa
  8. typealias KMRedactBaseWindowItemClick = (_ index: Int, _ value: Any?) -> ()
  9. class KMRedactBaseWindowController: NSWindowController {
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var topLine: NSBox!
  12. @IBOutlet weak var contentBox: NSBox!
  13. @IBOutlet weak var funcButton: NSButton!
  14. @IBOutlet weak var cancelButton: NSButton!
  15. @IBOutlet weak var contentWidthConst: NSLayoutConstraint!
  16. @IBOutlet weak var contentHeightConst: NSLayoutConstraint!
  17. var contentView: KMRedactContentBaseView!
  18. var pageCount: Int = 0
  19. var annotation: CPDFRedactAnnotation?
  20. // class func init(_ annotation: CPDFRedactAnnotation?) {
  21. // self.init(windowNibName: "KMRedactBaseWindowController")
  22. // self.annotation = annotation
  23. // }
  24. // func initWithWindowNibName
  25. var itemClick: KMRedactBaseWindowItemClick!
  26. override func windowDidLoad() {
  27. super.windowDidLoad()
  28. cancelButton.title = NSLocalizedString("Cancel", comment: "")
  29. cancelButton.isBordered = false
  30. cancelButton.wantsLayer = true
  31. cancelButton.layer?.borderWidth = 1
  32. cancelButton.layer?.borderColor = NSColor.black.cgColor
  33. cancelButton.layer?.cornerRadius = 4
  34. cancelButton.target = self
  35. cancelButton.action = #selector(cancelButtonAction)
  36. funcButton.isBordered = false
  37. funcButton.wantsLayer = true
  38. funcButton.layer?.cornerRadius = 4
  39. funcButton.target = self
  40. funcButton.action = #selector(funcButtonAction)
  41. }
  42. // MARK: Private Methods
  43. @objc private func cancelButtonAction() {
  44. guard let callback = self.itemClick else {
  45. return
  46. }
  47. callback(1, nil)
  48. }
  49. @objc private func funcButtonAction() {
  50. guard let callback = self.itemClick else {
  51. return
  52. }
  53. callback(2, nil)
  54. }
  55. // Mark: Publick Methods
  56. public func setContentSize(_ size: NSSize) {
  57. self.contentWidthConst.constant = size.width
  58. self.contentHeightConst.constant = size.height - 44 - 60
  59. }
  60. public func topLineIsShow(_ show: Bool) {
  61. self.topLine.isHidden = !show
  62. }
  63. }