123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- //
- // KMNLeftSideViewController.swift
- // PDF Reader Pro
- //
- // Created by 丁林圭 on 2024/11/2.
- //
- import Cocoa
- import KMComponentLibrary
- @objc protocol KMNLeftSideViewControllerDelegate: AnyObject {
- @objc optional func enterPageEditLeftSideViewController(leftSideViewController:KMNLeftSideViewController)
-
- @objc optional func changeSelectePageLeftSideViewController(leftSideViewController:KMNLeftSideViewController,pageIndex:Int)
-
- @objc optional func addBookmarkForLeftC(controller: KMNLeftSideViewController, bookmark: CPDFBookmark?, info: [String : Any]?)
- @objc optional func switchSearchPopWindow(controller: KMNLeftSideViewController)
-
- }
- class KMNLeftSideViewController: KMNBaseViewController {
-
- weak open var leftSideViewDelegate: KMNLeftSideViewControllerDelegate?
- @IBOutlet var backContentBox: NSBox!
-
- @IBOutlet var headerBox: NSBox!
-
- @IBOutlet var bottomBox: NSBox!
-
- @IBOutlet weak var headerBoxHeightConst: NSLayoutConstraint!
-
- private var currentDocument:CPDFDocument?
-
- public var thumnailViewController:KMNThumnailViewController?
-
- private lazy var bookmarkViewC_: KMBookMarkViewController = {
- let controller = KMBookMarkViewController()
- controller.delegate = self
- return controller
- }()
-
- private lazy var outlineViewC_: KMOutlineViewController = {
- let contr = KMOutlineViewController(nibName: "KMOutlineViewController", bundle: nil)
- return contr
- }()
-
- private lazy var searchViewC_: KMBotaSearchViewController = {
- let con = KMBotaSearchViewController()
- con.delegate = self
- return con
- }()
-
- var outlineViewC: KMOutlineViewController {
- get {
- return outlineViewC_
- }
- }
-
- var bookmarkViewC: KMBookMarkViewController {
- get {
- return bookmarkViewC_
- }
- }
-
- var searchViewC: KMBotaSearchViewController {
- get {
- return searchViewC_
- }
- }
-
- lazy var thumbnailHeaderViewController: KMNThumnailHeaderViewController = {
- let controller = KMNThumnailHeaderViewController(nibName: "KMNThumnailHeaderViewController", bundle: nil)
- controller.view.frame = headerBox.bounds
- controller.view.autoresizingMask = [.width, .height] // Use flexible for better resizing
- return controller
- }()
-
- public var leftsideType:KMPDFSidebarType = .none {
- didSet {
- switch leftsideType {
- case .search:
- headerBoxHeightConst.constant = 0
- bottomBox.contentView = searchViewC_.view
- case .thumbnail:
- headerBoxHeightConst.constant = 40
- headerBox.contentView = thumbnailHeaderViewController.view
- bottomBox.contentView = thumnailViewController?.view
- case .bookmark:
- headerBoxHeightConst.constant = 0
- bottomBox.contentView = bookmarkViewC_.view
- bookmarkViewC_.document = currentDocument
- bookmarkViewC_.reloadData()
- case .outline:
- headerBoxHeightConst.constant = 0
- bottomBox.contentView = outlineViewC_.view
- case .annotation:
- headerBoxHeightConst.constant = 40
- bottomBox.contentView = nil
- default: break
- }
- }
- }
-
- public func changeDocument(document: CPDFDocument?) {
- currentDocument = document
- }
-
- public func changeLeftSideBounds() {
- thumnailViewController?.updateThumbnailSize()
- }
-
- init(_ document: CPDFDocument) {
- super.init(nibName: "KMNLeftSideViewController", bundle: nil)
-
- currentDocument = document
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- updateUIThemeColor()
-
- initThumnailView()
- }
-
- override func updateUIThemeColor() {
- super.updateUIThemeColor()
-
- headerBox.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider")
- headerBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
- bottomBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
- }
-
- private func initThumnailView() {
- thumnailViewController = KMNThumnailViewController.init(currentDocument)
- thumnailViewController?.view.frame = bottomBox.bounds
- thumnailViewController?.thumnailViewDelegate = self
- thumnailViewController?.thumbnailBaseViewDelegate = self
- thumnailViewController?.view.autoresizingMask = [.width, .height]
- }
-
- }
- extension KMNLeftSideViewController: KMNThumbnailBaseViewDelegate {
- func changeIndexPathsThumbnailViewControlle(pageEditVC:KMNThumbnailBaseViewController?,selectionIndexPaths: Set<IndexPath>,selectionStrings:String ) {
-
- if(selectionIndexPaths.count == 1) {
- leftSideViewDelegate?.changeSelectePageLeftSideViewController?(leftSideViewController: self, pageIndex: selectionIndexPaths.first?.item ?? 0)
- }
- }
- }
- extension KMNLeftSideViewController: KMNThumnailViewControllerDelegate {
- func enterPageEditThumnailViewController(thumnailViewController: KMNThumnailViewController) {
- leftSideViewDelegate?.enterPageEditLeftSideViewController?(leftSideViewController: self)
- }
- }
- extension KMNLeftSideViewController: KMBookMarkViewControllerDelegate {
- func bkControllerAddAction(controller: KMBookMarkViewController, bookmark: CPDFBookmark?, info: [String : Any]?) {
- leftSideViewDelegate?.addBookmarkForLeftC?(controller: self, bookmark: bookmark, info: info)
- }
- }
- extension KMNLeftSideViewController: KMBotaSearchViewControllerDelegate {
- func switchSearchPopWindow(controller: KMBotaSearchViewController) {
- leftSideViewDelegate?.switchSearchPopWindow?(controller: self)
- }
- }
|