SettingsDisplayView.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. var menuItemArr: [ComponentMenuitemProperty] = []
  130. for string in ["Adaptation Width", "Adapt to Page", "Actual Size", " ",
  131. "10%", "25%", "50%", "75%", "100%", "150%", "200%", "400%", "800%"] {
  132. var itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: KMLocalizedString(string, comment: ""))
  133. if string == " " {
  134. itemProperty = ComponentMenuitemProperty.divider()
  135. }
  136. menuItemArr.append(itemProperty)
  137. }
  138. zoomSelectView.updateMenuItemsArr(menuItemArr)
  139. zoomSelectView.delegate = self
  140. }
  141. }
  142. func setUpLeftSidePanel() {
  143. //Left Side Panel
  144. defaultOpenRadio.properties = ComponentCheckBoxProperty(size: .s,
  145. state: .normal,
  146. isDisabled: false,
  147. showhelp: false,
  148. text: "Default Open",
  149. checkboxType: .normal)
  150. defaultOpenRadioWidthConst.constant = defaultOpenRadio.properties.propertyInfo.viewWidth
  151. defaultOpenSelectView.properties = ComponentSelectProperties(size: .s,
  152. state: .normal,
  153. isDisabled: false,
  154. isError: false,
  155. leftIcon: false,
  156. placeholder: nil,
  157. errorText: nil,
  158. creatable: false,
  159. text: "Thumbnail")
  160. if true {
  161. var menuItemArr: [ComponentMenuitemProperty] = []
  162. let ThumbnailProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Thumbnail")
  163. menuItemArr.append(ThumbnailProperty)
  164. let OutlineProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Outline")
  165. menuItemArr.append(OutlineProperty)
  166. let BookmarkProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Bookmark")
  167. menuItemArr.append(BookmarkProperty)
  168. let AnnotationProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Annotation")
  169. menuItemArr.append(AnnotationProperty)
  170. defaultOpenSelectView.updateMenuItemsArr(menuItemArr)
  171. defaultOpenSelectView.delegate = self
  172. }
  173. remeberLastRadio.properties = ComponentCheckBoxProperty(size: .s,
  174. state: .normal,
  175. isDisabled: false,
  176. showhelp: false,
  177. text: "Same as the last open",
  178. checkboxType: .normal)
  179. remeberLastRadioWidthConst.constant = remeberLastRadio.properties.propertyInfo.viewWidth
  180. hideLeftSideRadio.properties = ComponentCheckBoxProperty(size: .s,
  181. state: .normal,
  182. isDisabled: false,
  183. showhelp: false,
  184. text: "Hide left side panel",
  185. checkboxType: .normal)
  186. hideLeftSideRadioWidthConst.constant = hideLeftSideRadio.properties.propertyInfo.viewWidth
  187. prioritizeOutlineCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  188. state: .normal,
  189. isDisabled: false,
  190. showhelp: false,
  191. text: "Prioritize open the outline list when outlines are available",
  192. checkboxType: .normal)
  193. prioritizeOutlineCheckboxWidthConst.constant = prioritizeOutlineCheckbox.properties.propertyInfo.viewWidth
  194. defaultOpenRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  195. remeberLastRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  196. hideLeftSideRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  197. prioritizeOutlineCheckbox.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  198. }
  199. func setUpPropertyPanel() {
  200. //Property Panel
  201. panelInteractionSelect.properties = ComponentSelectProperties(size: .s,
  202. state: .normal,
  203. isDisabled: false,
  204. isError: false,
  205. leftIcon: false,
  206. placeholder: nil,
  207. errorText: nil,
  208. creatable: false,
  209. text: "Automatic")
  210. if true {
  211. var menuItemArr: [ComponentMenuitemProperty] = []
  212. let AutomaticProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Automatic")
  213. menuItemArr.append(AutomaticProperty)
  214. let hideProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Hide Property Panel")
  215. menuItemArr.append(hideProperty)
  216. panelInteractionSelect.updateMenuItemsArr(menuItemArr)
  217. panelInteractionSelect.delegate = self
  218. }
  219. showQuickCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  220. state: .normal,
  221. isDisabled: false,
  222. showhelp: false,
  223. text: "Always show quick action bar",
  224. checkboxType: SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal)
  225. showQuickCheckbox.setTarget(self, action: #selector(propertyPanelAction(_:)))
  226. showQuickCheckboxWidthConst.constant = showQuickCheckbox.properties.propertyInfo.viewWidth
  227. }
  228. func setUpHighlight() {
  229. //Highlight
  230. highlightLinkCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  231. state: .normal,
  232. isDisabled: false,
  233. showhelp: false,
  234. text: "Highlight Link",
  235. checkboxType: SettingsManager.sharedInstance.highlightLink ? .selected : .normal)
  236. highlightLinkBoxWidthConst.constant = highlightLinkCheckbox.properties.propertyInfo.viewWidth
  237. highlightFormCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  238. state: .normal,
  239. isDisabled: false,
  240. showhelp: false,
  241. text: "Highlight Form Field",
  242. checkboxType: SettingsManager.sharedInstance.highlightFormField ? .selected : .normal)
  243. highglightFormboxWidthConst.constant = highlightFormCheckbox.properties.propertyInfo.viewWidth
  244. highlightLinkCheckbox.setTarget(self, action: #selector(highlightAction(_:)))
  245. highlightFormCheckbox.setTarget(self, action: #selector(highlightAction(_:)))
  246. }
  247. func reloadData() {
  248. //Default Layout and Zoom
  249. layoutSelectView.selectItemAtIndex(SettingsManager.sharedInstance.layoutType.rawValue)
  250. zoomSelectView.selectItemAtIndex(SettingsManager.sharedInstance.zoomType.rawValue)
  251. //Left Side Panel
  252. defaultOpenRadio.properties.checkboxType = .normal
  253. remeberLastRadio.properties.checkboxType = .normal
  254. hideLeftSideRadio.properties.checkboxType = .normal
  255. prioritizeOutlineCheckbox.properties.checkboxType = .normal
  256. defaultOpenSelectView.properties.isDisabled = true
  257. if SettingsManager.sharedInstance.leftPanelType == .defaultOpen {
  258. defaultOpenSelectView.properties.isDisabled = false
  259. defaultOpenRadio.properties.checkboxType = .selected
  260. } else if SettingsManager.sharedInstance.leftPanelType == .sameAsLastOpen {
  261. remeberLastRadio.properties.checkboxType = .selected
  262. } else if SettingsManager.sharedInstance.leftPanelType == .hideLeftSide {
  263. hideLeftSideRadio.properties.checkboxType = .selected
  264. } else if SettingsManager.sharedInstance.leftPanelType == .prioritizeOutline {
  265. prioritizeOutlineCheckbox.properties.checkboxType = .selected
  266. }
  267. defaultOpenRadio.reloadData()
  268. remeberLastRadio.reloadData()
  269. hideLeftSideRadio.reloadData()
  270. prioritizeOutlineCheckbox.reloadData()
  271. defaultOpenSelectView.selectItemAtIndex(SettingsManager.sharedInstance.defaultOpen.rawValue)
  272. defaultOpenSelectView.reloadData()
  273. //Property Panel
  274. panelInteractionSelect.selectItemAtIndex(SettingsManager.sharedInstance.panelOpenType.rawValue)
  275. panelInteractionSelect.reloadData()
  276. showQuickCheckbox.properties.checkboxType = SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal
  277. showQuickCheckbox.reloadData()
  278. //Highlight
  279. highlightLinkCheckbox.properties.checkboxType = SettingsManager.sharedInstance.highlightLink ? .selected : .normal
  280. highlightLinkCheckbox.reloadData()
  281. highlightFormCheckbox.properties.checkboxType = SettingsManager.sharedInstance.highlightFormField ? .selected : .normal
  282. highlightFormCheckbox.reloadData()
  283. }
  284. //MARK: - Action
  285. @objc func leftSidePanelAction(_ sender: NSView) {
  286. if sender == defaultOpenRadio {
  287. SettingsManager.sharedInstance.leftPanelType = .defaultOpen
  288. } else if sender == remeberLastRadio {
  289. SettingsManager.sharedInstance.leftPanelType = .sameAsLastOpen
  290. } else if sender == hideLeftSideRadio {
  291. SettingsManager.sharedInstance.leftPanelType = .hideLeftSide
  292. } else if sender == prioritizeOutlineCheckbox {
  293. SettingsManager.sharedInstance.leftPanelType = .prioritizeOutline
  294. }
  295. self.reloadData()
  296. }
  297. @objc func propertyPanelAction(_ sender: NSView) {
  298. if sender == showQuickCheckbox {
  299. SettingsManager.sharedInstance.showQuickActionBar = showQuickCheckbox.properties.checkboxType == .selected ? true : false
  300. }
  301. self.reloadData()
  302. }
  303. @objc func highlightAction(_ sender: NSView) {
  304. if sender == highlightLinkCheckbox {
  305. SettingsManager.sharedInstance.highlightLink = highlightLinkCheckbox.properties.checkboxType == .selected ? true : false
  306. } else if sender == highlightFormCheckbox {
  307. SettingsManager.sharedInstance.highlightFormField = highlightFormCheckbox.properties.checkboxType == .selected ? true : false
  308. }
  309. self.reloadData()
  310. }
  311. }
  312. extension SettingsDisplayView: ComponentSelectDelegate {
  313. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  314. if view == layoutSelectView {
  315. if layoutSelectView.indexOfSelect() >= 0 {
  316. SettingsManager.sharedInstance.layoutType = pageLayoutType(rawValue: layoutSelectView.indexOfSelect())!
  317. }
  318. } else if view == zoomSelectView {
  319. if zoomSelectView.indexOfSelect() >= 0 {
  320. SettingsManager.sharedInstance.zoomType = zoomInfoType(rawValue: zoomSelectView.indexOfSelect())!
  321. }
  322. } else if view == defaultOpenSelectView {
  323. if defaultOpenSelectView.indexOfSelect() >= 0 {
  324. SettingsManager.sharedInstance.defaultOpen = defaultOpenType(rawValue: defaultOpenSelectView.indexOfSelect())!
  325. }
  326. } else if view == panelInteractionSelect {
  327. if panelInteractionSelect.indexOfSelect() >= 0 {
  328. SettingsManager.sharedInstance.panelOpenType = panelOpenInteractionType(rawValue: panelInteractionSelect.indexOfSelect())!
  329. }
  330. }
  331. SettingsManager.sharedInstance.saveData()
  332. self.reloadData()
  333. }
  334. }