WCCompWindowController.swift 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //
  2. // WCCompWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/8/22.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class WCCompWindowController: NSWindowController {
  10. @IBOutlet weak var tableView: NSTableView!
  11. @IBOutlet weak var rigntBox: NSBox!
  12. @IBOutlet weak var appjsonLabel: NSTextField!
  13. @IBOutlet weak var brandJsonLabel: NSTextField!
  14. @IBOutlet weak var resetButton: NSButton!
  15. var buttonVC: ButtonDemoVC = ButtonDemoVC()
  16. var dividerVC: DividerDemoVC = DividerDemoVC()
  17. var dropdownVC: DropdownDemoVC = DropdownDemoVC()
  18. var navigationVC: NavigationDemoVC = NavigationDemoVC()
  19. var tabbarVC: TabbarDemoVC = TabbarDemoVC()
  20. var sidebarVC: SidebarDemoVC = SidebarDemoVC()
  21. var inputVC: InputDemoVC = InputDemoVC()
  22. var inputNumberVC: InputNumberVC = InputNumberVC()
  23. var checkBoxVC: CheckBoxVC = CheckBoxVC()
  24. var sliderVC: SliderVC = SliderVC()
  25. var selectVC: SelectVC = SelectVC()
  26. var controllerVC: ControllerVC = ControllerVC()
  27. var progressVC: ProgressVC = ProgressVC()
  28. var segmentedVC: SegmentedVC = SegmentedVC()
  29. var tooltipVC: TooltipVC = TooltipVC()
  30. var tabsVC: TabsVC = TabsVC()
  31. var messageVC: MessageVC = MessageVC()
  32. var alertVC: AlertControllerVC = AlertControllerVC()
  33. var emptyVC: EmptyVC = EmptyVC()
  34. var notiVC: NotiVC = NotiVC()
  35. var cardVC: CardVC = CardVC()
  36. var paginationVC: PaginationVC = PaginationVC()
  37. var listVC: ListVC = ListVC()
  38. var modalVC: ModalVC = ModalVC()
  39. var treeVC: TreeVC = TreeVC()
  40. let tools = ["Button", "Divider", "Dropdown", "Navigation", "Input", "InputNumber", "CheckBox", "Radio", "Slider", "Select", "Controller", "Progress", "Segmented", "Tooltip", "Tabs", "Message", "Alert & Tag", "Empty", "notificationVC", "Card", "Pagination", "Sidebar", "List & FloatingToolbar", "Modal", "Tree"]
  41. override func windowDidLoad() {
  42. super.windowDidLoad()
  43. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  44. ComponentLibrary.shared.parserExcel(withPath: "")
  45. rigntBox.contentView = buttonVC.view
  46. self.reloadData()
  47. }
  48. func reloadData() {
  49. var isEnable = true
  50. if let appjsonURL = ComponentLibrary.shared.appJsonURL {
  51. let path = appjsonURL.path
  52. self.appjsonLabel.stringValue = path
  53. } else {
  54. self.appjsonLabel.stringValue = "-"
  55. isEnable = false
  56. }
  57. if let brandJsonURL = ComponentLibrary.shared.brandJsonURL {
  58. let path = brandJsonURL.path
  59. self.brandJsonLabel.stringValue = path
  60. } else {
  61. self.brandJsonLabel.stringValue = "-"
  62. isEnable = false
  63. }
  64. self.resetButton.isEnabled = isEnable
  65. }
  66. @IBAction func chooseAPPJson(_ sender: Any) {
  67. let openPanel = NSOpenPanel()
  68. openPanel.canChooseDirectories = true
  69. openPanel.canChooseFiles = true
  70. openPanel.allowsMultipleSelection = false;
  71. openPanel.allowedFileTypes = ["json"]
  72. openPanel.beginSheetModal(for: self.window!) { result in
  73. if result == .OK {
  74. let fileURL = openPanel.urls.first
  75. ComponentLibrary.shared.appJsonURL = fileURL
  76. }
  77. self.reloadData()
  78. }
  79. }
  80. @IBAction func changeBrandJson(_ sender: Any) {
  81. let openPanel = NSOpenPanel()
  82. openPanel.canChooseDirectories = true
  83. openPanel.canChooseFiles = true
  84. openPanel.allowsMultipleSelection = false;
  85. openPanel.allowedFileTypes = ["json"]
  86. openPanel.beginSheetModal(for: self.window!) { result in
  87. if result == .OK {
  88. let fileURL = openPanel.urls.first
  89. ComponentLibrary.shared.brandJsonURL = fileURL
  90. }
  91. self.reloadData()
  92. }
  93. }
  94. @IBAction func resetAction(_ sender: Any) {
  95. ComponentLibrary.shared.parserExcel(withPath: "")
  96. }
  97. }
  98. extension WCCompWindowController: NSTableViewDataSource, NSTableViewDelegate {
  99. // MARK: NSTableViewDelegate
  100. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  101. let cellIdentifier = NSUserInterfaceItemIdentifier("TableViewCell")
  102. guard let cell = tableView.makeView(withIdentifier: cellIdentifier, owner: self) as? NSTableCellView else {
  103. return nil
  104. }
  105. cell.textField?.stringValue = tools[row]
  106. return cell
  107. }
  108. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  109. return 50.0
  110. }
  111. func tableViewSelectionDidChange(_ notification: Notification) {
  112. let row = self.tableView.selectedRow
  113. if row == -1 { return }
  114. if tools[row] == "Button" {
  115. rigntBox.contentView = buttonVC.view
  116. } else if tools[row] == "Divider" {
  117. rigntBox.contentView = dividerVC.view
  118. } else if tools[row] == "Dropdown" {
  119. rigntBox.contentView = dropdownVC.view
  120. } else if tools[row] == "Navigation" {
  121. rigntBox.contentView = navigationVC.view
  122. } else if tools[row] == "Tabbar" {
  123. rigntBox.contentView = tabbarVC.view
  124. } else if tools[row] == "Sidebar" {
  125. rigntBox.contentView = sidebarVC.view
  126. } else if tools[row] == "Input" {
  127. rigntBox.contentView = inputVC.view
  128. } else if tools[row] == "InputNumber" {
  129. rigntBox.contentView = inputNumberVC.view
  130. } else if tools[row] == "CheckBox" {
  131. rigntBox.contentView = checkBoxVC.view
  132. checkBoxVC.typeBox.selectItem(at: 0)
  133. checkBoxVC.reloadData()
  134. } else if tools[row] == "Radio" {
  135. rigntBox.contentView = checkBoxVC.view
  136. checkBoxVC.typeBox.selectItem(at: 1)
  137. checkBoxVC.reloadData()
  138. } else if tools[row] == "Slider" {
  139. rigntBox.contentView = sliderVC.view
  140. } else if tools[row] == "Select" {
  141. rigntBox.contentView = selectVC.view
  142. } else if tools[row] == "Controller" {
  143. rigntBox.contentView = controllerVC.view
  144. } else if tools[row] == "Progress" {
  145. rigntBox.contentView = progressVC.view
  146. } else if tools[row] == "Segmented" {
  147. rigntBox.contentView = segmentedVC.view
  148. } else if tools[row] == "Tooltip" {
  149. rigntBox.contentView = tooltipVC.view
  150. } else if tools[row] == "Tabs" {
  151. rigntBox.contentView = tabsVC.view
  152. } else if tools[row] == "Message" {
  153. rigntBox.contentView = messageVC.view
  154. } else if tools[row] == "Alert & Tag" {
  155. rigntBox.contentView = alertVC.view
  156. } else if tools[row] == "Empty" {
  157. rigntBox.contentView = emptyVC.view
  158. } else if tools[row] == "notificationVC" {
  159. rigntBox.contentView = notiVC.view
  160. } else if tools[row] == "Card" {
  161. rigntBox.contentView = cardVC.view
  162. } else if tools[row] == "Pagination" {
  163. rigntBox.contentView = paginationVC.view
  164. } else if tools[row] == "List & FloatingToolbar" {
  165. rigntBox.contentView = listVC.view
  166. } else if tools[row] == "Modal" {
  167. rigntBox.contentView = modalVC.view
  168. } else if tools[row] == "Tree" {
  169. rigntBox.contentView = treeVC.view
  170. }
  171. }
  172. // MARK: NSTableViewDataSource
  173. func numberOfRows(in tableView: NSTableView) -> Int {
  174. return tools.count
  175. }
  176. }