SettingsDisplayView.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. //
  2. // SettingsDisplayView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/9/26.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class SettingsDisplayView: BaseXibView {
  10. @IBOutlet weak var contendBox: NSBox!
  11. @IBOutlet weak var layoutZoomView: NSView!
  12. @IBOutlet weak var layoutZoomLabel: NSTextField!
  13. @IBOutlet weak var layoutLabel: NSTextField!
  14. @IBOutlet weak var layoutSelectView: ComponentSelect!
  15. @IBOutlet weak var zoomLabel: NSTextField!
  16. @IBOutlet weak var zoomSelectView: ComponentSelect!
  17. @IBOutlet weak var leftSideView: NSView!
  18. @IBOutlet weak var leftSideLabel: NSTextField!
  19. @IBOutlet weak var defaultOpenRadio: ComponentRadio!
  20. @IBOutlet weak var defaultOpenSelectView: ComponentSelect!
  21. @IBOutlet weak var remeberLastRadio: ComponentRadio!
  22. @IBOutlet weak var hideLeftSideRadio: ComponentRadio!
  23. @IBOutlet weak var prioritizeOutlineCheckbox: ComponentCheckBox!
  24. @IBOutlet weak var defaultOpenRadioWidthConst: NSLayoutConstraint!
  25. @IBOutlet weak var remeberLastRadioWidthConst: NSLayoutConstraint!
  26. @IBOutlet weak var hideLeftSideRadioWidthConst: NSLayoutConstraint!
  27. @IBOutlet weak var prioritizeOutlineCheckboxWidthConst: NSLayoutConstraint!
  28. @IBOutlet weak var propertyPanelView: NSView!
  29. @IBOutlet weak var propertyPanelLabel: NSTextField!
  30. @IBOutlet weak var panelInteractionLabel: NSTextField!
  31. @IBOutlet weak var panelInteractionSelect: ComponentSelect!
  32. @IBOutlet weak var showQuickCheckbox: ComponentCheckBox!
  33. @IBOutlet weak var showQuickCheckboxWidthConst: NSLayoutConstraint!
  34. @IBOutlet weak var highlightView: NSView!
  35. @IBOutlet weak var highlightLabel: NSTextField!
  36. @IBOutlet weak var highlightLinkCheckbox: ComponentCheckBox!
  37. @IBOutlet weak var highlightFormCheckbox: ComponentCheckBox!
  38. @IBOutlet weak var highlightLinkBoxWidthConst: NSLayoutConstraint!
  39. @IBOutlet weak var highglightFormboxWidthConst: NSLayoutConstraint!
  40. deinit {
  41. NotificationCenter.default.removeObserver(self)
  42. }
  43. override func draw(_ dirtyRect: NSRect) {
  44. super.draw(dirtyRect)
  45. // Drawing code here.
  46. self.setTitleUI()
  47. self.setUpLayoutAndZoom()
  48. self.setUpLeftSidePanel()
  49. self.setUpPropertyPanel()
  50. self.setUpHighlight()
  51. self.reloadData()
  52. }
  53. public required init?(coder decoder: NSCoder) {
  54. super.init(coder: decoder)
  55. }
  56. override init(frame frameRect: NSRect) {
  57. super.init(frame: frameRect)
  58. }
  59. public override func awakeFromNib() {
  60. super.awakeFromNib()
  61. }
  62. func setTitleUI () {
  63. //获取颜色
  64. var titleLabelColor: NSColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  65. var subtitleLabelColor: NSColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor")
  66. //获取字体
  67. var titleLabelFont: NSFont = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  68. var subtitleLabelFont: NSFont = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
  69. //Layout and Zoom
  70. layoutZoomLabel.stringValue = KMLocalizedString("Default Layout and Zoom")
  71. layoutZoomLabel.textColor = titleLabelColor
  72. layoutZoomLabel.font = titleLabelFont
  73. layoutLabel.stringValue = KMLocalizedString("Page Layout:", comment: "")
  74. layoutLabel.textColor = subtitleLabelColor
  75. layoutLabel.font = subtitleLabelFont
  76. zoomLabel.stringValue = KMLocalizedString("Zoom:", comment: "")
  77. zoomLabel.textColor = subtitleLabelColor
  78. zoomLabel.font = subtitleLabelFont
  79. leftSideLabel.stringValue = KMLocalizedString("Left Side Panel", comment: "")
  80. leftSideLabel.textColor = titleLabelColor
  81. leftSideLabel.font = titleLabelFont
  82. propertyPanelLabel.stringValue = KMLocalizedString("Property Panel", comment: "")
  83. propertyPanelLabel.textColor = titleLabelColor
  84. propertyPanelLabel.font = titleLabelFont
  85. panelInteractionLabel.stringValue = KMLocalizedString("Panel Open Interaction:", comment: "")
  86. panelInteractionLabel.textColor = subtitleLabelColor
  87. panelInteractionLabel.font = subtitleLabelFont
  88. highlightLabel.stringValue = KMLocalizedString("Highlight", comment: "")
  89. highlightLabel.textColor = titleLabelColor
  90. highlightLabel.font = titleLabelFont
  91. }
  92. func setUpLayoutAndZoom() {
  93. layoutSelectView.properties = ComponentSelectProperties(size: .s,
  94. state: .normal,
  95. isDisabled: false,
  96. isError: false,
  97. leftIcon: false,
  98. placeholder: nil,
  99. errorText: nil,
  100. creatable: false,
  101. text: KMLocalizedString("Single Page Continuous", comment: ""))
  102. if true {
  103. var menuItemArr: [ComponentMenuitemProperty] = []
  104. for string in ["Single Page", "Single Page Continuous", "Two Page", "Two Page Continuous",
  105. "Book Mode", "Book Mode Continuous"] {
  106. var itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  107. itemSelected: false,
  108. isDisabled: false,
  109. keyEquivalent: nil,
  110. text: KMLocalizedString(string, comment: ""))
  111. if string == " " {
  112. itemProperty = ComponentMenuitemProperty.divider()
  113. }
  114. menuItemArr.append(itemProperty)
  115. }
  116. layoutSelectView.updateMenuItemsArr(menuItemArr)
  117. layoutSelectView.delegate = self
  118. }
  119. zoomSelectView.properties = ComponentSelectProperties(size: .s,
  120. state: .normal,
  121. isDisabled: false,
  122. isError: false,
  123. leftIcon: false,
  124. placeholder: nil,
  125. errorText: nil,
  126. creatable: false,
  127. text: KMLocalizedString("Adaptation Width", comment: ""))
  128. if true {
  129. zoomSelectView.updateMenuItemsArr(KMPDFToolbarConfig.scaleZoomItems())
  130. zoomSelectView.delegate = self
  131. }
  132. }
  133. func setUpLeftSidePanel() {
  134. //Left Side Panel
  135. defaultOpenRadio.properties = ComponentCheckBoxProperty(size: .s,
  136. state: .normal,
  137. isDisabled: false,
  138. showhelp: false,
  139. text: "Default Open",
  140. checkboxType: .normal)
  141. defaultOpenRadioWidthConst.constant = defaultOpenRadio.properties.propertyInfo.viewWidth
  142. defaultOpenSelectView.properties = ComponentSelectProperties(size: .s,
  143. state: .normal,
  144. isDisabled: false,
  145. isError: false,
  146. leftIcon: false,
  147. placeholder: nil,
  148. errorText: nil,
  149. creatable: false,
  150. text: "Thumbnail")
  151. if true {
  152. var menuItemArr: [ComponentMenuitemProperty] = []
  153. let ThumbnailProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Thumbnail")
  154. menuItemArr.append(ThumbnailProperty)
  155. let OutlineProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Outline")
  156. menuItemArr.append(OutlineProperty)
  157. let BookmarkProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Bookmark")
  158. menuItemArr.append(BookmarkProperty)
  159. let AnnotationProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Annotation")
  160. menuItemArr.append(AnnotationProperty)
  161. defaultOpenSelectView.updateMenuItemsArr(menuItemArr)
  162. defaultOpenSelectView.delegate = self
  163. }
  164. remeberLastRadio.properties = ComponentCheckBoxProperty(size: .s,
  165. state: .normal,
  166. isDisabled: false,
  167. showhelp: false,
  168. text: "Same as the last open",
  169. checkboxType: .normal)
  170. remeberLastRadioWidthConst.constant = remeberLastRadio.properties.propertyInfo.viewWidth
  171. hideLeftSideRadio.properties = ComponentCheckBoxProperty(size: .s,
  172. state: .normal,
  173. isDisabled: false,
  174. showhelp: false,
  175. text: "Hide left side panel",
  176. checkboxType: .normal)
  177. hideLeftSideRadioWidthConst.constant = hideLeftSideRadio.properties.propertyInfo.viewWidth
  178. prioritizeOutlineCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  179. state: .normal,
  180. isDisabled: false,
  181. showhelp: false,
  182. text: "Prioritize open the outline list when outlines are available",
  183. checkboxType: .normal)
  184. prioritizeOutlineCheckboxWidthConst.constant = prioritizeOutlineCheckbox.properties.propertyInfo.viewWidth
  185. defaultOpenRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  186. remeberLastRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  187. hideLeftSideRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  188. prioritizeOutlineCheckbox.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  189. }
  190. func setUpPropertyPanel() {
  191. //Property Panel
  192. panelInteractionSelect.properties = ComponentSelectProperties(size: .s,
  193. state: .normal,
  194. isDisabled: false,
  195. isError: false,
  196. leftIcon: false,
  197. placeholder: nil,
  198. errorText: nil,
  199. creatable: false,
  200. text: "Automatic")
  201. if true {
  202. var menuItemArr: [ComponentMenuitemProperty] = []
  203. let AutomaticProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Automatic")
  204. menuItemArr.append(AutomaticProperty)
  205. let hideProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Hide Property Panel")
  206. menuItemArr.append(hideProperty)
  207. panelInteractionSelect.updateMenuItemsArr(menuItemArr)
  208. panelInteractionSelect.delegate = self
  209. }
  210. showQuickCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  211. state: .normal,
  212. isDisabled: false,
  213. showhelp: false,
  214. text: "Always show quick action bar",
  215. checkboxType: SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal)
  216. showQuickCheckbox.setTarget(self, action: #selector(propertyPanelAction(_:)))
  217. showQuickCheckboxWidthConst.constant = showQuickCheckbox.properties.propertyInfo.viewWidth
  218. }
  219. func setUpHighlight() {
  220. //Highlight
  221. highlightLinkCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  222. state: .normal,
  223. isDisabled: false,
  224. showhelp: false,
  225. text: "Highlight Link",
  226. checkboxType: SettingsManager.sharedInstance.highlightLink ? .selected : .normal)
  227. highlightLinkBoxWidthConst.constant = highlightLinkCheckbox.properties.propertyInfo.viewWidth
  228. highlightFormCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  229. state: .normal,
  230. isDisabled: false,
  231. showhelp: false,
  232. text: "Highlight Form Field",
  233. checkboxType: SettingsManager.sharedInstance.highlightFormField ? .selected : .normal)
  234. highglightFormboxWidthConst.constant = highlightFormCheckbox.properties.propertyInfo.viewWidth
  235. highlightLinkCheckbox.setTarget(self, action: #selector(highlightAction(_:)))
  236. highlightFormCheckbox.setTarget(self, action: #selector(highlightAction(_:)))
  237. }
  238. func reloadData() {
  239. //Default Layout and Zoom
  240. layoutSelectView.selectItemAtIndex(SettingsManager.sharedInstance.layoutType.rawValue)
  241. zoomSelectView.selectItemAtIndex(SettingsManager.sharedInstance.zoomType.rawValue)
  242. //Left Side Panel
  243. defaultOpenRadio.properties.checkboxType = .normal
  244. remeberLastRadio.properties.checkboxType = .normal
  245. hideLeftSideRadio.properties.checkboxType = .normal
  246. prioritizeOutlineCheckbox.properties.checkboxType = .normal
  247. defaultOpenSelectView.properties.isDisabled = true
  248. if SettingsManager.sharedInstance.leftPanelType == .defaultOpen {
  249. defaultOpenSelectView.properties.isDisabled = false
  250. defaultOpenRadio.properties.checkboxType = .selected
  251. } else if SettingsManager.sharedInstance.leftPanelType == .sameAsLastOpen {
  252. remeberLastRadio.properties.checkboxType = .selected
  253. } else if SettingsManager.sharedInstance.leftPanelType == .hideLeftSide {
  254. hideLeftSideRadio.properties.checkboxType = .selected
  255. } else if SettingsManager.sharedInstance.leftPanelType == .prioritizeOutline {
  256. prioritizeOutlineCheckbox.properties.checkboxType = .selected
  257. }
  258. defaultOpenRadio.reloadData()
  259. remeberLastRadio.reloadData()
  260. hideLeftSideRadio.reloadData()
  261. prioritizeOutlineCheckbox.reloadData()
  262. defaultOpenSelectView.selectItemAtIndex(SettingsManager.sharedInstance.defaultOpen.rawValue)
  263. defaultOpenSelectView.reloadData()
  264. //Property Panel
  265. panelInteractionSelect.selectItemAtIndex(SettingsManager.sharedInstance.panelOpenType.rawValue)
  266. panelInteractionSelect.reloadData()
  267. showQuickCheckbox.properties.checkboxType = SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal
  268. showQuickCheckbox.reloadData()
  269. //Highlight
  270. highlightLinkCheckbox.properties.checkboxType = SettingsManager.sharedInstance.highlightLink ? .selected : .normal
  271. highlightLinkCheckbox.reloadData()
  272. highlightFormCheckbox.properties.checkboxType = SettingsManager.sharedInstance.highlightFormField ? .selected : .normal
  273. highlightFormCheckbox.reloadData()
  274. }
  275. //MARK: - Action
  276. @objc func leftSidePanelAction(_ sender: NSView) {
  277. if sender == defaultOpenRadio {
  278. SettingsManager.sharedInstance.leftPanelType = .defaultOpen
  279. } else if sender == remeberLastRadio {
  280. SettingsManager.sharedInstance.leftPanelType = .sameAsLastOpen
  281. } else if sender == hideLeftSideRadio {
  282. SettingsManager.sharedInstance.leftPanelType = .hideLeftSide
  283. } else if sender == prioritizeOutlineCheckbox {
  284. SettingsManager.sharedInstance.leftPanelType = .prioritizeOutline
  285. }
  286. self.reloadData()
  287. }
  288. @objc func propertyPanelAction(_ sender: NSView) {
  289. if sender == showQuickCheckbox {
  290. SettingsManager.sharedInstance.showQuickActionBar = showQuickCheckbox.properties.checkboxType == .selected ? true : false
  291. }
  292. self.reloadData()
  293. }
  294. @objc func highlightAction(_ sender: NSView) {
  295. if sender == highlightLinkCheckbox {
  296. SettingsManager.sharedInstance.highlightLink = highlightLinkCheckbox.properties.checkboxType == .selected ? true : false
  297. } else if sender == highlightFormCheckbox {
  298. SettingsManager.sharedInstance.highlightFormField = highlightFormCheckbox.properties.checkboxType == .selected ? true : false
  299. }
  300. self.reloadData()
  301. }
  302. }
  303. extension SettingsDisplayView: ComponentSelectDelegate {
  304. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  305. if view == layoutSelectView {
  306. if layoutSelectView.indexOfSelect() >= 0 {
  307. SettingsManager.sharedInstance.layoutType = pageLayoutType(rawValue: layoutSelectView.indexOfSelect())!
  308. }
  309. } else if view == zoomSelectView {
  310. if zoomSelectView.indexOfSelect() >= 0 {
  311. SettingsManager.sharedInstance.zoomType = zoomInfoType(rawValue: zoomSelectView.indexOfSelect())!
  312. }
  313. } else if view == defaultOpenSelectView {
  314. if defaultOpenSelectView.indexOfSelect() >= 0 {
  315. SettingsManager.sharedInstance.defaultOpen = defaultOpenType(rawValue: defaultOpenSelectView.indexOfSelect())!
  316. }
  317. } else if view == panelInteractionSelect {
  318. if panelInteractionSelect.indexOfSelect() >= 0 {
  319. SettingsManager.sharedInstance.panelOpenType = panelOpenInteractionType(rawValue: panelInteractionSelect.indexOfSelect())!
  320. }
  321. }
  322. SettingsManager.sharedInstance.saveData()
  323. self.reloadData()
  324. }
  325. }