// // TreeVC.swift // PDF Reader Pro Edition // // Created by Niehaoyu on 2024/9/25. // import Cocoa import KMComponentLibrary class TreeVC: NSViewController { @IBOutlet weak var treeItem: ComponentTreeItem! @IBOutlet weak var levelIndexBox: NSComboBox! @IBOutlet weak var collapseBtn: NSButton! @IBOutlet weak var showCollapseBtn: NSButton! @IBOutlet weak var disableBtn: NSButton! @IBOutlet weak var editableBtn: NSButton! @IBOutlet weak var iconBtn: NSButton! var settingsWC = SettingsWindowController.shared override func viewDidLoad() { super.viewDidLoad() // Do view setup here. self.levelIndexBox.selectItem(at: 0) treeItem.componentDelegate = self self.reloadData() } func reloadData() { let property = ComponentTreeItemProperty(levelIndex: self.levelIndexBox.indexOfSelectedItem + 1, state: .normal, collapse: collapseBtn.state == .on, icon: self.iconBtn.state == .on ? ComponentLibrary.shared.image(forResource: "test") : nil, placeholder: "", showCollapse: showCollapseBtn.state == .on, text: "Text", isDisable: disableBtn.state == .on, editable: editableBtn.state == .on) treeItem.properties = property } @IBAction func clickAction(_ sender: Any) { self.reloadData() } @IBAction func settingsButtonAction(_ sender: Any) { settingsWC.showWindow(nil) } } extension TreeVC: ComponentTreeItemDelegate { func componentTreeItemDidCollapseStateChanged(_ view: ComponentTreeItem) { self.collapseBtn.state = view.properties.collapse ? .on : .off } func componentTreeItemInfoDidChanged(_ view: ComponentTreeItem) { print(view.properties.text) } }