TreeVC.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // TreeVC.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2024/9/25.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class TreeVC: NSViewController {
  10. @IBOutlet weak var treeItem: ComponentTreeItem!
  11. @IBOutlet weak var levelIndexBox: NSComboBox!
  12. @IBOutlet weak var collapseBtn: NSButton!
  13. @IBOutlet weak var showCollapseBtn: NSButton!
  14. @IBOutlet weak var disableBtn: NSButton!
  15. @IBOutlet weak var editableBtn: NSButton!
  16. @IBOutlet weak var iconBtn: NSButton!
  17. var settingsWC = SettingsWindowController.shared
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. // Do view setup here.
  21. self.levelIndexBox.selectItem(at: 0)
  22. treeItem.componentDelegate = self
  23. self.reloadData()
  24. }
  25. func reloadData() {
  26. let property = ComponentTreeItemProperty(levelIndex: self.levelIndexBox.indexOfSelectedItem + 1,
  27. state: .normal,
  28. collapse: collapseBtn.state == .on,
  29. icon: self.iconBtn.state == .on ? ComponentLibrary.shared.image(forResource: "test") : nil,
  30. placeholder: "",
  31. showCollapse: showCollapseBtn.state == .on,
  32. text: "Text",
  33. isDisable: disableBtn.state == .on,
  34. editable: editableBtn.state == .on)
  35. treeItem.properties = property
  36. }
  37. @IBAction func clickAction(_ sender: Any) {
  38. self.reloadData()
  39. }
  40. @IBAction func settingsButtonAction(_ sender: Any) {
  41. settingsWC.showWindow(nil)
  42. }
  43. }
  44. extension TreeVC: ComponentTreeItemDelegate {
  45. func componentTreeItemDidCollapseStateChanged(_ view: ComponentTreeItem) {
  46. self.collapseBtn.state = view.properties.collapse ? .on : .off
  47. }
  48. func componentTreeItemInfoDidChanged(_ view: ComponentTreeItem) {
  49. print(view.properties.text)
  50. }
  51. }