// // SidebarDemoVC.swift // KMComponentLibraryDemo // // Created by wanjun on 2024/8/2. // import Cocoa import KMComponentLibrary class SidebarDemoVC: NSViewController { @IBOutlet weak var searchItem: ComponentSideBarItem! @IBOutlet weak var thumbnailItem: ComponentSideBarItem! @IBOutlet weak var outlineItem: ComponentSideBarItem! @IBOutlet weak var bookmarkItem: ComponentSideBarItem! @IBOutlet weak var annotationItem: ComponentSideBarItem! @IBOutlet weak var pageTurnerView: ComponentSidebarPageTurner! @IBOutlet weak var firstPageBtn: NSButton! @IBOutlet weak var lastPageBtn: NSButton! @IBOutlet weak var previousBtn: NSButton! @IBOutlet weak var nextBtn: NSButton! let searchProperty: ComponentSideBarItemProperty = ComponentSideBarItemProperty(state: .normal, icon: ComponentLibrary.shared.image(forResource: "Sidebar_search")) let thumbnailProperty: ComponentSideBarItemProperty = ComponentSideBarItemProperty(state: .normal, icon: ComponentLibrary.shared.image(forResource: "Sidebar_thumbnails")) let outlineProperty: ComponentSideBarItemProperty = ComponentSideBarItemProperty(state: .normal, icon: ComponentLibrary.shared.image(forResource: "Sidebar_outline")) let bookmarkProperty: ComponentSideBarItemProperty = ComponentSideBarItemProperty(state: .normal, icon: ComponentLibrary.shared.image(forResource: "Sidebar_bookmark")) let annotationProperty: ComponentSideBarItemProperty = ComponentSideBarItemProperty(state: .normal, icon: ComponentLibrary.shared.image(forResource: "Sidebar_annotation")) var sideBarType: KMPDFSidebarType = .search override func viewDidLoad() { super.viewDidLoad() // Do view setup here. self.searchItem.properties = searchProperty self.thumbnailItem.properties = thumbnailProperty self.outlineItem.properties = outlineProperty self.bookmarkItem.properties = bookmarkProperty self.annotationItem.properties = annotationProperty self.searchItem.setTarget(self, action: #selector(sidebarItemClicked(_ :))) self.thumbnailItem.setTarget(self, action: #selector(sidebarItemClicked(_ :))) self.outlineItem.setTarget(self, action: #selector(sidebarItemClicked(_ :))) self.bookmarkItem.setTarget(self, action: #selector(sidebarItemClicked(_ :))) self.annotationItem.setTarget(self, action: #selector(sidebarItemClicked(_ :))) self.reloadData() self.reloadPageTurnerData() } func reloadData() { searchProperty.state = .normal thumbnailProperty.state = .normal outlineProperty.state = .normal bookmarkProperty.state = .normal annotationProperty.state = .normal if self.sideBarType == .search { searchProperty.state = .pressed } else if self.sideBarType == .thumbnail { thumbnailProperty.state = .pressed } else if self.sideBarType == .outline { outlineProperty.state = .pressed } else if self.sideBarType == .bookmark { bookmarkProperty.state = .pressed } else if self.sideBarType == .annotation { annotationProperty.state = .pressed } searchItem.reloadData() thumbnailItem.reloadData() outlineItem.reloadData() bookmarkItem.reloadData() annotationItem.reloadData() } func reloadPageTurnerData() { let turnerProperty: ComponentSidebarPageTurnerProperty = ComponentSidebarPageTurnerProperty(currentIndex: 1, totalCount: 200) turnerProperty.firstPage_show = self.firstPageBtn.state == .on turnerProperty.lastPage_show = self.lastPageBtn.state == .on turnerProperty.previous_show = self.previousBtn.state == .on turnerProperty.next_show = self.nextBtn.state == .on self.pageTurnerView.properties = turnerProperty } @objc func sidebarItemClicked(_ sender: ComponentSideBarItem) { if sender == self.searchItem { self.sideBarType = .search } else if sender == self.thumbnailItem { self.sideBarType = .thumbnail } else if sender == self.outlineItem { self.sideBarType = .outline } else if sender == self.bookmarkItem { self.sideBarType = .bookmark } else if sender == self.annotationItem { self.sideBarType = .annotation } self.reloadData() } @IBAction func clickAction(_ sender: Any) { self.reloadData() self.reloadPageTurnerData() } override func mouseDown(with event: NSEvent) { self.view.window?.makeFirstResponder(nil) } }