KMRightSideController.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // KMRightSideController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/11/12.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMRightSideController: NSViewController {
  10. @IBOutlet var contendView: NSView!
  11. @IBOutlet var contendLeftDivider: ComponentDivider!
  12. @IBOutlet var headerBGView: NSView!
  13. @IBOutlet var titleLabel: NSTextField!
  14. @IBOutlet var infoContendView: NSView!
  15. @IBOutlet var emptyView: ComponentEmpty!
  16. var annotations: [CPDFAnnotation] {
  17. get {
  18. return self.pdfView?.activeAnnotations as? [CPDFAnnotation] ?? []
  19. }
  20. }
  21. var pdfView: CPDFListView?
  22. var viewManager: KMPDFViewManager?
  23. //Controller
  24. //Markup
  25. //Edit
  26. var edit_textController: KMEditPDFTextPropertyViewController?
  27. var edit_imageController: KMEditImageController?
  28. var edit_linkController: KMLinkViewController?
  29. //Form
  30. //Fill
  31. //
  32. var contentViewController: NSViewController?
  33. //MARK: - func
  34. override func viewDidLoad() {
  35. super.viewDidLoad()
  36. // Do view setup here.
  37. setupUI()
  38. setupContentController()
  39. }
  40. func setupUI() {
  41. contendView.wantsLayer = true
  42. contendView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor
  43. contendLeftDivider.properties = ComponentDividerProperty(type: .vertical)
  44. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  45. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold")
  46. emptyView.properties = ComponentEmptyProperty(emptyType: .noWatermark, text: KMLocalizedString("No identical attributes"), subText: "")
  47. }
  48. func updateTitleLabel() {
  49. if viewManager?.subToolMode == .Edit_text {
  50. titleLabel.stringValue = KMLocalizedString("Text")
  51. } else if viewManager?.subToolMode == .Edit_Image {
  52. titleLabel.stringValue = KMLocalizedString("Image")
  53. } else if viewManager?.subToolMode == .Edit_Link {
  54. titleLabel.stringValue = KMLocalizedString("Link")
  55. } else if viewManager?.subToolMode == .Edit_Crop {
  56. titleLabel.stringValue = KMLocalizedString("Crop")
  57. }
  58. }
  59. func setupContentController() {
  60. updateTitleLabel()
  61. contentViewController?.view.removeFromSuperview()
  62. contentViewController = nil
  63. if viewManager?.toolMode == .Edit {
  64. if pdfView?.km_EditingAreas().isEmpty == true {
  65. } else if pdfView?.km_editingImageAreas().isEmpty == true && pdfView?.km_editingTextAreas().isEmpty == false {
  66. //编辑文字
  67. if edit_textController == nil {
  68. edit_textController = KMEditPDFTextPropertyViewController.init()
  69. }
  70. edit_textController?.pdfView = self.pdfView
  71. contentViewController = edit_textController
  72. } else if pdfView?.km_editingImageAreas().isEmpty == false && pdfView?.km_editingTextAreas().isEmpty == true {
  73. //编辑图片
  74. if edit_imageController == nil {
  75. edit_imageController = KMEditImageController.init()
  76. }
  77. contentViewController = edit_imageController
  78. } else {
  79. //多选
  80. }
  81. if viewManager?.subToolMode == .Edit_Link {
  82. //链接
  83. if edit_linkController == nil {
  84. edit_linkController = KMLinkViewController.init()
  85. }
  86. edit_linkController?.pdfView = self.pdfView
  87. contentViewController = edit_linkController
  88. }
  89. }
  90. if let contendVC = contentViewController {
  91. contendVC.view.frame = infoContendView.bounds
  92. contendVC.view.autoresizingMask = [.width, .height]
  93. infoContendView.addSubview(contendVC.view)
  94. headerBGView.isHidden = false
  95. emptyView.isHidden = true
  96. } else {
  97. headerBGView.isHidden = true
  98. emptyView.isHidden = false
  99. }
  100. }
  101. func reloadData() {
  102. if viewManager?.toolMode == .Edit {
  103. //图片&文字
  104. if pdfView?.km_EditingAreas().isEmpty == true {
  105. } else if pdfView?.km_editingImageAreas().isEmpty == true && pdfView?.km_editingTextAreas().isEmpty == false {
  106. //编辑文字
  107. edit_textController?.pdfView = self.pdfView
  108. edit_textController?.reloadData()
  109. } else if pdfView?.km_editingImageAreas().isEmpty == false && pdfView?.km_editingTextAreas().isEmpty == true {
  110. //编辑图片
  111. edit_imageController?.pdfView = self.pdfView
  112. edit_imageController?.reloadData()
  113. } else {
  114. //多选
  115. }
  116. //Link
  117. if viewManager?.subToolMode == .Edit_Link && contentViewController is KMLinkViewController {
  118. if (contentViewController as! KMLinkViewController).pdfView != self.pdfView {
  119. (contentViewController as! KMLinkViewController).pdfView = self.pdfView
  120. }
  121. var linkAnnotations: [CPDFLinkAnnotation] = []
  122. for annotation in self.annotations {
  123. if annotation is CPDFLinkAnnotation {
  124. linkAnnotations.append(annotation as! CPDFLinkAnnotation)
  125. }
  126. }
  127. (contentViewController as! KMLinkViewController).annotations = linkAnnotations
  128. (contentViewController as! KMLinkViewController).reloadData()
  129. if linkAnnotations.count == 0 {
  130. (contentViewController as! KMLinkViewController).view.isHidden = true
  131. } else {
  132. (contentViewController as! KMLinkViewController).view.isHidden = false
  133. }
  134. }
  135. }
  136. }
  137. public func reloadDataWithPDFView(pdfView: CPDFListView) {
  138. self.pdfView = pdfView
  139. setupContentController()
  140. reloadData()
  141. }
  142. //重新刷新编辑中内容
  143. public func reloadEditingAreas() {
  144. if contentViewController is KMEditPDFTextPropertyViewController {
  145. (contentViewController as! KMEditPDFTextPropertyViewController).reloadData()
  146. } else if contentViewController is KMEditImageController {
  147. (contentViewController as! KMEditImageController).reloadData()
  148. }
  149. }
  150. }