KMNLeftSideViewController.swift 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // KMNLeftSideViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by 丁林圭 on 2024/11/2.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. @objc protocol KMNLeftSideViewControllerDelegate: AnyObject {
  10. @objc optional func enterPageEditLeftSideViewController(leftSideViewController:KMNLeftSideViewController)
  11. @objc optional func changeSelectePageLeftSideViewController(leftSideViewController:KMNLeftSideViewController,pageIndex:Int)
  12. @objc optional func addBookmarkForLeftC(controller: KMNLeftSideViewController, bookmark: CPDFBookmark?, info: [String : Any]?)
  13. @objc optional func switchSearchPopWindow(controller: KMNLeftSideViewController)
  14. }
  15. class KMNLeftSideViewController: KMNBaseViewController {
  16. weak open var leftSideViewDelegate: KMNLeftSideViewControllerDelegate?
  17. @IBOutlet var backContentBox: NSBox!
  18. @IBOutlet var headerBox: NSBox!
  19. @IBOutlet var bottomBox: NSBox!
  20. @IBOutlet weak var headerBoxHeightConst: NSLayoutConstraint!
  21. private var currentDocument:CPDFDocument?
  22. public var thumnailViewController:KMNThumnailViewController?
  23. private lazy var bookmarkViewC_: KMBookMarkViewController = {
  24. let controller = KMBookMarkViewController()
  25. controller.delegate = self
  26. return controller
  27. }()
  28. private lazy var outlineViewC_: KMOutlineViewController = {
  29. let contr = KMOutlineViewController(nibName: "KMOutlineViewController", bundle: nil)
  30. return contr
  31. }()
  32. private lazy var searchViewC_: KMBotaSearchViewController = {
  33. let con = KMBotaSearchViewController()
  34. con.delegate = self
  35. return con
  36. }()
  37. var outlineViewC: KMOutlineViewController {
  38. get {
  39. return outlineViewC_
  40. }
  41. }
  42. var bookmarkViewC: KMBookMarkViewController {
  43. get {
  44. return bookmarkViewC_
  45. }
  46. }
  47. var searchViewC: KMBotaSearchViewController {
  48. get {
  49. return searchViewC_
  50. }
  51. }
  52. lazy var thumbnailHeaderViewController: KMNThumnailHeaderViewController = {
  53. let controller = KMNThumnailHeaderViewController(nibName: "KMNThumnailHeaderViewController", bundle: nil)
  54. controller.view.frame = headerBox.bounds
  55. controller.view.autoresizingMask = [.width, .height] // Use flexible for better resizing
  56. return controller
  57. }()
  58. public var leftsideType:KMPDFSidebarType = .none {
  59. didSet {
  60. switch leftsideType {
  61. case .search:
  62. headerBoxHeightConst.constant = 0
  63. bottomBox.contentView = searchViewC_.view
  64. case .thumbnail:
  65. headerBoxHeightConst.constant = 40
  66. headerBox.contentView = thumbnailHeaderViewController.view
  67. bottomBox.contentView = thumnailViewController?.view
  68. case .bookmark:
  69. headerBoxHeightConst.constant = 0
  70. bottomBox.contentView = bookmarkViewC_.view
  71. bookmarkViewC_.document = currentDocument
  72. bookmarkViewC_.reloadData()
  73. case .outline:
  74. headerBoxHeightConst.constant = 0
  75. bottomBox.contentView = outlineViewC_.view
  76. case .annotation:
  77. headerBoxHeightConst.constant = 40
  78. bottomBox.contentView = nil
  79. default: break
  80. }
  81. }
  82. }
  83. public func changeDocument(document: CPDFDocument?) {
  84. currentDocument = document
  85. }
  86. public func changeLeftSideBounds() {
  87. thumnailViewController?.updateThumbnailSize()
  88. }
  89. init(_ document: CPDFDocument) {
  90. super.init(nibName: "KMNLeftSideViewController", bundle: nil)
  91. currentDocument = document
  92. }
  93. required init?(coder: NSCoder) {
  94. fatalError("init(coder:) has not been implemented")
  95. }
  96. override func viewDidLoad() {
  97. super.viewDidLoad()
  98. updateUIThemeColor()
  99. initThumnailView()
  100. }
  101. override func updateUIThemeColor() {
  102. super.updateUIThemeColor()
  103. headerBox.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider")
  104. headerBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
  105. bottomBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
  106. }
  107. private func initThumnailView() {
  108. thumnailViewController = KMNThumnailViewController.init(currentDocument)
  109. thumnailViewController?.view.frame = bottomBox.bounds
  110. thumnailViewController?.thumnailViewDelegate = self
  111. thumnailViewController?.thumbnailBaseViewDelegate = self
  112. thumnailViewController?.view.autoresizingMask = [.width, .height]
  113. }
  114. }
  115. extension KMNLeftSideViewController: KMNThumbnailBaseViewDelegate {
  116. func changeIndexPathsThumbnailViewControlle(pageEditVC:KMNThumbnailBaseViewController?,selectionIndexPaths: Set<IndexPath>,selectionStrings:String ) {
  117. if(selectionIndexPaths.count == 1) {
  118. leftSideViewDelegate?.changeSelectePageLeftSideViewController?(leftSideViewController: self, pageIndex: selectionIndexPaths.first?.item ?? 0)
  119. }
  120. }
  121. }
  122. extension KMNLeftSideViewController: KMNThumnailViewControllerDelegate {
  123. func enterPageEditThumnailViewController(thumnailViewController: KMNThumnailViewController) {
  124. leftSideViewDelegate?.enterPageEditLeftSideViewController?(leftSideViewController: self)
  125. }
  126. }
  127. extension KMNLeftSideViewController: KMBookMarkViewControllerDelegate {
  128. func bkControllerAddAction(controller: KMBookMarkViewController, bookmark: CPDFBookmark?, info: [String : Any]?) {
  129. leftSideViewDelegate?.addBookmarkForLeftC?(controller: self, bookmark: bookmark, info: info)
  130. }
  131. }
  132. extension KMNLeftSideViewController: KMBotaSearchViewControllerDelegate {
  133. func switchSearchPopWindow(controller: KMBotaSearchViewController) {
  134. leftSideViewDelegate?.switchSearchPopWindow?(controller: self)
  135. }
  136. }