KMToolbarConfigViewController.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. //
  2. // KMToolbarConfigViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/5/23.
  6. //
  7. import Cocoa
  8. class KMToolbarConfigViewController: NSViewController {
  9. @IBOutlet weak var collectionView: NSCollectionView!
  10. private let cellIdentifier_ = NSUserInterfaceItemIdentifier(rawValue: "ToolbarConfigCellIdentifier")
  11. var model = KMToolbarConfigModel()
  12. deinit {
  13. Swift.debugPrint("KMToolbarConfigViewController deinit.")
  14. }
  15. convenience init() {
  16. self.init(nibName: "KMToolbarConfigViewController", bundle: nil)
  17. }
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. self.view.wantsLayer = true
  21. self.view.layer?.backgroundColor = NSColor.red.cgColor
  22. self.initDefalutValue()
  23. }
  24. func initDefalutValue() {
  25. self.collectionView.delegate = self
  26. self.collectionView.dataSource = self
  27. // let layout = NSCollectionViewFlowLayout()
  28. // layout.sectionInset = NSEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
  29. // layout.minimumInteritemSpacing = 20
  30. // layout.minimumLineSpacing = 30
  31. // layout.itemSize = NSSize(width: 60, height: 44)
  32. // self.collectionView.collectionViewLayout = layout
  33. self.collectionView.register(KMToolbarConfigViewItem.self, forItemWithIdentifier: self.cellIdentifier_)
  34. }
  35. private func _setupMainItem(_ item: KMToolbarItemView?) {
  36. let identifier = item?.itemIdentifier
  37. if identifier == KMLeftControlToolbarItemIdentifier {
  38. item?.image = NSImage(named: "KMImageNameUXIconBtnTriLeftNor")
  39. item?.titleName = NSLocalizedString("Panel", comment: "")
  40. item?.target = self
  41. item?.toolTip = NSLocalizedString("View Settings", comment: "")
  42. item?.boxImagePosition = .imageAbove
  43. item?.selectBackgroundType = .imageBox
  44. } else if identifier == KMDocumentZoomToolbarItemIdentifier {
  45. item?.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor")
  46. item?.titleName = NSLocalizedString("", comment: "")
  47. item?.target = self
  48. item?.btnTag = 1
  49. item?.toolTip = NSLocalizedString("Zoom In", comment: "")
  50. item?.boxImagePosition = .imageAbove
  51. } else if identifier == KMDocumentZoomOutToolbarItemIdentifier {
  52. item?.image = NSImage(named: "KMImageNameUXIconToolbarZoomoutNor")
  53. item?.titleName = NSLocalizedString("", comment: "")
  54. item?.target = self
  55. item?.btnTag = 0
  56. item?.toolTip = NSLocalizedString("Zoom Out", comment: "")
  57. item?.boxImagePosition = .imageAbove
  58. } else if identifier == KMDocumentZoomViewToolbarItemIdentifier{
  59. item?.titleName = NSLocalizedString("Zoom", comment: "")
  60. item?.target = self
  61. let view = KMToolbarZoomItemView(zoomView: nil)
  62. item?.customizeView = view
  63. } else if identifier == KMDocumentNextPageToolbarItemIdentifier {
  64. item?.image = NSImage(named: "KMImageNameToolbarPagenextNor")
  65. item?.titleName = NSLocalizedString("Next", comment: "")
  66. item?.target = self
  67. item?.toolTip = NSLocalizedString("Go To Next Page", comment: "")
  68. item?.boxImagePosition = .imageAbove
  69. } else if identifier == KMDocumentPreviousPageToolbarItemIdentifier {
  70. item?.titleName = NSLocalizedString("Zoom", comment: "")
  71. item?.target = self
  72. let view = KMToolbarPreviousNextItemView()
  73. item?.customizeView = view
  74. } else if identifier == KMDocumentHomeToolbarItemIdentifier {
  75. item?.image = NSImage(named: "KMImageNameToolbarHomeNor")
  76. item?.titleName = NSLocalizedString("Home", comment: "")
  77. item?.target = self
  78. item?.toolTip = NSLocalizedString("A Welcome Gift from Us", comment: "")
  79. item?.boxImagePosition = .imageAbove
  80. item?.selectBackgroundType = .imageBox
  81. } else if identifier == KMDocumentAnnotationToolbarItemIdentifier {
  82. item?.titleName = NSLocalizedString("Tools", comment: "")
  83. item?.image = NSImage(named: "KMImageNameUXIconToolbarMytoolsNor")
  84. item?.target = self
  85. item?.toolTip = String(format: "%@: %@, %@, %@, %@", KMLocalizedString("Tool Mode", nil),KMLocalizedString("Annotate", nil),KMLocalizedString("Scroll", nil),KMLocalizedString("Magnify", nil),KMLocalizedString("Select", nil))
  86. item?.btnTag = KMToolbarViewType.Annatiton.rawValue
  87. item?.boxImagePosition = .imageAbove
  88. item?.selectBackgroundType = .imageBox
  89. } else if identifier == KMDocumentPageToolbarItemIdentifier {
  90. item?.titleName = NSLocalizedString("Page Edit", comment: "")
  91. item?.target = self
  92. item?.image = NSImage(named: "KMImageNameUXIconToolbarPageeditNor")
  93. item?.toolTip = NSLocalizedString("PDF page editor: insert, delete, extract, rotate, reposition, and replace pages in a PDF", comment: "")
  94. item?.btnTag = KMToolbarViewType.Page.rawValue
  95. item?.boxImagePosition = .imageAbove
  96. item?.selectBackgroundType = .imageBox
  97. } else if identifier == KMDocumentConversonToolbarItemIdentifier {
  98. item?.titleName = NSLocalizedString("Converter", comment: "")
  99. item?.target = self
  100. item?.image = NSImage(named: "KMImageNameUXIconToolbarConvertNor")
  101. item?.toolTip = NSLocalizedString("Convert PDFs to Microsoft Word, PowerPoint, Excel, RTF, Text, Image, CSV, and more Offline", comment: "")
  102. item?.btnTag = KMToolbarViewType.Conversion.rawValue
  103. item?.boxImagePosition = .imageAbove
  104. item?.selectBackgroundType = .imageBox
  105. item?.promptIdentifier = identifier
  106. } else if identifier == KMDocumentScanOCRToolbarItemIdentifier {
  107. item?.titleName = NSLocalizedString("OCR", comment: "")
  108. item?.target = self
  109. item?.image = NSImage(named: "KMImageNameToolbarOCRNor")
  110. item?.boxImagePosition = .imageAbove
  111. item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
  112. item?.selectBackgroundType = .imageBox
  113. item?.promptIdentifier = identifier
  114. } else if identifier == KMToolbarToolEnhancedScanIdentifier {
  115. item?.image = NSImage(named: "KMImageNameMainToolEnhancedScan")
  116. item?.target = self
  117. item?.btnTag = 0
  118. item?.toolTip = NSLocalizedString("Enhanced Scan", comment: "")
  119. item?.titleName = NSLocalizedString("Enhanced Scan", comment: "")
  120. item?.boxImagePosition = .imageLeft
  121. item?.selectBackgroundType = .imageBox
  122. } else if identifier == KMToolbarToolOCRTextIdentifier {
  123. item?.image = NSImage(named: "KMImageNameMainToolOCRText")
  124. item?.target = self
  125. item?.toolTip = NSLocalizedString("OCR Text Recognition", comment: "")
  126. item?.titleName = NSLocalizedString("OCR Text Recognition", comment: "")
  127. item?.boxImagePosition = .imageLeft
  128. item?.selectBackgroundType = .imageBox
  129. item?.promptIdentifier = identifier
  130. } else if identifier == KMDocumentEditToolbarItemIdentifier {
  131. item?.titleName = NSLocalizedString("Edit PDF", comment: "")
  132. item?.target = self
  133. item?.image = NSImage(named: "KMImageNameUXIconToolbarEditNor")
  134. item?.boxImagePosition = .imageAbove
  135. item?.btnTag = KMToolbarViewType.editPDF.rawValue
  136. item?.toolTip = NSLocalizedString("Edit text and image in PDF ", comment: "")
  137. item?.selectBackgroundType = .imageBox
  138. item?.promptIdentifier = identifier
  139. } else if identifier == KMDocumentFormToolbarItemIdentifier {
  140. item?.titleName = NSLocalizedString("Forms", comment: "")
  141. item?.target = self
  142. item?.image = NSImage(named: "KMImageNameUXIconToolbarFormNor")
  143. item?.boxImagePosition = .imageAbove
  144. item?.btnTag = KMToolbarViewType.Form.rawValue
  145. item?.toolTip = NSLocalizedString("Edit PDF Form", comment: "")
  146. item?.selectBackgroundType = .imageBox
  147. item?.promptIdentifier = identifier
  148. }
  149. else if identifier == KMDocumentFillSginToolbarItemIdentifier {
  150. item?.titleName = NSLocalizedString("Fill & Sign", comment: "")
  151. item?.target = self
  152. item?.image = NSImage(named: "KMImageNameUXIconToolbarFillsignNor")
  153. item?.boxImagePosition = .imageAbove
  154. item?.btnTag = KMToolbarViewType.FillSign.rawValue
  155. item?.toolTip = NSLocalizedString("Fill and sign forms", comment: "")
  156. item?.selectBackgroundType = .imageBox
  157. item?.promptIdentifier = identifier
  158. } else if identifier == KMDocumentToolToolbarItemIdentifier {
  159. item?.titleName = NSLocalizedString("Editor", comment: "")
  160. item?.target = self
  161. item?.image = NSImage(named: "KMImageNameUXIconToolbarEdittoolNor")
  162. item?.boxImagePosition = .imageAbove
  163. item?.btnTag = KMToolbarViewType.Tool.rawValue
  164. item?.toolTip = NSLocalizedString("Edit, delete, cut, copy, paste, and insert text in PDFs", comment: "")
  165. item?.selectBackgroundType = .imageBox
  166. item?.promptIdentifier = identifier
  167. } else if identifier == KMDocumentRedactToolbarItemIdentifier {
  168. item?.titleName = NSLocalizedString("Redact Text", comment: "")
  169. item?.target = self
  170. item?.image = NSImage(named: "KMImageNameUXIconToolbarRedactNor")
  171. item?.boxImagePosition = .imageAbove
  172. item?.toolTip = NSLocalizedString("Mark for redaction", comment: "")
  173. item?.selectBackgroundType = .imageBox
  174. item?.promptIdentifier = identifier
  175. } else if identifier == KMDocumentAITranslationToolbarItemIdentifier {
  176. item?.image = NSImage(named: "ic_function_other_AITranslation")
  177. item?.titleName = "AI Translation"
  178. item?.target = self
  179. item?.toolTip = NSLocalizedString("AI Translation", comment: "")
  180. item?.boxImagePosition = .imageOnly
  181. item?.promptIdentifier = identifier
  182. } else if identifier == KMDocumentPrintToolbarItemIdentifier {
  183. item?.image = NSImage(named: "KMImageNameMainToolbarPrint")
  184. item?.titleName = "Print"
  185. item?.target = self
  186. item?.toolTip = NSLocalizedString("Print", comment: "")
  187. item?.boxImagePosition = .imageOnly
  188. } else if identifier == KMDocumentViewDisplayToolbarItemIdentifier {
  189. item?.image = NSImage(named: "KMImageNameUXIconToolbarPageviewNor")
  190. item?.titleName = NSLocalizedString("Page Display", comment: "")
  191. item?.target = self
  192. item?.toolTip = NSLocalizedString("Page Display", comment: "")
  193. item?.boxImagePosition = .imageAbove
  194. item?.selectBackgroundType = .imageBox
  195. item?.promptIdentifier = identifier
  196. } else if identifier == KMDocumentAIToolsToolbarItemIdentifier {
  197. item?.image = NSImage(named: "KMImageNameUXIconAINor")
  198. item?.titleName = NSLocalizedString("AI Tools", comment: "")
  199. item?.target = self
  200. item?.toolTip = NSLocalizedString("AI Tools", comment: "")
  201. item?.boxImagePosition = .imageAbove
  202. item?.selectBackgroundType = .imageBox
  203. item?.promptIdentifier = identifier
  204. } else if identifier == KMDocumentShareToolbarItemIdentifier {
  205. item?.image = NSImage(named: "KMImageNameUXIconToolbarShareNor")
  206. item?.titleName = NSLocalizedString("Share", comment: "")
  207. item?.target = self
  208. // item?.toolTip = NSLocalizedString("Share the file with others", comment: "")
  209. item?.boxImagePosition = .imageAbove
  210. item?.selectBackgroundType = .imageBox
  211. } else if identifier == KMDocumentSearchToolbarItemIdentifier {
  212. item?.titleName = NSLocalizedString("Search", comment: "")
  213. item?.target = self
  214. let view = NSView()
  215. view.frame = NSMakeRect(0, 0, 150, 40)
  216. let boxView = NSView()
  217. boxView.frame = NSMakeRect(0, 16, 150, 22)
  218. view.addSubview(boxView)
  219. let searchView = NSSearchField()
  220. searchView.frame = NSMakeRect(0, 0, 150, 22)
  221. searchView.placeholderString = NSLocalizedString("Search", comment: "")
  222. searchView.sendsWholeSearchString = true
  223. searchView.sendsSearchStringImmediately = true
  224. searchView.drawsBackground = false
  225. // searchView.delegate = self
  226. // self.searchField = searchView
  227. // self.refreshSearchBarMenu()
  228. boxView.addSubview(searchView)
  229. let titleLabel = NSTextField(labelWithString: NSLocalizedString("Search", comment: ""))
  230. view.addSubview(titleLabel)
  231. titleLabel.frame = NSMakeRect(0, 0, 130, 14)
  232. titleLabel.alignment = .center
  233. titleLabel.textColor = KMAppearance.subtitleColor()
  234. titleLabel.font = KMToolbarMainItemView.textFont
  235. item?.customizeView = view
  236. } else if identifier == KMRightControlToolbarItemIdentifier {
  237. item?.image = NSImage(named: "KMImageNameUXIconBtnTriRightNor")
  238. item?.titleName = NSLocalizedString("Properties", comment: "")
  239. item?.target = self
  240. item?.toolTip = NSLocalizedString("Show/Hide Annotation Properties Panel", comment: "")
  241. item?.boxImagePosition = .imageAbove
  242. item?.selectBackgroundType = .imageBox
  243. } else if identifier == KMToolbarToolRedactItemIdentifier {
  244. item?.image = NSImage(named: "KMImageNameMainToolsRedact")
  245. item?.target = self
  246. item?.btnTag = KMToolbarType.redact.rawValue
  247. item?.toolTip = NSLocalizedString("Redact", comment: "")
  248. item?.titleName = NSLocalizedString("Redact", comment: "")
  249. item?.selectBackgroundType = .imageBox
  250. item?.promptIdentifier = identifier
  251. } else if identifier == KMDocumentDigitalSignToolbarItemIdentifier {
  252. item?.image = NSImage(named: "DigitalSign_icon")
  253. item?.target = self
  254. item?.toolTip = NSLocalizedString("Digital signature ensures the authenticity and integrity of digital files. Click and drag the cursor to create a signature field on the page.", comment: "")
  255. item?.titleName = NSLocalizedString("Digital Sign", comment: "")
  256. item?.selectBackgroundType = .imageBox
  257. item?.boxImagePosition = .imageAbove
  258. item?.promptIdentifier = identifier
  259. }
  260. }
  261. }
  262. extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout {
  263. func numberOfSections(in collectionView: NSCollectionView) -> Int {
  264. return 1
  265. }
  266. func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
  267. return self.model.cellIdentifiers?.count ?? 0
  268. }
  269. func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
  270. let cell = collectionView.makeItem(withIdentifier: self.cellIdentifier_, for: indexPath) as! KMToolbarConfigViewItem
  271. let itemId = self.model.cellIdentifiers?[indexPath.item] ?? ""
  272. let item = KMToolbarItemView(itemIdentifier: itemId)
  273. self._setupMainItem(item)
  274. cell.itemView = item
  275. return cell
  276. }
  277. // Layout
  278. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
  279. let itemId = self.model.cellIdentifiers?[indexPath.item] ?? ""
  280. let item = KMToolbarItemView(itemIdentifier: itemId)
  281. self._setupMainItem(item)
  282. return NSSize(width: item.itemWidth, height: 48)
  283. }
  284. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  285. return 100
  286. }
  287. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  288. return 20
  289. }
  290. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
  291. return .init(top: 10, left: 20, bottom: 5, right: 40)
  292. }
  293. }