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