// // 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,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) } }