KMHomeViewController+UI.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //
  2. // KMHomeViewController+UI.swift
  3. // PDF Master
  4. //
  5. // Created by wanjun on 2022/10/13.
  6. //
  7. import Foundation
  8. extension KMHomeViewController {
  9. // MARK: Private Methods
  10. func productPromotionShow(_ pdfProSeries: NSArray, withOthers others: NSArray, isInitialize initialize: Bool) {
  11. // if pdfProSeries.count > 0 {
  12. // if (self.pdfProSeriesBoxHeightConstraint.constant == 0.0) || initialize {
  13. // var height = CGFloat(pdfProSeries.count) * 32.0
  14. // for name in pdfProSeries {
  15. // height -= 32.0
  16. //
  17. // let dict: Dictionary = self.productPromotionData[name] as! Dictionary<NSString, NSString>
  18. // let subBox = KMBox(frame: CGRect(origin: CGPoint(x: 0, y: height), size: CGSize(width: self.pdfProSeriesBox.frame.width, height: 32.0)))
  19. // subBox.boxType = .custom
  20. // subBox.borderWidth = 0.0
  21. // self.pdfProSeriesBox.contentView?.addSubview(subBox)
  22. // subBox.downCallback = {(downEntered, mouseBox, event) -> Void in
  23. // if downEntered {
  24. // self.productPromotionClickAction(dict["Name"]!)
  25. // }
  26. // }
  27. //
  28. // let subImageView = NSImageView(frame: NSZeroRect)
  29. // subImageView.image = NSImage(named: dict["Image"]! as NSImage.Name)
  30. // subBox.addSubview(subImageView)
  31. // subImageView.mas_makeConstraints { (make) in
  32. // make?.width.height().equalTo()(16)
  33. // make?.centerY.equalTo()(0)
  34. // make?.left.equalTo()(18)
  35. // }
  36. //
  37. // let subLabel = NSTextField(frame: NSZeroRect)
  38. // subLabel.isBezeled = false
  39. // subLabel.isEditable = false
  40. // subLabel.backgroundColor = .clear
  41. // let paragraphStyle = NSMutableParagraphStyle()
  42. // paragraphStyle.lineSpacing = 22.0
  43. // subLabel.attributedStringValue = NSAttributedString(string: dict["Name"]! as String, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  44. // subLabel.font = NSFont(name: "SFProText-Regular", size: 14)
  45. // subLabel.textColor = NSColor(hex: "#616469")
  46. // subLabel.sizeToFit()
  47. // subBox.addSubview(subLabel)
  48. // subLabel.mas_makeConstraints { (make) in
  49. // make?.left.equalTo()(subImageView.mas_right)?.offset()(10)
  50. // make?.centerY.equalTo()(0)
  51. // }
  52. // }
  53. //
  54. // pdfSeriesButtonVC.image = NSImage(named: "icon_btn_expand_lv2_down_false")!
  55. // self.pdfProSeriesBoxHeightConstraint.constant = CGFloat(pdfProSeries.count) * 32.0
  56. // }
  57. // } else {
  58. // pdfSeriesButtonVC.image = NSImage(named: "icon_btn_expand_lv2_right_false")!
  59. // self.pdfProSeriesBox.contentView = NSView.init()
  60. // self.pdfProSeriesBoxHeightConstraint.constant = 0.0
  61. // }
  62. //
  63. // if others.count > 0 {
  64. // if (self.othersBoxHeightConstraint.constant == 0.0) || initialize {
  65. // var height = CGFloat(others.count) * 32.0
  66. // for name in others {
  67. // height -= 32.0
  68. //
  69. // let dict: Dictionary = self.productPromotionData[name] as! Dictionary<NSString, NSString>
  70. // let subBox = KMBox(frame: CGRect(x: 0, y: height, width: self.othersBox.frame.width, height: 32.0))
  71. // subBox.boxType = .custom
  72. // subBox.borderWidth = 0.0
  73. // self.othersBox.contentView?.addSubview(subBox)
  74. // subBox.downCallback = {(downEntered, mouseBox, event) -> Void in
  75. // if downEntered {
  76. // self.productPromotionClickAction(dict["Name"]!)
  77. // }
  78. // }
  79. //
  80. // let subImageView = NSImageView(frame: NSZeroRect)
  81. // subImageView.image = NSImage(named: dict["Image"]! as NSImage.Name)
  82. // subImageView.imageScaling = .scaleProportionallyDown
  83. // subImageView.imageAlignment = .alignCenter
  84. // subImageView.sizeToFit()
  85. // subBox.addSubview(subImageView)
  86. // subImageView.mas_makeConstraints { (make) in
  87. // make?.width.height().equalTo()(16)
  88. // make?.centerY.equalTo()(0)
  89. // make?.left.equalTo()(18)
  90. // }
  91. //
  92. // let subLabel = NSTextField(frame: NSZeroRect)
  93. // subLabel.isBezeled = false
  94. // subLabel.isEditable = false
  95. // subLabel.backgroundColor = .clear
  96. // let paragraphStyle = NSMutableParagraphStyle()
  97. // paragraphStyle.lineSpacing = 22.0
  98. // subLabel.attributedStringValue = NSAttributedString(string: dict["Name"]! as String, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  99. // subLabel.font = NSFont(name: "SFProText-Regular", size: 14)
  100. // subLabel.textColor = NSColor(red: 0.38, green: 0.392, blue: 0.412, alpha: 1.0)
  101. // subLabel.sizeToFit()
  102. // subBox.addSubview(subLabel)
  103. // subLabel.mas_makeConstraints { (make) in
  104. // make?.left.equalTo()(subImageView.mas_right)?.offset()(10)
  105. // make?.centerY.equalTo()(0)
  106. // }
  107. // }
  108. //
  109. // self.pdfOthersButtonVC.image = NSImage(named: "icon_btn_expand_lv2_down_false")!
  110. // self.othersBoxHeightConstraint.constant = CGFloat(others.count) * 32.0
  111. // }
  112. // } else {
  113. // self.pdfOthersButtonVC.image = NSImage(named: "icon_btn_expand_lv2_right_false")!
  114. // self.othersBox.contentView = NSView.init()
  115. // self.othersBoxHeightConstraint.constant = 0.0
  116. // }
  117. //
  118. // pdfSeriesButtonVC.updateUI()
  119. // pdfOthersButtonVC.updateUI()
  120. }
  121. func refreshRightBoxUI(_ state: KMHomeToolState) {
  122. rightFullBox.isHidden = true
  123. rightTopBox.isHidden = true
  124. rightBottomBox.isHidden = true
  125. homeButtonVC.state = .Norm
  126. pdfToolsButtonVC.state = .Norm
  127. cloudDocumentsButtonVC.state = .Norm
  128. switch state {
  129. case .Home:
  130. rightTopBox.isHidden = false
  131. rightBottomBox.isHidden = false
  132. rightTopBox.contentView = fastToolViewController.view
  133. rightBottomBox.contentView = historyFileViewController.view
  134. rightFullBox.contentView = nil
  135. let isQuickToolsType:Bool = UserDefaults.standard.bool(forKey: "kHomeQucikToolsTypeKey")
  136. if isQuickToolsType {
  137. rightTopBoxHeightConstraint.constant = 230 + ScrollerViewWidget
  138. } else {
  139. rightTopBoxHeightConstraint.constant = 326 + ScrollerViewWidget
  140. }
  141. homeButtonVC.state = .Sel
  142. refreshUI()
  143. break
  144. case .PDFTools:
  145. rightFullBox.isHidden = false
  146. rightFullBox.contentView = pdfToolsViewController.view
  147. rightTopBox.contentView = nil
  148. rightBottomBox.contentView = nil
  149. pdfToolsButtonVC.state = .Sel
  150. refreshUI()
  151. break
  152. case .CloudDocuments:
  153. rightFullBox.isHidden = false
  154. rightFullBox.contentView = cloudDocumentsViewController.view
  155. rightTopBox.contentView = nil
  156. rightBottomBox.contentView = nil
  157. cloudDocumentsButtonVC.state = .Sel
  158. refreshUI()
  159. break
  160. default:
  161. break
  162. }
  163. }
  164. }
  165. // MARK: - NSSplitViewDelegate
  166. extension KMHomeViewController: NSSplitViewDelegate {
  167. func splitView(_ splitView: NSSplitView, constrainMinCoordinate proposedMinimumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
  168. return 270.0
  169. }
  170. func splitView(_ splitView: NSSplitView, constrainMaxCoordinate proposedMaximumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
  171. return 270.0
  172. }
  173. func splitView(_ splitView: NSSplitView, shouldAdjustSizeOfSubview view: NSView) -> Bool {
  174. return false
  175. }
  176. func splitViewDidResizeSubviews(_ notification: Notification) {
  177. let rect = self.homeSplitView.frame
  178. self.leftBox.setFrameSize(CGSize(width: 270, height: rect.size.height))
  179. self.rightBox.frame = CGRect(origin: CGPoint(x: 271.0, y: 0), size: CGSize(width: rect.width - 271.0, height: rect.height))
  180. refreshProductActiveSpacing()
  181. }
  182. func splitView(_ splitView: NSSplitView, constrainSplitPosition proposedPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
  183. return proposedPosition
  184. }
  185. func splitView(_ splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
  186. return false
  187. }
  188. func splitView(_ splitView: NSSplitView, shouldCollapseSubview subview: NSView, forDoubleClickOnDividerAt dividerIndex: Int) -> Bool {
  189. return false
  190. }
  191. func splitView(_ splitView: NSSplitView, shouldHideDividerAt dividerIndex: Int) -> Bool {
  192. return splitView.isEqual(to: self.homeSplitView)
  193. }
  194. func splitView(_ splitView: NSSplitView, effectiveRect proposedEffectiveRect: NSRect, forDrawnRect drawnRect: NSRect, ofDividerAt dividerIndex: Int) -> NSRect {
  195. return proposedEffectiveRect
  196. }
  197. func splitView(_ splitView: NSSplitView, additionalEffectiveRectOfDividerAt dividerIndex: Int) -> NSRect {
  198. return NSMakeRect(0, 0, 0, 0)
  199. }
  200. }
  201. // MARK: - KMHomeFastToolViewControllerDelegate
  202. extension KMHomeViewController: KMHomeFastToolViewControllerDelegate {
  203. func fastToolViewController(_ viewController: KMHomeFastToolViewController, foldChangeState: Bool) {
  204. if foldChangeState {
  205. rightTopBoxHeightConstraint.constant = 230.0 + ScrollerViewWidget
  206. } else {
  207. rightTopBoxHeightConstraint.constant = 326.0 + ScrollerViewWidget
  208. }
  209. }
  210. func fastToolDidSelectAllTools(_ viewController: KMHomeFastToolViewController) {
  211. fastToolDidSelectAllTools()
  212. }
  213. func fastToolViewController(_ viewController: KMHomeFastToolViewController, didSelectItemsAt indexPaths: [Int]) {
  214. for index in indexPaths {
  215. fastToolItemAction(DataNavigationViewButtonActionType(rawValue: index) ?? .Batch)
  216. }
  217. }
  218. }
  219. // MARK: - KMHomeHistoryFileViewControllerDelegate
  220. extension KMHomeViewController: KMHomeHistoryFileViewControllerDelegate {
  221. func historyFileViewController(_ viewController: KMHomeHistoryFileViewController, deleteDocuments indexPaths: [URL]) {
  222. historyFile(deleteDocuments: indexPaths)
  223. }
  224. func historyFileViewController(_ viewController: KMHomeHistoryFileViewController, didSelectItemsAt indexPaths: [URL]) {
  225. for url in indexPaths {
  226. openHistoryFilePath(url: url)
  227. }
  228. }
  229. }
  230. // MARK: - KMPDFToolsViewControllerDelegate
  231. extension KMHomeViewController: KMPDFToolsViewControllerDelegate {
  232. func pdfToolsViewController(_ viewController: KMPDFToolsViewController, didSelectItemsAt indexPaths: [Int]) {
  233. for index in indexPaths {
  234. fastToolItemAction(DataNavigationViewButtonActionType(rawValue: index) ?? .Batch)
  235. }
  236. }
  237. }
  238. // MARK: - KMHomeDragViewDelegate
  239. extension KMHomeViewController: KMHomeDragViewDelegate {
  240. func homeDragView(_ viewController: KMHomeDragView, filePath: URL) {
  241. if self.aiHomeState == .AITranslation {
  242. self.aiTranslation(withFilePath: filePath.path)
  243. } else {
  244. self.openFile(withFilePath: filePath)
  245. }
  246. }
  247. func homeDragView(_ viewController: KMHomeDragView, notSupport: Bool) {
  248. if notSupport {
  249. let alert = NSAlert()
  250. alert.alertStyle = .critical
  251. alert.messageText = NSLocalizedString("This file format is not supported. Please enter PDF, picture, or Office file", comment: "")
  252. alert.runModal()
  253. }
  254. }
  255. }