KMToolbarConfigModel.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. //
  2. // KMToolbarConfigModel.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/5/28.
  6. //
  7. import Cocoa
  8. class KMToolbarConfigModel: NSObject {
  9. var leftCellIdentifiers: [String]? {
  10. didSet {
  11. let ids = self.leftCellIdentifiers ?? []
  12. self.leftWidth = 0
  13. if ids.isEmpty == false {
  14. self.leftWidth += self.leftMargin + 5
  15. }
  16. for itemId in ids {
  17. let item = KMToolbarItemView(itemIdentifier: itemId)
  18. self.setupMainItem(item)
  19. self.leftWidth += (item.itemWidth + 5)
  20. }
  21. }
  22. }
  23. var leftCount: Int {
  24. get {
  25. return self.leftCellIdentifiers?.count ?? 0
  26. }
  27. }
  28. var centerCellIdentifiers: [String]? {
  29. didSet {
  30. let ids = self.centerCellIdentifiers ?? []
  31. self.centerWidth = 0
  32. for itemId in ids {
  33. let item = KMToolbarItemView(itemIdentifier: itemId)
  34. self.setupMainItem(item)
  35. self.centerWidth += (item.itemWidth + 5)
  36. }
  37. }
  38. }
  39. var centerCount: Int {
  40. get {
  41. return self.centerCellIdentifiers?.count ?? 0
  42. }
  43. }
  44. var rightCellIdentifiers: [String]? {
  45. didSet {
  46. let ids = self.rightCellIdentifiers ?? []
  47. self.rightWidth = 0
  48. if ids.isEmpty == false {
  49. self.rightWidth += self.rightMargin + 5
  50. }
  51. for itemId in ids {
  52. let item = KMToolbarItemView(itemIdentifier: itemId)
  53. self.setupMainItem(item)
  54. self.rightWidth += (item.itemWidth + 5)
  55. }
  56. }
  57. }
  58. var rightCount: Int {
  59. get {
  60. return self.rightCellIdentifiers?.count ?? 0
  61. }
  62. }
  63. var defaultCellIdentifiers: [String]?
  64. var allowedCellIdentifiers: [String]? {
  65. get {
  66. let left = self.leftCellIdentifiers ?? []
  67. let center = self.centerCellIdentifiers ?? []
  68. let right = self.rightCellIdentifiers ?? []
  69. return left + center + right
  70. }
  71. }
  72. var leftWidth: CGFloat = 0
  73. var centerWidth: CGFloat = 0
  74. var rightWidth: CGFloat = 0
  75. var leftMargin: CGFloat = 10
  76. var rightMargin: CGFloat = 10
  77. var itemH: CGFloat = 48
  78. var contentWidth: CGFloat {
  79. get {
  80. return self.leftWidth + self.centerWidth + self.rightWidth
  81. }
  82. }
  83. var windowWidth: CGFloat = 1480
  84. var segItemWidth: CGFloat {
  85. get {
  86. return (self.windowWidth - self.contentWidth - 26 * 2) * 0.5
  87. }
  88. }
  89. func isLeft(at idx: Int) -> Bool {
  90. if self.leftCount <= 0 {
  91. return false
  92. }
  93. let stardIdx = 0
  94. let endIdx = self.leftCount
  95. if idx >= stardIdx && idx < endIdx {
  96. return true
  97. }
  98. return false
  99. }
  100. func isCenter(at idx: Int) -> Bool {
  101. if self.centerCount <= 0 {
  102. return false
  103. }
  104. let stardIdx = self.leftCount+1
  105. let endIdx = stardIdx+self.centerCount
  106. if idx >= stardIdx && idx < endIdx {
  107. return true
  108. }
  109. return false
  110. }
  111. func isRight(at idx: Int) -> Bool {
  112. if self.rightCount <= 0 {
  113. return false
  114. }
  115. let stardIdx = self.leftCount+self.centerCount+2
  116. let endIdx = stardIdx+self.rightCount
  117. if idx >= stardIdx && idx < endIdx {
  118. return true
  119. }
  120. return false
  121. }
  122. func isFirstSegI(at idx: Int) -> Bool {
  123. return idx == self.leftCount
  124. }
  125. func isSecondSegI(at idx: Int) -> Bool {
  126. return idx == (self.leftCount+self.centerCount+1)
  127. }
  128. }
  129. extension KMToolbarConfigModel {
  130. func setupMainItem(_ item: KMToolbarItemView?) {
  131. let identifier = item?.itemIdentifier
  132. if identifier == KMLeftControlToolbarItemIdentifier {
  133. item?.image = NSImage(named: "KMImageNameUXIconBtnTriLeftNor")
  134. item?.titleName = NSLocalizedString("Panel", comment: "")
  135. item?.target = self
  136. item?.toolTip = NSLocalizedString("View Settings", comment: "")
  137. item?.boxImagePosition = .imageAbove
  138. item?.selectBackgroundType = .imageBox
  139. } else if identifier == KMDocumentZoomToolbarItemIdentifier {
  140. item?.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor")
  141. item?.titleName = NSLocalizedString("", comment: "")
  142. item?.target = self
  143. item?.btnTag = 1
  144. item?.toolTip = NSLocalizedString("Zoom In", comment: "")
  145. item?.boxImagePosition = .imageAbove
  146. } else if identifier == KMDocumentZoomOutToolbarItemIdentifier {
  147. item?.image = NSImage(named: "KMImageNameUXIconToolbarZoomoutNor")
  148. item?.titleName = NSLocalizedString("", comment: "")
  149. item?.target = self
  150. item?.btnTag = 0
  151. item?.toolTip = NSLocalizedString("Zoom Out", comment: "")
  152. item?.boxImagePosition = .imageAbove
  153. } else if identifier == KMDocumentZoomViewToolbarItemIdentifier{
  154. item?.titleName = NSLocalizedString("Zoom", comment: "")
  155. item?.target = self
  156. let view = KMToolbarZoomItemView(zoomView: nil)
  157. item?.customizeView = view
  158. } else if identifier == KMDocumentNextPageToolbarItemIdentifier {
  159. item?.image = NSImage(named: "KMImageNameToolbarPagenextNor")
  160. item?.titleName = NSLocalizedString("Next", comment: "")
  161. item?.target = self
  162. item?.toolTip = NSLocalizedString("Go To Next Page", comment: "")
  163. item?.boxImagePosition = .imageAbove
  164. } else if identifier == KMDocumentPreviousPageToolbarItemIdentifier {
  165. item?.titleName = NSLocalizedString("Zoom", comment: "")
  166. item?.target = self
  167. let view = KMToolbarPreviousNextItemView()
  168. item?.customizeView = view
  169. } else if identifier == KMDocumentHomeToolbarItemIdentifier {
  170. item?.image = NSImage(named: "KMImageNameToolbarHomeNor")
  171. item?.titleName = NSLocalizedString("Home", comment: "")
  172. item?.target = self
  173. item?.toolTip = NSLocalizedString("A Welcome Gift from Us", comment: "")
  174. item?.boxImagePosition = .imageAbove
  175. item?.selectBackgroundType = .imageBox
  176. } else if identifier == KMDocumentAnnotationToolbarItemIdentifier {
  177. item?.titleName = NSLocalizedString("Tools", comment: "")
  178. item?.image = NSImage(named: "KMImageNameUXIconToolbarMytoolsNor")
  179. item?.target = self
  180. item?.toolTip = String(format: "%@: %@, %@, %@, %@", KMLocalizedString("Tool Mode", nil),KMLocalizedString("Annotate", nil),KMLocalizedString("Scroll", nil),KMLocalizedString("Magnify", nil),KMLocalizedString("Select", nil))
  181. item?.btnTag = KMToolbarViewType.Annatiton.rawValue
  182. item?.boxImagePosition = .imageAbove
  183. item?.selectBackgroundType = .imageBox
  184. } else if identifier == KMDocumentPageToolbarItemIdentifier {
  185. item?.titleName = NSLocalizedString("Page Edit", comment: "")
  186. item?.target = self
  187. item?.image = NSImage(named: "KMImageNameUXIconToolbarPageeditNor")
  188. item?.toolTip = NSLocalizedString("PDF page editor: insert, delete, extract, rotate, reposition, and replace pages in a PDF", comment: "")
  189. item?.btnTag = KMToolbarViewType.Page.rawValue
  190. item?.boxImagePosition = .imageAbove
  191. item?.selectBackgroundType = .imageBox
  192. } else if identifier == KMDocumentConversonToolbarItemIdentifier {
  193. item?.titleName = NSLocalizedString("Converter", comment: "")
  194. item?.target = self
  195. item?.image = NSImage(named: "KMImageNameUXIconToolbarConvertNor")
  196. item?.toolTip = NSLocalizedString("Convert PDFs to Microsoft Word, PowerPoint, Excel, RTF, Text, Image, CSV, and more Offline", comment: "")
  197. item?.btnTag = KMToolbarViewType.Conversion.rawValue
  198. item?.boxImagePosition = .imageAbove
  199. item?.selectBackgroundType = .imageBox
  200. item?.promptIdentifier = identifier
  201. } else if identifier == KMDocumentScanOCRToolbarItemIdentifier {
  202. item?.titleName = NSLocalizedString("OCR", comment: "")
  203. item?.target = self
  204. item?.image = NSImage(named: "KMImageNameToolbarOCRNor")
  205. item?.boxImagePosition = .imageAbove
  206. item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
  207. item?.selectBackgroundType = .imageBox
  208. item?.promptIdentifier = identifier
  209. } else if identifier == KMToolbarToolEnhancedScanIdentifier {
  210. item?.image = NSImage(named: "KMImageNameMainToolEnhancedScan")
  211. item?.target = self
  212. item?.btnTag = 0
  213. item?.toolTip = NSLocalizedString("Enhanced Scan", comment: "")
  214. item?.titleName = NSLocalizedString("Enhanced Scan", comment: "")
  215. item?.boxImagePosition = .imageLeft
  216. item?.selectBackgroundType = .imageBox
  217. } else if identifier == KMToolbarToolOCRTextIdentifier {
  218. item?.image = NSImage(named: "KMImageNameMainToolOCRText")
  219. item?.target = self
  220. item?.toolTip = NSLocalizedString("OCR Text Recognition", comment: "")
  221. item?.titleName = NSLocalizedString("OCR Text Recognition", comment: "")
  222. item?.boxImagePosition = .imageLeft
  223. item?.selectBackgroundType = .imageBox
  224. item?.promptIdentifier = identifier
  225. } else if identifier == KMDocumentEditToolbarItemIdentifier {
  226. item?.titleName = NSLocalizedString("Edit PDF", comment: "")
  227. item?.target = self
  228. item?.image = NSImage(named: "KMImageNameUXIconToolbarEditNor")
  229. item?.boxImagePosition = .imageAbove
  230. item?.btnTag = KMToolbarViewType.editPDF.rawValue
  231. item?.toolTip = NSLocalizedString("Edit text and image in PDF ", comment: "")
  232. item?.selectBackgroundType = .imageBox
  233. item?.promptIdentifier = identifier
  234. } else if identifier == KMDocumentFormToolbarItemIdentifier {
  235. item?.titleName = NSLocalizedString("Forms", comment: "")
  236. item?.target = self
  237. item?.image = NSImage(named: "KMImageNameUXIconToolbarFormNor")
  238. item?.boxImagePosition = .imageAbove
  239. item?.btnTag = KMToolbarViewType.Form.rawValue
  240. item?.toolTip = NSLocalizedString("Edit PDF Form", comment: "")
  241. item?.selectBackgroundType = .imageBox
  242. item?.promptIdentifier = identifier
  243. }
  244. else if identifier == KMDocumentFillSginToolbarItemIdentifier {
  245. item?.titleName = NSLocalizedString("Fill & Sign", comment: "")
  246. item?.target = self
  247. item?.image = NSImage(named: "KMImageNameUXIconToolbarFillsignNor")
  248. item?.boxImagePosition = .imageAbove
  249. item?.btnTag = KMToolbarViewType.FillSign.rawValue
  250. item?.toolTip = NSLocalizedString("Fill and sign forms", comment: "")
  251. item?.selectBackgroundType = .imageBox
  252. item?.promptIdentifier = identifier
  253. } else if identifier == KMDocumentToolToolbarItemIdentifier {
  254. item?.titleName = NSLocalizedString("Editor", comment: "")
  255. item?.target = self
  256. item?.image = NSImage(named: "KMImageNameUXIconToolbarEdittoolNor")
  257. item?.boxImagePosition = .imageAbove
  258. item?.btnTag = KMToolbarViewType.Tool.rawValue
  259. item?.toolTip = NSLocalizedString("Edit, delete, cut, copy, paste, and insert text in PDFs", comment: "")
  260. item?.selectBackgroundType = .imageBox
  261. item?.promptIdentifier = identifier
  262. } else if identifier == KMDocumentRedactToolbarItemIdentifier {
  263. item?.titleName = NSLocalizedString("Redact Text", comment: "")
  264. item?.target = self
  265. item?.image = NSImage(named: "KMImageNameUXIconToolbarRedactNor")
  266. item?.boxImagePosition = .imageAbove
  267. item?.toolTip = NSLocalizedString("Mark for redaction", comment: "")
  268. item?.selectBackgroundType = .imageBox
  269. item?.promptIdentifier = identifier
  270. } else if identifier == KMDocumentAITranslationToolbarItemIdentifier {
  271. item?.image = NSImage(named: "ic_function_other_AITranslation")
  272. item?.titleName = "AI Translation"
  273. item?.target = self
  274. item?.toolTip = NSLocalizedString("AI Translation", comment: "")
  275. item?.boxImagePosition = .imageOnly
  276. item?.promptIdentifier = identifier
  277. } else if identifier == KMDocumentPrintToolbarItemIdentifier {
  278. item?.image = NSImage(named: "KMImageNameMainToolbarPrint")
  279. item?.titleName = "Print"
  280. item?.target = self
  281. item?.toolTip = NSLocalizedString("Print", comment: "")
  282. item?.boxImagePosition = .imageOnly
  283. } else if identifier == KMDocumentViewDisplayToolbarItemIdentifier {
  284. item?.image = NSImage(named: "KMImageNameUXIconToolbarPageviewNor")
  285. item?.titleName = NSLocalizedString("Page Display", comment: "")
  286. item?.target = self
  287. item?.toolTip = NSLocalizedString("Page Display", comment: "")
  288. item?.boxImagePosition = .imageAbove
  289. item?.selectBackgroundType = .imageBox
  290. item?.promptIdentifier = identifier
  291. } else if identifier == KMDocumentAIToolsToolbarItemIdentifier {
  292. item?.image = NSImage(named: "KMImageNameUXIconAINor")
  293. item?.titleName = NSLocalizedString("AI Tools", comment: "")
  294. item?.target = self
  295. item?.toolTip = NSLocalizedString("AI Tools", comment: "")
  296. item?.boxImagePosition = .imageAbove
  297. item?.selectBackgroundType = .imageBox
  298. item?.promptIdentifier = identifier
  299. } else if identifier == KMDocumentShareToolbarItemIdentifier {
  300. item?.image = NSImage(named: "KMImageNameUXIconToolbarShareNor")
  301. item?.titleName = NSLocalizedString("Share", comment: "")
  302. item?.target = self
  303. // item?.toolTip = NSLocalizedString("Share the file with others", comment: "")
  304. item?.boxImagePosition = .imageAbove
  305. item?.selectBackgroundType = .imageBox
  306. } else if identifier == KMDocumentSearchToolbarItemIdentifier {
  307. item?.titleName = NSLocalizedString("Search", comment: "")
  308. item?.target = self
  309. let view = NSView()
  310. view.frame = NSMakeRect(0, 0, 150, 40)
  311. let boxView = NSView()
  312. boxView.frame = NSMakeRect(0, 16, 150, 22)
  313. view.addSubview(boxView)
  314. let searchView = NSSearchField()
  315. searchView.frame = NSMakeRect(0, 0, 150, 22)
  316. searchView.placeholderString = NSLocalizedString("Search", comment: "")
  317. searchView.sendsWholeSearchString = true
  318. searchView.sendsSearchStringImmediately = true
  319. searchView.drawsBackground = false
  320. // searchView.delegate = self
  321. // self.searchField = searchView
  322. // self.refreshSearchBarMenu()
  323. boxView.addSubview(searchView)
  324. let titleLabel = NSTextField(labelWithString: NSLocalizedString("Search", comment: ""))
  325. view.addSubview(titleLabel)
  326. titleLabel.frame = NSMakeRect(0, 0, 130, 14)
  327. titleLabel.alignment = .center
  328. titleLabel.textColor = KMAppearance.subtitleColor()
  329. titleLabel.font = KMToolbarMainItemView.textFont
  330. item?.customizeView = view
  331. } else if identifier == KMRightControlToolbarItemIdentifier {
  332. item?.image = NSImage(named: "KMImageNameUXIconBtnTriRightNor")
  333. item?.titleName = NSLocalizedString("Properties", comment: "")
  334. item?.target = self
  335. item?.toolTip = NSLocalizedString("Show/Hide Annotation Properties Panel", comment: "")
  336. item?.boxImagePosition = .imageAbove
  337. item?.selectBackgroundType = .imageBox
  338. } else if identifier == KMToolbarToolRedactItemIdentifier {
  339. item?.image = NSImage(named: "KMImageNameMainToolsRedact")
  340. item?.target = self
  341. item?.btnTag = KMToolbarType.redact.rawValue
  342. item?.toolTip = NSLocalizedString("Redact", comment: "")
  343. item?.titleName = NSLocalizedString("Redact", comment: "")
  344. item?.selectBackgroundType = .imageBox
  345. item?.promptIdentifier = identifier
  346. } else if identifier == KMDocumentDigitalSignToolbarItemIdentifier {
  347. item?.image = NSImage(named: "DigitalSign_icon")
  348. item?.target = self
  349. 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: "")
  350. item?.titleName = NSLocalizedString("Digital Sign", comment: "")
  351. item?.selectBackgroundType = .imageBox
  352. item?.boxImagePosition = .imageAbove
  353. item?.promptIdentifier = identifier
  354. }
  355. }
  356. }