SettingsDisplayView.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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 prioritizeOutlineRadio: ComponentRadio!
  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 var autoExpandPropertyPanelCheckbox: ComponentCheckBox!
  31. @IBOutlet weak var showQuickCheckbox: ComponentCheckBox!
  32. @IBOutlet weak var showQuickCheckboxWidthConst: NSLayoutConstraint!
  33. @IBOutlet var propertyPanelWidthConst: 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. let titleLabelColor: NSColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  65. let subtitleLabelColor: NSColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor")
  66. //获取字体
  67. let titleLabelFont: NSFont = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  68. let 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. highlightLabel.stringValue = KMLocalizedString("Highlight", comment: "")
  86. highlightLabel.textColor = titleLabelColor
  87. highlightLabel.font = titleLabelFont
  88. }
  89. func setUpLayoutAndZoom() {
  90. layoutSelectView.properties = ComponentSelectProperties(size: .s,
  91. state: .normal,
  92. isDisabled: false,
  93. isError: false,
  94. leftIcon: false,
  95. placeholder: nil,
  96. errorText: nil,
  97. creatable: false,
  98. text: KMLocalizedString("Single Page Continuous", comment: ""))
  99. if true {
  100. var menuItemArr: [ComponentMenuitemProperty] = []
  101. for string in ["Single Page", "Single Page Continuous", "Two Page", "Two Page Continuous",
  102. "Book Mode", "Book Mode Continuous"] {
  103. var itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  104. itemSelected: false,
  105. isDisabled: false,
  106. keyEquivalent: nil,
  107. text: KMLocalizedString(string, comment: ""))
  108. if string == " " {
  109. itemProperty = ComponentMenuitemProperty.divider()
  110. }
  111. menuItemArr.append(itemProperty)
  112. }
  113. layoutSelectView.updateMenuItemsArr(menuItemArr)
  114. layoutSelectView.delegate = self
  115. }
  116. zoomSelectView.properties = ComponentSelectProperties(size: .s,
  117. state: .normal,
  118. isDisabled: false,
  119. isError: false,
  120. leftIcon: false,
  121. placeholder: nil,
  122. errorText: nil,
  123. creatable: false,
  124. text: KMLocalizedString("Adaptation Width", comment: ""))
  125. if true {
  126. zoomSelectView.updateMenuItemsArr(KMPDFToolbarConfig.scaleZoomItems())
  127. zoomSelectView.delegate = self
  128. }
  129. }
  130. func setUpLeftSidePanel() {
  131. //Left Side Panel
  132. defaultOpenRadio.properties = ComponentCheckBoxProperty(size: .s,
  133. state: .normal,
  134. isDisabled: false,
  135. showhelp: false,
  136. text: "Default Open",
  137. checkboxType: .normal)
  138. defaultOpenRadioWidthConst.constant = defaultOpenRadio.properties.propertyInfo.viewWidth
  139. defaultOpenSelectView.properties = ComponentSelectProperties(size: .s,
  140. state: .normal,
  141. isDisabled: false,
  142. isError: false,
  143. leftIcon: false,
  144. placeholder: nil,
  145. errorText: nil,
  146. creatable: false,
  147. text: "Thumbnail")
  148. if true {
  149. var menuItemArr: [ComponentMenuitemProperty] = []
  150. let ThumbnailProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Thumbnail")
  151. menuItemArr.append(ThumbnailProperty)
  152. let OutlineProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Outline")
  153. menuItemArr.append(OutlineProperty)
  154. let BookmarkProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Bookmark")
  155. menuItemArr.append(BookmarkProperty)
  156. let AnnotationProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Annotation")
  157. menuItemArr.append(AnnotationProperty)
  158. defaultOpenSelectView.updateMenuItemsArr(menuItemArr)
  159. defaultOpenSelectView.delegate = self
  160. }
  161. remeberLastRadio.properties = ComponentCheckBoxProperty(size: .s,
  162. state: .normal,
  163. isDisabled: false,
  164. showhelp: false,
  165. text: "Same as the last open",
  166. checkboxType: .normal)
  167. remeberLastRadioWidthConst.constant = remeberLastRadio.properties.propertyInfo.viewWidth
  168. hideLeftSideRadio.properties = ComponentCheckBoxProperty(size: .s,
  169. state: .normal,
  170. isDisabled: false,
  171. showhelp: false,
  172. text: "Hide left side panel",
  173. checkboxType: .normal)
  174. hideLeftSideRadioWidthConst.constant = hideLeftSideRadio.properties.propertyInfo.viewWidth
  175. prioritizeOutlineRadio.properties = ComponentCheckBoxProperty(size: .s,
  176. state: .normal,
  177. isDisabled: false,
  178. showhelp: false,
  179. text: "Prioritize open the outline list when outlines are available",
  180. checkboxType: .normal)
  181. prioritizeOutlineCheckboxWidthConst.constant = prioritizeOutlineRadio.properties.propertyInfo.viewWidth
  182. defaultOpenRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  183. remeberLastRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  184. hideLeftSideRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  185. prioritizeOutlineRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
  186. }
  187. func setUpPropertyPanel() {
  188. //Property Panel
  189. autoExpandPropertyPanelCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  190. state: .normal,
  191. isDisabled: false,
  192. showhelp: false,
  193. text: "Automatically expand the properties panel",
  194. checkboxType: SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal)
  195. autoExpandPropertyPanelCheckbox.setTarget(self, action: #selector(propertyPanelAction(_:)))
  196. propertyPanelWidthConst.constant = autoExpandPropertyPanelCheckbox.properties.propertyInfo.viewWidth
  197. showQuickCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  198. state: .normal,
  199. isDisabled: false,
  200. showhelp: false,
  201. text: "Always show quick action bar",
  202. checkboxType: SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal)
  203. showQuickCheckbox.setTarget(self, action: #selector(propertyPanelAction(_:)))
  204. showQuickCheckboxWidthConst.constant = showQuickCheckbox.properties.propertyInfo.viewWidth
  205. }
  206. func setUpHighlight() {
  207. //Highlight
  208. highlightLinkCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  209. state: .normal,
  210. isDisabled: false,
  211. showhelp: false,
  212. text: "Highlight Link",
  213. checkboxType: SettingsManager.sharedInstance.highlightLink ? .selected : .normal)
  214. highlightLinkBoxWidthConst.constant = highlightLinkCheckbox.properties.propertyInfo.viewWidth
  215. highlightFormCheckbox.properties = ComponentCheckBoxProperty(size: .s,
  216. state: .normal,
  217. isDisabled: false,
  218. showhelp: false,
  219. text: "Highlight Form Field",
  220. checkboxType: SettingsManager.sharedInstance.highlightFormField ? .selected : .normal)
  221. highglightFormboxWidthConst.constant = highlightFormCheckbox.properties.propertyInfo.viewWidth
  222. highlightLinkCheckbox.setTarget(self, action: #selector(highlightAction(_:)))
  223. highlightFormCheckbox.setTarget(self, action: #selector(highlightAction(_:)))
  224. }
  225. func reloadData() {
  226. //Default Layout and Zoom
  227. layoutSelectView.selectItemAtIndex(SettingsManager.sharedInstance.layoutType.rawValue)
  228. zoomSelectView.selectItemAtIndex(SettingsManager.sharedInstance.zoomType.rawValue)
  229. //Left Side Panel
  230. defaultOpenRadio.properties.checkboxType = .normal
  231. remeberLastRadio.properties.checkboxType = .normal
  232. hideLeftSideRadio.properties.checkboxType = .normal
  233. prioritizeOutlineRadio.properties.checkboxType = .normal
  234. defaultOpenSelectView.properties.isDisabled = true
  235. if SettingsManager.sharedInstance.leftPanelType == .defaultOpen {
  236. defaultOpenSelectView.properties.isDisabled = false
  237. defaultOpenRadio.properties.checkboxType = .selected
  238. } else if SettingsManager.sharedInstance.leftPanelType == .sameAsLastOpen {
  239. remeberLastRadio.properties.checkboxType = .selected
  240. } else if SettingsManager.sharedInstance.leftPanelType == .hideLeftSide {
  241. hideLeftSideRadio.properties.checkboxType = .selected
  242. } else if SettingsManager.sharedInstance.leftPanelType == .prioritizeOutline {
  243. prioritizeOutlineRadio.properties.checkboxType = .selected
  244. }
  245. defaultOpenRadio.reloadData()
  246. remeberLastRadio.reloadData()
  247. hideLeftSideRadio.reloadData()
  248. prioritizeOutlineRadio.reloadData()
  249. defaultOpenSelectView.selectItemAtIndex(SettingsManager.sharedInstance.defaultOpen.rawValue)
  250. defaultOpenSelectView.reloadData()
  251. //Property Panel
  252. autoExpandPropertyPanelCheckbox.properties.checkboxType = SettingsManager.sharedInstance.autoExpandPropertyPanel ? .selected : .normal
  253. autoExpandPropertyPanelCheckbox.reloadData()
  254. showQuickCheckbox.properties.checkboxType = SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal
  255. showQuickCheckbox.reloadData()
  256. //Highlight
  257. highlightLinkCheckbox.properties.checkboxType = SettingsManager.sharedInstance.highlightLink ? .selected : .normal
  258. highlightLinkCheckbox.reloadData()
  259. highlightFormCheckbox.properties.checkboxType = SettingsManager.sharedInstance.highlightFormField ? .selected : .normal
  260. highlightFormCheckbox.reloadData()
  261. }
  262. //MARK: - Action
  263. @objc func leftSidePanelAction(_ sender: NSView) {
  264. if sender == defaultOpenRadio {
  265. SettingsManager.sharedInstance.leftPanelType = .defaultOpen
  266. } else if sender == remeberLastRadio {
  267. SettingsManager.sharedInstance.leftPanelType = .sameAsLastOpen
  268. } else if sender == hideLeftSideRadio {
  269. SettingsManager.sharedInstance.leftPanelType = .hideLeftSide
  270. } else if sender == prioritizeOutlineRadio {
  271. SettingsManager.sharedInstance.leftPanelType = .prioritizeOutline
  272. }
  273. self.reloadData()
  274. }
  275. @objc func propertyPanelAction(_ sender: NSView) {
  276. if sender == showQuickCheckbox {
  277. SettingsManager.sharedInstance.showQuickActionBar = showQuickCheckbox.properties.checkboxType == .selected ? true : false
  278. } else if sender == autoExpandPropertyPanelCheckbox {
  279. SettingsManager.sharedInstance.autoExpandPropertyPanel = autoExpandPropertyPanelCheckbox.properties.checkboxType == .selected ? true : false
  280. }
  281. self.reloadData()
  282. }
  283. @objc func highlightAction(_ sender: NSView) {
  284. if sender == highlightLinkCheckbox {
  285. SettingsManager.sharedInstance.highlightLink = highlightLinkCheckbox.properties.checkboxType == .selected ? true : false
  286. } else if sender == highlightFormCheckbox {
  287. SettingsManager.sharedInstance.highlightFormField = highlightFormCheckbox.properties.checkboxType == .selected ? true : false
  288. }
  289. self.reloadData()
  290. }
  291. }
  292. extension SettingsDisplayView: ComponentSelectDelegate {
  293. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  294. if view == layoutSelectView {
  295. if layoutSelectView.indexOfSelect() >= 0 {
  296. SettingsManager.sharedInstance.layoutType = pageLayoutType(rawValue: layoutSelectView.indexOfSelect())!
  297. }
  298. } else if view == zoomSelectView {
  299. if zoomSelectView.indexOfSelect() >= 0 {
  300. SettingsManager.sharedInstance.zoomType = zoomInfoType(rawValue: zoomSelectView.indexOfSelect())!
  301. }
  302. } else if view == defaultOpenSelectView {
  303. if defaultOpenSelectView.indexOfSelect() >= 0 {
  304. SettingsManager.sharedInstance.defaultOpen = defaultOpenType(rawValue: defaultOpenSelectView.indexOfSelect())!
  305. }
  306. }
  307. SettingsManager.sharedInstance.saveData()
  308. self.reloadData()
  309. }
  310. }