KMMainViewController+MenuAction.swift 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  1. //
  2. // KMMainViewController+MenuAction.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/2/19.
  6. //
  7. import Foundation
  8. // MARK: File Menu
  9. extension KMMainViewController {
  10. @IBAction func menuItemClick_mergePDF(_ sender: Any) {
  11. self.toolbarController.delegate?.clickChildTool?(type: .merge, index: 0)
  12. }
  13. @IBAction func menuItemClick_Compress(_ sender: Any) {
  14. self.toolbarController.delegate?.clickChildTool?(type: .compress, index: 0)
  15. }
  16. @IBAction func menuItemClick_Convert(_ sender: Any) {
  17. }
  18. @IBAction func menuItemAction_ConvertToWord(_ sender: Any) {
  19. self.toolbarController.delegate?.clickChildTool?(type: .word, index: 0)
  20. }
  21. @IBAction func menuItemAction_ConvertToExcel(_ sender: Any) {
  22. self.toolbarController.delegate?.clickChildTool?(type: .excel, index: 0)
  23. }
  24. @IBAction func menuItemAction_ConvertToPPT(_ sender: Any) {
  25. self.toolbarController.delegate?.clickChildTool?(type: .ppt, index: 0)
  26. }
  27. @IBAction func menuItemAction_ConvertToRTF(_ sender: Any) {
  28. self.toolbarController.delegate?.clickChildTool?(type: .rtf, index: 0)
  29. }
  30. @IBAction func menuItemAction_ConvertToHTML(_ sender: Any) {
  31. self.toolbarController.delegate?.clickChildTool?(type: .html, index: 0)
  32. }
  33. @IBAction func menuItemAction_ConvertToText(_ sender: Any) {
  34. self.toolbarController.delegate?.clickChildTool?(type: .conversion_text, index: 0)
  35. }
  36. @IBAction func menuItemAction_ConvertToCSV(_ sender: Any) {
  37. self.toolbarController.delegate?.clickChildTool?(type: .csv, index: 0)
  38. }
  39. @IBAction func menuItemAction_ConvertToImage(_ sender: Any) {
  40. self.toolbarController.delegate?.clickChildTool?(type: .conversion_image, index: 0)
  41. }
  42. @IBAction func menuItemClick_SettingPassword(_ sender: Any) {
  43. self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 1)
  44. }
  45. @IBAction func menuItemClick_RemovePassword(_ sender: Any) {
  46. self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 2)
  47. }
  48. @IBAction func menuItemAction_closeWindow(_ sender: Any) {
  49. self.view.window?.close()
  50. }
  51. @IBAction func menuItemAction_closeAllWindows(_ sender: Any) {
  52. for window in NSApp.windows {
  53. window.close()
  54. }
  55. }
  56. @IBAction func menuItemAction_closeTagPage(_ sender: Any) {
  57. self.browserWindowController?.browser?.closeTab()
  58. }
  59. @IBAction func menuItemAction_showInFinder(_ sender: Any) {
  60. NSWorkspace.shared.activateFileViewerSelecting([self.listView.document.documentURL])
  61. }
  62. @IBAction func menuItemAction_property(_ sender: Any) {
  63. KMInfoWindowController.shared.showWindow(sender)
  64. }
  65. @IBAction func menuItemAction_print(_ sender: Any) {
  66. self.showPrintWindow()
  67. }
  68. }
  69. extension KMMainViewController: KMSystemFileMenuProtocol {
  70. @IBAction func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  71. Task { @MainActor in
  72. if IAPProductsManager.default().isAvailableAllFunction() == false {
  73. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  74. return
  75. }
  76. self.saveAsFlattenedPDFAction()
  77. }
  78. }
  79. func saveAsFlattenedPDFAction(limit: Bool = false) {
  80. DispatchQueue.main.async {
  81. NSPanel.savePanel(self.view.window!, true) { panel in
  82. panel.nameFieldStringValue = self.listView.document.documentURL.deletingPathExtension().lastPathComponent + "_flatten" + ".pdf"
  83. } completion: { response, url, isOpen in
  84. if (response == .cancel) {
  85. return
  86. }
  87. var result = false
  88. if (limit) {
  89. let data = KMTools.saveWatermarkDocumentForFlatten(document: self.listView.document, to: url!)
  90. result = data != nil
  91. } else {
  92. result = self.listView.document.writeFlatten(to: url!)
  93. }
  94. if (!result) {
  95. return
  96. }
  97. if (isOpen) {
  98. NSDocumentController.shared.km_safe_openDocument(withContentsOf: url!, display: true) { _, _, _ in
  99. }
  100. } else {
  101. NSWorkspace.shared.activateFileViewerSelecting([url!])
  102. }
  103. }
  104. }
  105. }
  106. }
  107. // MARK: Edit Menu
  108. @objc protocol KMEditMenuProtocol: NSObjectProtocol {
  109. @objc optional func undo(_ sender: Any)
  110. @objc optional func redo(_ sender: Any)
  111. @objc optional func cut(_ sender: Any)
  112. @objc optional func copy(_ sender: Any)
  113. @objc optional func paste(_ sender: Any)
  114. @objc optional func delete(_ sender: Any)
  115. }
  116. extension KMMainViewController: KMEditMenuProtocol {
  117. @IBAction func menuItemAction_find(_ sender: Any) {
  118. if (self.leftSideViewController.isShowPanel) {
  119. self.toolbarController.cancelSelected(KMLeftControlToolbarItemIdentifier)
  120. self.toolbarController.toolbarType = .None
  121. self.leftSideViewController.showPanelView(show: false)
  122. }
  123. // else {
  124. let isSearch = self.leftSideViewController.type.methodType == .Search
  125. self.leftSideViewController.refreshMethodType(methodType: .Search)
  126. if (isSearch) { // 关闭
  127. self.view.window?.makeFirstResponder(self.listView)
  128. }
  129. // }
  130. }
  131. }
  132. // MARK: - View Menu
  133. extension KMMainViewController {
  134. @IBAction func menuItemAction_adjustWidth(_ sender: Any) {
  135. self.selectZoom(.width)
  136. }
  137. @IBAction func menuItemAction_adjustPage(_ sender: Any) {
  138. self.selectZoom(.fit)
  139. }
  140. @IBAction func menuItemAction_size(_ sender: Any) {
  141. self.selectZoom(.actualSize)
  142. }
  143. @IBAction func menuItemAction_zoomOut(_ sender: Any) {
  144. if (self.listView.canZoomOut) {
  145. self.listView.zoomOut(nil)
  146. }
  147. }
  148. @IBAction func menuItemAction_zoomIn(_ sender: Any) {
  149. if (self.listView.canZoomIn) {
  150. self.listView.zoomIn(nil)
  151. }
  152. }
  153. // page show
  154. @IBAction func menuItemAction_singlePage(_ sender: Any) {
  155. self.selectDisplay(display: .singlePage)
  156. }
  157. @IBAction func menuItemAction_singlePageContinue(_ sender: Any) {
  158. self.selectDisplay(display: .singlePageContinuous)
  159. }
  160. @IBAction func menuItemAction_doublePage(_ sender: Any) {
  161. self.selectDisplay(display: .twoUp)
  162. }
  163. @IBAction func menuItemAction_doublePageContinue(_ sender: Any) {
  164. self.selectDisplay(display: .twoUpContinuous)
  165. }
  166. @IBAction func menuItemAction_bookMode(_ sender: Any) {
  167. self.selectDisplay(display: .bookMode)
  168. }
  169. @IBAction func menuItemAction_readMode(_ sender: Any) {
  170. if (self.isReadMode) {
  171. self.closeReadModel()
  172. } else {
  173. self.openReadModel()
  174. }
  175. }
  176. @IBAction func menuItemAction_showSplitPage(_ sender: Any) {
  177. self.listView?.displaysPageBreaks = !(self.listView?.displaysPageBreaks ?? false)
  178. self.listView.layoutDocumentView()
  179. }
  180. @IBAction func menuItemAction_autoScrol(_ sender: Any) {
  181. }
  182. @IBAction func menuItemAction_autoScrolSetting(_ sender: Any) {
  183. }
  184. // rotate
  185. @IBAction func menuItemAction_rotateLeft(_ sender: Any) {
  186. self.rotateLeft(sender)
  187. }
  188. func rotatePageItems(pageItems: [KMThumbnailPageItem]) {
  189. let tempPageItems = pageItems
  190. for pageItem in tempPageItems {
  191. pageItem.page.rotation = pageItem.rotate
  192. }
  193. self.listView.layoutDocumentView()
  194. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMPDFViewRotatePage"), object: self.listView.document)
  195. self.listView.undoManager?.registerUndo(withTarget: self) { [weak self] targetType in
  196. var tempPageItems: [KMThumbnailPageItem] = []
  197. for pageItem in pageItems {
  198. let item = KMThumbnailPageItem(page: pageItem.page, rotate: pageItem.oldRotate, oldRotate: pageItem.rotate)
  199. tempPageItems.append(item)
  200. }
  201. self?.rotatePageItems(pageItems: tempPageItems)
  202. }
  203. }
  204. @IBAction func menuItemAction_rotateRight(_ sender: Any) {
  205. self.rotateRight(sender)
  206. }
  207. @IBAction func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  208. self.rotateAllLeft(sender)
  209. }
  210. @IBAction func menuItemAction_rotateAllPageRight(_ sender: Any) {
  211. self.rotateAllRight(sender)
  212. }
  213. // split screen
  214. @IBAction func menuItemAction_splitScreenVerti(_ sender: Any) {
  215. }
  216. @IBAction func menuItemAction_splitScreenHorti(_ sender: Any) {
  217. }
  218. @IBAction func menuItemAction_splitScreenNo(_ sender: Any) {
  219. }
  220. @IBAction func menuItemAction_view_readMode(_ sender: Any) {
  221. if (self.isReadMode) {
  222. self.closeReadModel()
  223. } else {
  224. self.openReadModel()
  225. }
  226. }
  227. @IBAction func menuItemAction_enterFullScreen(_ sender: Any) {
  228. }
  229. @IBAction func menuItemAction_hiddenLeftSide(_ sender: Any) {
  230. if (self.leftSideViewController.type.methodType != .None) {
  231. self.leftSideViewController.selectType(self.leftSideViewController.type.methodType)
  232. } else {
  233. self.toolbarController.selectItem(KMLeftControlToolbarItemIdentifier)
  234. }
  235. }
  236. @IBAction func menuItemAction_hiddenRightSide(_ sender: Any) {
  237. self.toolbarController.selectItem(KMRightControlToolbarItemIdentifier)
  238. }
  239. @IBAction func menuItemAction_thumai(_ sender: Any) {
  240. self.leftSideViewController.switchType(.Thumbnail)
  241. }
  242. @IBAction func menuItemAction_outline(_ sender: Any) {
  243. self.leftSideViewController.switchType(.Outline)
  244. }
  245. @IBAction func menuItemAction_bookmark(_ sender: Any) {
  246. self.leftSideViewController.switchType(.Annotation)
  247. }
  248. @IBAction func menuItemAction_annotation(_ sender: Any) {
  249. self.leftSideViewController.switchType(.Annotation)
  250. }
  251. @IBAction func menuItemAction_search(_ sender: Any) {
  252. self.leftSideViewController.switchType(.Search)
  253. }
  254. @IBAction func menuItemAction_topic(_ sender: Any) {
  255. }
  256. @IBAction func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  257. }
  258. @IBAction func togglePresentation(_ sender: Any?) {
  259. if self.canExitPresentation() {
  260. self.exitFullScreen("")
  261. } else if self.canEnterPresentation(){
  262. self.enterPresentation()
  263. }
  264. }
  265. @IBAction func chooseTransition(_ sender: Any?) {
  266. let presentationSheetController = SKPresentationOptionsSheetController()
  267. presentationSheetController.controller = self
  268. // let window = NSWindow.currentWindow()
  269. self.km_beginSheet(windowC: presentationSheetController)
  270. presentationSheetController.closeCallBack = {[weak self] vc in
  271. self?.km_quick_endSheet()
  272. }
  273. }
  274. @IBAction func toggleAutoFlow(_ sender: Any?) {
  275. if (self.listView.isAutoFlow()) {
  276. self.listView.stopAutoFlow()
  277. } else {
  278. self.listView.startAutoFlow()
  279. }
  280. }
  281. @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
  282. autoFlowOptionsSheetController = KMAutoFlowOptionsSheetController(windowNibName: "KMAutoFlowOptionsSheetController")
  283. NSWindow.currentWindow().beginSheet((autoFlowOptionsSheetController?.window)!) { responce in }
  284. }
  285. @IBAction func toggleReadingBar(_ sender: Any?) {
  286. KMPrint("toggleReadingBar")
  287. }
  288. @IBAction func toggleLeftSidePane(_ sender: Any?) {
  289. if self.model.leftPanelOpen {
  290. self.closeLeftPane()
  291. } else {
  292. self.openLeftPane()
  293. }
  294. }
  295. @IBAction func changeLeftSidePaneState(_ sender: Any?) {
  296. guard let item = sender as? NSMenuItem else {
  297. NSSound.beep()
  298. return
  299. }
  300. if item.tag == 3 {
  301. self.leftSideViewController.switchType(.snapshot)
  302. }
  303. }
  304. @IBAction func splitViewAction(_ sender: Any?) {
  305. guard let item = sender as? NSMenuItem else {
  306. return
  307. }
  308. if item.tag < 2 && IAPProductsManager.default().isAvailableAllFunction() == false {
  309. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  310. return
  311. }
  312. self.splitView(withTag: item.tag)
  313. }
  314. @IBAction func themesColor(_ sender: Any?) {
  315. guard let item = sender as? NSMenuItem else {
  316. NSSound.beep()
  317. return
  318. }
  319. let mode = item.tag
  320. if mode > 0 {
  321. if !IAPProductsManager.default().isAvailableAllFunction() {
  322. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  323. return
  324. }
  325. }
  326. if mode == 0 {
  327. self.listView.displayMode = .normal
  328. } else if mode == 1 {
  329. self.listView.displayMode = .soft
  330. } else if mode == 2 {
  331. self.listView.displayMode = .night
  332. } else if mode == 3 {
  333. self.listView.displayMode = .green
  334. } else {
  335. self.listView.displayMode = .custom
  336. var data: Data? = nil
  337. if let themesData = UserDefaults.standard.object(forKey: "kKMPDFViewModeThemesArray") as? Data {
  338. data = themesData
  339. }
  340. let appArray = NSKeyedUnarchiver.unarchiveObject(with: data ?? Data()) as? [Any] ?? []
  341. let mutableArray = appArray
  342. if mutableArray.count > 0 {
  343. let themesArray = mutableArray as! [NSColor]
  344. let color = themesArray[mode]
  345. self.listView.displayModeCustomColor = color
  346. }
  347. }
  348. self.listView.layoutDocumentView()
  349. self.listView.setNeedsDisplayForVisiblePages()
  350. UserDefaults.standard.set(mode, forKey: "kPDFViewModeKey")
  351. UserDefaults.standard.synchronize()
  352. }
  353. @IBAction func toggleStatusBar(_ sender: Any?) {
  354. KMPrint("toggleStatusBar ...")
  355. }
  356. @IBAction func toggleToolbarShow(_ sender: Any?) {
  357. self.toolbarController.mainToolBarisVisable = !self.toolbarController.mainToolBarisVisable
  358. }
  359. }
  360. // MARK: - Annotation Menu
  361. extension KMMainViewController {
  362. @IBAction func menuItemAction_highlight(_ sender: Any) {
  363. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarHighlightAnnotationItemIdentifier)
  364. }
  365. @IBAction func menuItemAction_underline(_ sender: Any) {
  366. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarUnderlineAnnotationItemIdentifier)
  367. }
  368. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  369. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarStrikeOutAnnotationItemIdentifier)
  370. }
  371. @IBAction func menuItemAction_wavyLine(_ sender: Any) {
  372. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarSquigglyAnnotationItemIdentifier)
  373. }
  374. @IBAction func menuItemAction_freehand(_ sender: Any) {
  375. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarInkAnnotationItemIdentifier)
  376. }
  377. @IBAction func menuItemAction_text(_ sender: Any) {
  378. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarFreeTextAnnotationItemIdentifier)
  379. }
  380. @IBAction func menuItemAction_note(_ sender: Any) {
  381. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarAnchoredAnnotationItemIdentifier)
  382. }
  383. @IBAction func menuItemAction_squre(_ sender: Any) {
  384. UserDefaults.standard.set(6, forKey: KMToolBarToolPDFShapeStyle)
  385. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  386. }
  387. @IBAction func menuItemAction_circle(_ sender: Any) {
  388. UserDefaults.standard.set(7, forKey: KMToolBarToolPDFShapeStyle)
  389. self.toolbarController.clickItem(KMToolbarCircleAnnotationItemIdentifier)
  390. }
  391. @IBAction func menuItemAction_arrow(_ sender: Any) {
  392. UserDefaults.standard.set(5, forKey: KMToolBarToolPDFShapeStyle)
  393. self.toolbarController.clickItem(KMToolbarArrowAnnotationItemIdentifier)
  394. }
  395. @IBAction func menuItemAction_line(_ sender: Any) {
  396. UserDefaults.standard.set(4, forKey: KMToolBarToolPDFShapeStyle)
  397. self.toolbarController.clickItem(KMToolbarLineAnnotationItemIdentifier)
  398. }
  399. // link
  400. @IBAction func menuItemAction_link(_ sender: Any) {
  401. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
  402. }
  403. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  404. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
  405. }
  406. @IBAction func menuItemAction_linkHttps(_ sender: Any) {
  407. }
  408. @IBAction func menuItemAction_linkEmail(_ sender: Any) {
  409. }
  410. @IBAction func notesLink(_ sender: Any?) {
  411. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
  412. }
  413. // stamp
  414. @IBAction func menuItemAction_stamp(_ sender: Any) {
  415. self.mainMenuUpdateAnnotationStyle(identifier: KMAnnotationStampToolbarItemIdentifier)
  416. }
  417. @IBAction func menuItemAction_stampStandard(_ sender: Any) {
  418. }
  419. @IBAction func menuItemAction_stampDynamic(_ sender: Any) {
  420. }
  421. @IBAction func menuItemAction_stampCustom(_ sender: Any) {
  422. }
  423. @IBAction func notesStamp(_ sender: Any?) {
  424. self.mainMenuUpdateAnnotationStyle(identifier: KMAnnotationStampToolbarItemIdentifier)
  425. }
  426. @IBAction func menuItemAction_signure(_ sender: Any) {
  427. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarSignSignatureAnnotationItemIdentifier)
  428. }
  429. @IBAction func image(_ sender: Any?) {
  430. self.toolbarController.clickItem(KMAnnotationImageToolbarItemIdentifier)
  431. }
  432. @IBAction func table(_ sender: Any?) {
  433. self.toolbarController.clickItem(KMAnnotationTableToolbarItemIdentifier)
  434. }
  435. @IBAction func addForm(_ sender: Any?) {
  436. guard let item = sender as? NSMenuItem else {
  437. NSSound.beep()
  438. return
  439. }
  440. var identifiers: String?
  441. let idx = item.tag
  442. if idx == 0 { // raido
  443. identifiers = KMToolbarToolRadioButtonItemIdentifier
  444. } else if idx == 1 { // checkbox
  445. identifiers = KMToolbarToolCheckBoxItemIdentifier
  446. } else if idx == 2 { // textfiled
  447. identifiers = KMToolbarToolTextFieldItemIdentifier
  448. } else if idx == 3 { // combobox
  449. identifiers = KMToolbarToolPullDownmenuItemIdentifier
  450. } else if idx == 4 { // listbox
  451. identifiers = KMToolbarToolListBoxItemIdentifier
  452. } else if idx == 5 { // button
  453. identifiers = KMToolbarToolButtonIdentifier
  454. } else if idx == 6 { // sign
  455. identifiers = KMToolbarToolSignBoxIdentifier
  456. }
  457. if let itemID = identifiers {
  458. self.toolbarController.clickItem(itemID)
  459. }
  460. }
  461. @IBAction func editNote(_ sender: Any?) {
  462. if self.listView.hideNotes {
  463. NSSound.beep()
  464. return
  465. }
  466. if let anno = self.listView.activeAnnotation {
  467. self.listView.edit(anno)
  468. }
  469. }
  470. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  471. self.showOrHideNotes()
  472. }
  473. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  474. self.removeAllAnnotations()
  475. }
  476. private func mainMenuUpdateAnnotationStyle(identifier : String) {
  477. if self.toolbarController.toolbarType != .Annatiton {
  478. self.toolbarController.clickItem(KMDocumentAnnotationToolbarItemIdentifier)
  479. }
  480. self.toolbarController.clickItem(identifier)
  481. }
  482. }
  483. // MARK: - KMSystemPDFMenuProtocol
  484. extension KMMainViewController: KMSystemPDFMenuProtocol {
  485. func changeDisplayMode(_ sender: Any?) {
  486. guard let item = sender as? NSMenuItem else {
  487. NSSound.beep()
  488. return
  489. }
  490. let mode = item.tag
  491. if mode == 0 {
  492. self.selectDisplay(display: .singlePage)
  493. } else if mode == 1 {
  494. self.selectDisplay(display: .singlePageContinuous)
  495. } else if mode == 2 {
  496. self.selectDisplay(display: .twoUp)
  497. } else if mode == 3 {
  498. self.selectDisplay(display: .twoUpContinuous)
  499. }
  500. }
  501. func toggleDisplayAsBook(_ sender: Any?) {
  502. self.selectDisplay(display: .bookMode)
  503. }
  504. func toggleDisplayPageBreaks(_ sender: Any?) {
  505. self.listView?.displaysPageBreaks = !(self.listView?.displaysPageBreaks ?? false)
  506. self.listView.layoutDocumentView()
  507. }
  508. func changeDisplayBox(_ sender: Any?) {
  509. guard let item = sender as? NSMenuItem else {
  510. NSSound.beep()
  511. return
  512. }
  513. let mode = item.tag
  514. if mode == 0 {
  515. self.listView.displayBox = .mediaBox
  516. } else if mode == 1 {
  517. self.listView.displayBox = .cropBox
  518. }
  519. }
  520. func toggleAutoScale(_ sender: Any?) {
  521. // if ([self interactionMode] == SKPresentationMode)
  522. // [pdfView toggleAutoActualSize:sender];
  523. // else
  524. // [pdfView setAutoScales:[pdfView autoScales] == NO];
  525. self.listView.autoScales = !self.listView.autoScales
  526. }
  527. func doZoomToActualSize(_ sender: Any?) {
  528. self.selectZoom(.actualSize)
  529. }
  530. func doZoomToFit(_ sender: Any?) {
  531. self.selectZoom(.fit)
  532. }
  533. func doZoomIn(_ sender: Any?) {
  534. if (self.listView.canZoomIn) {
  535. self.listView.zoomIn(nil)
  536. }
  537. if self.digitalSignController?.pdfView != nil {
  538. if (self.digitalSignController?.pdfView.canZoomIn) == true {
  539. self.digitalSignController?.pdfView.zoomIn(nil)
  540. }
  541. }
  542. if self.redactController?.redactPdfView != nil {
  543. if (self.redactController?.redactPdfView.canZoomIn) == true {
  544. self.redactController?.redactPdfView.zoomIn(nil)
  545. }
  546. }
  547. }
  548. func doZoomOut(_ sender: Any?) {
  549. if (self.listView.canZoomOut) {
  550. self.listView.zoomOut(nil)
  551. }
  552. if self.digitalSignController?.pdfView != nil {
  553. if (self.digitalSignController?.pdfView.canZoomOut) == true {
  554. self.digitalSignController?.pdfView.zoomOut(nil)
  555. }
  556. }
  557. if self.redactController?.redactPdfView != nil {
  558. if (self.redactController?.redactPdfView.canZoomOut) == true {
  559. self.redactController?.redactPdfView.zoomOut(nil)
  560. }
  561. }
  562. }
  563. func doMarqueeZoomTool(_ sender: Any?) {
  564. let isSelected = self.toolbarController.findItem(KMToolbarZoomToSelectionItemIdentifier)?.isSelected ?? false
  565. if isSelected == false {
  566. self.toolbarController.clickItem(KMToolbarZoomToSelectionItemIdentifier)
  567. }
  568. }
  569. func highlightFormFiled(_ sender: Any?) {
  570. let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
  571. CPDFKitConfig.sharedInstance().setEnableFormFieldHighlight(!enabled)
  572. self.listView.setNeedsDisplayForVisiblePages()
  573. }
  574. func highlightLinks(_ sender: Any?) {
  575. let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
  576. CPDFKitConfig.sharedInstance().setEnableLinkFieldHighlight(!enabled)
  577. self.listView.setNeedsDisplayForVisiblePages()
  578. }
  579. func resetForm(_ sender: Any?) {
  580. self.listView.resetFormAnnotation()
  581. }
  582. func removeAllAnnotation(_ sender: Any?) {
  583. self.listView.removeAllAnnotation()
  584. }
  585. func savePDFSettingToDefaults(_ sender: Any?) {
  586. if self.interactionMode == .normal {
  587. UserDefaults.standard.sync_setValue(self.currentPDFSettings(), forKey: KMDefaultPDFDisplaySettingsKey)
  588. } else if self.interactionMode != .presentation {
  589. UserDefaults.standard.sync_setValue(self.currentPDFSettings(), forKey: KMDefaultFullScreenPDFDisplaySettingsKey)
  590. }
  591. if listView.displaysAsBook && self.listView.displayTwoUp {
  592. if listView.fetchDisplayViewMode() == .twoUp {
  593. KMPreferenceManager.shared.viewPageDisplayType = .bookMode
  594. } else {
  595. KMPreferenceManager.shared.viewPageDisplayType = .bookContinuous
  596. }
  597. } else {
  598. KMPreferenceManager.shared.viewPageDisplayType = KMPDFDisplayType(rawValue: listView.fetchDisplayViewMode().rawValue) ?? .singlePage
  599. }
  600. self.savePageNumberIfNeed()
  601. }
  602. }
  603. // MARK: - goto Menu
  604. extension KMMainViewController {
  605. @IBAction func menuItemAction_nextPage(_ sender: Any) {
  606. if (self.listView.canGoToNextPage()) {
  607. self.listView.goToNextPage(nil)
  608. }
  609. }
  610. @IBAction func menuItemAction_forwardPage(_ sender: Any) {
  611. if (self.listView.canGoToPreviousPage()) {
  612. self.listView.goToPreviousPage(nil)
  613. }
  614. }
  615. @IBAction func menuItemAction_firstPage(_ sender: Any) {
  616. if (self.listView.canGoToFirstPage()) {
  617. self.listView.goToFirstPage(nil)
  618. }
  619. }
  620. @IBAction func menuItemAction_lastPage(_ sender: Any) {
  621. if (self.listView.canGoToLastPage()) {
  622. self.listView.goToLastPage(nil)
  623. }
  624. }
  625. @IBAction func menuItemAction_forward(_ sender: Any) {
  626. if (self.listView.km_canGoForward()) {
  627. self.listView.km_goForward(nil)
  628. }
  629. }
  630. @IBAction func menuItemAction_goback(_ sender: Any) {
  631. if (self.listView.km_canGoBack()) {
  632. self.listView.km_goBack(nil)
  633. }
  634. }
  635. @IBAction func menuItemAction_gotoPage(_ sender: Any) {
  636. let sheet = KMTextFieldSheetController.init(windowNibName: "PageSheet")
  637. var pages : [String] = []
  638. for i in 0 ..< self.listView.document.pageCount {
  639. pages.append("\(i)")
  640. }
  641. sheet.callback = { [weak self] stringValue in
  642. guard let index = Int(stringValue) else {
  643. return
  644. }
  645. if (self?.listView == nil) {
  646. return
  647. }
  648. if (index > 0 && index <= self!.listView.document.pageCount) {
  649. self?.listView.go(toPageIndex: index-1, animated: true)
  650. }
  651. }
  652. sheet.showWindow(nil)
  653. sheet.pageBox.addItems(withObjectValues: pages)
  654. sheet.stringValue = "\(self.listView.currentPageIndex+1)"
  655. }
  656. @IBAction func goToMarkedPage(_ sender: Any?) {
  657. guard let pdfDoc = self.listView.document, pdfDoc.isLocked == false && pdfDoc.pageCount > 0 else {
  658. NSSound.beep()
  659. return
  660. }
  661. guard let currentPageIndex = self.listView.currentPage()?.pageIndex() else {
  662. NSSound.beep()
  663. return
  664. }
  665. if self.model.beforeMarkedPageIndex != NSNotFound {
  666. self.listView.goToPage(at: min(UInt(self.model.beforeMarkedPageIndex), pdfDoc.pageCount-1), point: self.model.beforeMarkedPagePoint)
  667. } else if (currentPageIndex != self.model.markedPageIndex) {
  668. // NSUInteger lastPageIndex = [pdfView currentPageIndexAndPoint:&beforeMarkedPagePoint rotated:NULL];
  669. let lastPageIndex = self.listView.currentPageIndexAndPoint(&self.model.beforeMarkedPagePoint, rotated: nil)
  670. self.listView.goToPage(at: min(UInt(self.model.markedPageIndex), pdfDoc.pageCount-1), point: self.model.markedPagePoint)
  671. self.model.beforeMarkedPageIndex = Int(lastPageIndex)
  672. }
  673. }
  674. @IBAction func markPage(_ sender: Any?) {
  675. self.model.markedPageIndex = Int(self.listView.currentPageIndexAndPoint(&self.model.markedPagePoint, rotated: nil))
  676. self.model.beforeMarkedPageIndex = NSNotFound
  677. }
  678. }
  679. // MARK: - tool Menu
  680. extension KMMainViewController: KMSystemToolMenuProtocol {
  681. func getInfo(_ sender: Any?) {
  682. KMInfoWindowController.shared.showWindow(sender)
  683. }
  684. @IBAction func menuItemAction_textTool(_ sender: Any) {
  685. self.listView?.toolMode = .textToolMode
  686. self.listView?.annotationType = .unkown
  687. }
  688. @IBAction func menuItemAction_scrolTool(_ sender: Any) {
  689. self.toolbarController.selectItem(KMToolbarMoveToolModeItemIdentifier)
  690. }
  691. @IBAction func menuItemAction_zoomOutTool(_ sender: Any) {
  692. self.toolbarController.selectItem(KMToolbarMagnifyToolModeItemIdentifier)
  693. }
  694. @IBAction func menuItemAction_selectTool(_ sender: Any) {
  695. self.toolbarController.selectItem(KMToolbarSelectToolModeItemIdentifier)
  696. }
  697. func changeToolMode(_ sender: Any?) {
  698. let value = KMDataManager.ud_integer(forKey: SKLastAnnotationModeKey)
  699. var aType: CAnnotationType = .highlight
  700. if let data = CAnnotationType(rawValue: value) {
  701. aType = data
  702. }
  703. if aType.isMarkup() || aType.isSquare() || aType == .freeText || aType == .anchored {
  704. } else {
  705. aType = .highlight
  706. }
  707. var itemId: String = KMToolbarHighlightAnnotationItemIdentifier
  708. if aType == .highlight {
  709. } else if aType == .underline {
  710. itemId = KMToolbarUnderlineAnnotationItemIdentifier
  711. } else if aType == .strikeOut {
  712. itemId = KMToolbarStrikeOutAnnotationItemIdentifier
  713. } else if aType == .ink {
  714. itemId = KMToolbarInkAnnotationItemIdentifier
  715. } else if aType == .freeText {
  716. itemId = KMToolbarFreeTextAnnotationItemIdentifier
  717. } else if aType == .anchored {
  718. itemId = KMToolbarAnchoredAnnotationItemIdentifier
  719. } else if aType == .square {
  720. itemId = KMToolbarSquareAnnotationItemIdentifier
  721. } else if aType == .circle {
  722. itemId = KMToolbarCircleAnnotationItemIdentifier
  723. } else if aType == .line {
  724. itemId = KMToolbarLineAnnotationItemIdentifier
  725. } else if aType == .arrow {
  726. itemId = KMToolbarArrowAnnotationItemIdentifier
  727. } else if aType == .link {
  728. itemId = KMToolbarLinkAnnotationItemIdentifier
  729. }
  730. let isSelected = self.toolbarController.findItem(itemId)?.isSelected ?? false
  731. if isSelected == false {
  732. self.toolbarController.selectItem(itemId)
  733. }
  734. }
  735. @IBAction func menuItemAction_redact(_ sender: Any) {
  736. self.toolbarController.clickItem(KMDocumentRedactToolbarItemIdentifier)
  737. }
  738. @IBAction func menuItemAction_warkmark(_ sender: Any) {
  739. self.toolbarController.delegate?.clickChildTool?(type: .watermark, index: 0)
  740. }
  741. @IBAction func menuItemAction_background(_ sender: Any) {
  742. self.toolbarController.delegate?.clickChildTool?(type: .background, index: 0)
  743. }
  744. @IBAction func menuItemAction_headerfooter(_ sender: Any) {
  745. self.toolbarController.delegate?.clickChildTool?(type: .headerAndFooter, index: 0)
  746. }
  747. @IBAction func menuItemAction_bates(_ sender: Any) {
  748. self.toolbarController.delegate?.clickChildTool?(type: .bates, index: 0)
  749. }
  750. @IBAction func menuItemAction_batch(_ sender: Any) {
  751. // KMBatchWindowController.openFile(self.listView.document?.documentURL, .Batch)
  752. }
  753. func compression(_ sender: Any?) {
  754. self.toolbarController.delegate?.clickChildTool?(type: .compress, index: 0)
  755. }
  756. func merge(_ sender: Any?) {
  757. self.toolbarController.delegate?.clickChildTool?(type: .merge, index: 0)
  758. }
  759. func convert(_ sender: Any?) {
  760. self.toolbarController.delegate?.clickChildTool?(type: .word, index: 0)
  761. }
  762. func imageToPDF(_ sender: Any?) {
  763. KMApp.ShowImageToPDFWindow()
  764. }
  765. func ocr(_ sender: Any?) {
  766. self.toolbarController.clickItem(KMDocumentScanOCRToolbarItemIdentifier)
  767. }
  768. func extractImage(_ sender: Any?) {
  769. self.extractImageAction(num: 1)
  770. }
  771. func pageEdit(_ sender: Any?) {
  772. self.toolbarController.clickItem(KMDocumentPageToolbarItemIdentifier)
  773. }
  774. func textEditAction(_ sender: Any?) {
  775. self.toolbarController.clickItem(KMDocumentEditToolbarItemIdentifier)
  776. }
  777. func security(_ sender: Any?) {
  778. self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 1)
  779. }
  780. func decryption(_ sender: Any?) {
  781. self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 2)
  782. }
  783. func cropAll(_ sender: Any?) {
  784. self.cropAllPage()
  785. }
  786. func crop(_ sender: Any?) {
  787. self.cropCurrentPage()
  788. }
  789. // 白边距
  790. func autoCropAll(_ sender: Any?) {
  791. self.smart_cropAllPage()
  792. }
  793. // 自动
  794. func smartAutoCropAll(_ sender: Any?) {
  795. self.auto_cropAllPage()
  796. }
  797. func cropOptionsModel(_ sender: Any?) {
  798. KMPrint("cropOptionsModel ...")
  799. }
  800. func selectToolModel(_ sender: Any?) {
  801. self.toolbarController.clickItem(KMToolbarSelectToolModeItemIdentifier)
  802. }
  803. func takeSnapshot(_ sender: Any?) {
  804. self.listView.takeSnapshot(sender)
  805. }
  806. func takeSnapshotSelectContent(_ sender: Any?) {
  807. self.listView.takeSnapshotSelectContent(sender)
  808. }
  809. func changeAnnotationMode(_ sender: Any?) {
  810. if let data = sender as? NSMenuItem {
  811. // self.changeAnnotationMode_itemAction(sender: data)
  812. var itemId: String?
  813. if data.tag == 8 {
  814. itemId = KMToolbarHighlightAnnotationItemIdentifier
  815. } else if data.tag == 9 {
  816. itemId = KMToolbarUnderlineAnnotationItemIdentifier
  817. } else if data.tag == 10 {
  818. itemId = KMToolbarStrikeOutAnnotationItemIdentifier
  819. }
  820. // else if data.tag == CAnnotationType.squiggly.rawValue {
  821. // itemId = KMToolbarSquigglyAnnotationItemIdentifier
  822. // }
  823. else if data.tag == 13 {
  824. itemId = KMToolbarInkAnnotationItemIdentifier
  825. } else if data.tag == 3 {
  826. itemId = KMToolbarFreeTextAnnotationItemIdentifier
  827. } else if data.tag == 1 {
  828. itemId = KMToolbarAnchoredAnnotationItemIdentifier
  829. } else if data.tag == 6 {
  830. itemId = KMToolbarSquareAnnotationItemIdentifier
  831. } else if data.tag == 7 {
  832. itemId = KMToolbarCircleAnnotationItemIdentifier
  833. }
  834. // else if data.tag == 4 {
  835. // itemId = KMToolbarArrowAnnotationItemIdentifier
  836. // }
  837. else if data.tag == 4 {
  838. itemId = KMToolbarLineAnnotationItemIdentifier
  839. } else if data.tag == 2 {
  840. itemId = KMToolbarLinkAnnotationItemIdentifier
  841. }
  842. if let data = itemId {
  843. self.toolbarController.clickItem(data)
  844. }
  845. }
  846. }
  847. func addWatermark(_ sender: Any?) {
  848. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  849. if item == nil {
  850. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  851. }
  852. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
  853. }
  854. func removeWatermark(_ sender: Any?) {
  855. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  856. if item == nil {
  857. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  858. }
  859. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
  860. }
  861. func batchAddWatermark(_ sender: Any?) {
  862. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  863. if item == nil {
  864. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  865. }
  866. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
  867. }
  868. func batchRemoveWatermark(_ sender: Any?) {
  869. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  870. if item == nil {
  871. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  872. }
  873. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil)
  874. }
  875. func templateWatermark(_ sender: Any?) {
  876. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  877. if item == nil {
  878. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  879. }
  880. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
  881. }
  882. func addBackground(_ sender: Any?) {
  883. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  884. if item == nil {
  885. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  886. }
  887. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
  888. }
  889. func removeBackground(_ sender: Any?) {
  890. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  891. if item == nil {
  892. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  893. }
  894. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
  895. }
  896. func batchAddBackground(_ sender: Any?) {
  897. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  898. if item == nil {
  899. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  900. }
  901. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
  902. }
  903. func batchRemoveBackground(_ sender: Any?) {
  904. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  905. if item == nil {
  906. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  907. }
  908. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil) }
  909. func templateBackground(_ sender: Any?) {
  910. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  911. if item == nil {
  912. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  913. }
  914. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
  915. }
  916. func addHeaderFooter(_ sender: Any?) {
  917. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  918. if item == nil {
  919. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  920. }
  921. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
  922. }
  923. func removeHeaderFooter(_ sender: Any?) {
  924. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  925. if item == nil {
  926. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  927. }
  928. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
  929. }
  930. func batchAddHeaderFooter(_ sender: Any?) {
  931. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  932. if item == nil {
  933. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  934. }
  935. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
  936. }
  937. func batchRemoveHeaderFooter(_ sender: Any?) {
  938. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  939. if item == nil {
  940. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  941. }
  942. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil)
  943. }
  944. func templateHeaderFooter(_ sender: Any?) {
  945. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  946. if item == nil {
  947. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  948. }
  949. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
  950. }
  951. func addHeaderFooterBates(_ sender: Any?) {
  952. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  953. if item == nil {
  954. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  955. }
  956. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
  957. }
  958. func removeHeaderFooterBates(_ sender: Any?) {
  959. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  960. if item == nil {
  961. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  962. }
  963. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
  964. }
  965. func batchAddBates(_ sender: Any?) {
  966. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  967. if item == nil {
  968. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  969. }
  970. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
  971. }
  972. func batchRemoveBates(_ sender: Any?) {
  973. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  974. if item == nil {
  975. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  976. }
  977. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil)
  978. }
  979. func templateBates(_ sender: Any?) {
  980. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  981. if item == nil {
  982. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  983. }
  984. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
  985. }
  986. func togglePoster(_ sender: Any?) {
  987. self.saveDocument()
  988. KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.listView.document, inputPageRange: KMPrintPageRange(), printType: .poster)
  989. }
  990. func toggleMultiple(_ sender: Any?) {
  991. self.saveDocument()
  992. KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.listView.document, inputPageRange: KMPrintPageRange(), printType: .multipage)
  993. }
  994. func toggleBooklet(_ sender: Any?) {
  995. self.saveDocument()
  996. KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.listView.document, inputPageRange: KMPrintPageRange(), printType: .pamphlet)
  997. }
  998. func rotateLeft(_ sender: Any?) {
  999. if IAPProductsManager.default().isAvailableAllFunction() == false {
  1000. let winC = KMPurchaseCompareWindowController.sharedInstance()
  1001. winC?.kEventName = "Reading_Rotate_BuyNow"
  1002. winC?.kEventTag = 1
  1003. winC?.showWindow(nil)
  1004. return
  1005. }
  1006. Task { @MainActor in
  1007. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  1008. let rotation = page.rotation
  1009. page.leftRotate()
  1010. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  1011. self.handlePageBoundsDidChange(page: page, action: CPDFPage.Action.rotate)
  1012. }
  1013. }
  1014. func rotateRight(_ sender: Any?) {
  1015. if IAPProductsManager.default().isAvailableAllFunction() == false {
  1016. let winC = KMPurchaseCompareWindowController.sharedInstance()
  1017. winC?.kEventName = "Reading_Rotate_BuyNow"
  1018. winC?.kEventTag = 1
  1019. winC?.showWindow(nil)
  1020. return
  1021. }
  1022. Task { @MainActor in
  1023. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  1024. let rotation = page.rotation
  1025. page.rightRotate()
  1026. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  1027. self.handlePageBoundsDidChange(page: page, action: CPDFPage.Action.rotate)
  1028. }
  1029. }
  1030. func rotateAllLeft(_ sender: Any?) {
  1031. if IAPProductsManager.default().isAvailableAllFunction() == false {
  1032. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  1033. return
  1034. }
  1035. Task { @MainActor in
  1036. var pageItems: [KMThumbnailPageItem] = []
  1037. for index in 0 ... self.listView.document.pageCount - 1 {
  1038. let page: CPDFPage = self.listView.document.page(at: index)
  1039. let rotation = page.rotation
  1040. page.leftRotate()
  1041. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  1042. }
  1043. self.rotatePageItems(pageItems: pageItems)
  1044. self.handlePageBoundsDidChange(page: nil, action: CPDFPage.Action.rotate)
  1045. }
  1046. }
  1047. func rotateAllRight(_ sender: Any?) {
  1048. if IAPProductsManager.default().isAvailableAllFunction() == false {
  1049. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  1050. return
  1051. }
  1052. Task { @MainActor in
  1053. var pageItems: [KMThumbnailPageItem] = []
  1054. for index in 0 ... self.listView.document.pageCount - 1 {
  1055. let page: CPDFPage = self.listView.document.page(at: index)
  1056. let rotation = page.rotation
  1057. page.rightRotate()
  1058. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  1059. }
  1060. self.rotatePageItems(pageItems: pageItems)
  1061. self.handlePageBoundsDidChange(page: nil, action: CPDFPage.Action.rotate)
  1062. }
  1063. }
  1064. func autoSelectContent(_ sender: Any?) {
  1065. self.listView.autoSelectContent(sender)
  1066. }
  1067. }
  1068. // MARK: - window Menu
  1069. extension KMMainViewController {
  1070. @IBAction func menuItemAction_showForwardTagPage(_ sender: Any) {
  1071. (self.myDocument as? KMMainDocument)?.browser.selectPreviousTab()
  1072. }
  1073. @IBAction func menuItemAction_showNextTagPage(_ sender: Any) {
  1074. (self.myDocument as? KMMainDocument)?.browser.selectNextTab()
  1075. }
  1076. @IBAction func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  1077. self.browserWindowController?.openNewWindow(sender)
  1078. }
  1079. @IBAction func menuItemAction_mergeAllWindow(_ sender: Any) {
  1080. ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController)?.mergeAllWindow(sender)
  1081. }
  1082. @IBAction func menuItemAction_currentWindowName(_ sender: Any) {
  1083. }
  1084. @IBAction func performFit(_ sender: Any?) {
  1085. if self.interactionMode != .normal {
  1086. NSSound.beep()
  1087. return
  1088. }
  1089. let displayMode = self.listView.fetchDisplayViewMode()
  1090. let scaleFactor = self.listView.scaleFactor
  1091. let autoScales = self.listView.autoScales
  1092. var isSingleRow = false
  1093. if displayMode == .singlePage || displayMode == .twoUp {
  1094. isSingleRow = true
  1095. } else if displayMode == .singlePageContinuous || self.listView.displaysAsBook {
  1096. isSingleRow = (self.listView?.document?.pageCount ?? 0) <= 1
  1097. } else {
  1098. isSingleRow = (self.listView?.document?.pageCount ?? 0) <= 2
  1099. }
  1100. var frame = self.view.window?.frame ?? .zero
  1101. var size: NSSize = .zero
  1102. let oldSize = self.listView.frame.size
  1103. let documentView = self.listView.documentView()
  1104. let documentRect = documentView?.convert(documentView?.bounds ?? .zero, to: nil) ?? .zero
  1105. let page = self.listView.currentPage()
  1106. let box = self.listView.displayBox
  1107. let PAGE_BREAK_MARGIN: CGFloat = 8.0
  1108. let margin = self.listView.displaysPageBreaks ? PAGE_BREAK_MARGIN : 0.0
  1109. // Calculate the new size for the pdfView
  1110. size.width = NSWidth(documentRect)
  1111. if (autoScales) {
  1112. size.width /= scaleFactor
  1113. }
  1114. if (isSingleRow) {
  1115. size.height = NSHeight(documentRect)
  1116. } else {
  1117. let rect = self.listView.convert(page?.bounds(for: box) ?? .zero, from: page)
  1118. size.height = NSHeight(rect) + margin * scaleFactor
  1119. // if ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)] == NO || [NSScroller preferredScrollerStyle] == NSScrollerStyleLegacy)
  1120. // size.width += [NSScroller scrollerWidth];
  1121. if NSScroller.responds(to: NSSelectorFromString("preferredScrollerStyle")) == false {
  1122. let w = NSScroller.scrollerWidth(for: .regular, scrollerStyle: .legacy)
  1123. size.width += w
  1124. } else {
  1125. if NSScroller.preferredScrollerStyle == .legacy {
  1126. let w = NSScroller.scrollerWidth(for: .regular, scrollerStyle: .legacy)
  1127. size.width += w
  1128. }
  1129. }
  1130. }
  1131. if (autoScales) {
  1132. size.height /= scaleFactor
  1133. }
  1134. // Calculate the new size for the window
  1135. size.width = ceil(NSWidth(frame) + size.width - oldSize.width)
  1136. size.height = ceil(NSHeight(frame) + size.height - oldSize.height)
  1137. // Align the window frame from the old topleft point and constrain to the screen
  1138. frame.origin.y = NSMaxY(frame) - size.height
  1139. frame.size = size
  1140. if let screen = self.view.window?.screen ?? NSScreen.main {
  1141. frame = self.view.window?.constrainFrameRect(frame, to: screen) ?? .zero
  1142. }
  1143. self.view.window?.setFrame(frame, display: self.view.window?.isVisible ?? false)
  1144. if displayMode == .singlePageContinuous || displayMode == .twoUpContinuous {
  1145. self.listView.go(to: NSInsetRect(page?.bounds(for: box) ?? .zero, -0.5 * margin, -0.5 * margin), on: page)
  1146. }
  1147. }
  1148. }
  1149. extension KMMainViewController {
  1150. override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  1151. if (menuItem.action == #selector(menuItemAction_currentWindowName)) {
  1152. menuItem.title = (self.myDocument?.fileURL?.lastPathComponent) ?? ""
  1153. return true
  1154. }
  1155. let act = menuItem.action
  1156. if act == #selector(menuItemAnnotationClick_addStype) ||
  1157. act == #selector(menuItemAnnotationClick_add) ||
  1158. act == #selector(menuItemAnnotationClick_toolModel) ||
  1159. act == #selector(changeAnnotationMode_itemAction) {
  1160. return !(self.listView?.hideNotes ?? false)
  1161. }
  1162. if let data = act, KMSystemMenu.isAnnotationSelector(sel: data) {
  1163. if KMSystemMenu.Annotation.hiddenAllSelector == act {
  1164. // return true
  1165. } else {
  1166. return !(self.listView?.hideNotes ?? false)
  1167. }
  1168. }
  1169. if (menuItem.action == #selector(menuItemAction_thumai) ||
  1170. menuItem.action == #selector(menuItemAction_outline) ||
  1171. menuItem.action == #selector(menuItemAction_bookmark) ||
  1172. menuItem.action == #selector(menuItemAction_annotation) ||
  1173. menuItem.action == #selector(menuItemAction_search)) {
  1174. menuItem.state = .off
  1175. let type = self.leftSideViewController.type.methodType
  1176. if (menuItem.action == #selector(menuItemAction_thumai) && type == .Thumbnail) {
  1177. menuItem.state = .on
  1178. }
  1179. if (menuItem.action == #selector(menuItemAction_outline) && type == .Outline) {
  1180. menuItem.state = .on
  1181. }
  1182. if (menuItem.action == #selector(menuItemAction_bookmark) && type == .Annotation) {
  1183. menuItem.state = .on
  1184. }
  1185. if (menuItem.action == #selector(menuItemAction_annotation) && type == .Annotation) {
  1186. menuItem.state = .on
  1187. }
  1188. if (menuItem.action == #selector(menuItemAction_search) && type == .Search) {
  1189. menuItem.state = .on
  1190. }
  1191. }
  1192. if (menuItem.action == #selector(menuItemAction_hiddenLeftSide)) {
  1193. if (self.model.leftPanelOpen) {
  1194. menuItem.title = NSLocalizedString("Hide Left Side Panel", comment: "")
  1195. } else {
  1196. menuItem.title = NSLocalizedString("Show Left Side Panel", comment: "")
  1197. }
  1198. }
  1199. if (menuItem.action == #selector(menuItemAction_hiddenRightSide)) {
  1200. if (self.model.rightPanelIsOpen) {
  1201. menuItem.title = NSLocalizedString("Hide Right Side Panel", comment: "")
  1202. } else {
  1203. menuItem.title = NSLocalizedString("Show Right Side Panel", comment: "")
  1204. }
  1205. }
  1206. if (menuItem.action == #selector(menuItemAction_hiddenAllAnnotation)) {
  1207. if (self.listView.hideNotes) {
  1208. menuItem.title = NSLocalizedString("Show Notes", comment: "")
  1209. } else {
  1210. menuItem.title = NSLocalizedString("Hide Notes", comment: "")
  1211. }
  1212. }
  1213. if (menuItem.action == #selector(menuItemAction_showForwardTagPage) ||
  1214. menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  1215. let browser = self.browserWindowController?.browser
  1216. if (browser != nil && (browser is KMBrowser)) {
  1217. if (menuItem.action == #selector(menuItemAction_showForwardTagPage)) {
  1218. return (browser as! KMBrowser).canSelectPreviousTab()
  1219. }
  1220. if (menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  1221. return (browser as! KMBrowser).canSelectNextTab()
  1222. }
  1223. }
  1224. }
  1225. if (menuItem.action == #selector(menuItemAction_mergeAllWindow)) {
  1226. if let _browserWindowC = ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController) {
  1227. return _browserWindowC.canMergeAllWindow()
  1228. }
  1229. }
  1230. if (menuItem.action == #selector(menuItemAction_nextPage) ||
  1231. menuItem.action == #selector(menuItemAction_forwardPage) ||
  1232. menuItem.action == #selector(menuItemAction_firstPage) ||
  1233. menuItem.action == #selector(menuItemAction_lastPage) ||
  1234. menuItem.action == #selector(menuItemAction_forward) ||
  1235. menuItem.action == #selector(menuItemAction_goback)) {
  1236. if self.hasEnterPageEdit() {
  1237. return false
  1238. }
  1239. if (menuItem.action == #selector(menuItemAction_nextPage)) {
  1240. if self.listView.isEditing() && self.listView.isEditable() {
  1241. return false
  1242. }
  1243. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToNextPage())
  1244. }
  1245. if (menuItem.action == #selector(menuItemAction_forwardPage)) {
  1246. if self.listView.isEditing() && self.listView.isEditable() {
  1247. return false
  1248. }
  1249. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToPreviousPage())
  1250. }
  1251. if (menuItem.action == #selector(menuItemAction_firstPage)) {
  1252. return self.listView.canGoToFirstPage()
  1253. }
  1254. if (menuItem.action == #selector(menuItemAction_lastPage)) {
  1255. return self.listView.canGoToLastPage()
  1256. }
  1257. if (menuItem.action == #selector(menuItemAction_forward)) {
  1258. return self.listView.km_canGoForward()
  1259. }
  1260. if (menuItem.action == #selector(menuItemAction_goback)) {
  1261. return self.listView.km_canGoBack()
  1262. }
  1263. }
  1264. if menuItem.action == #selector(changeAnnotationMode) {
  1265. let type = self.listView.annotationType
  1266. if type == .highlight {
  1267. menuItem.state = menuItem.tag == 8 ? .on : .off
  1268. } else if type == .underline {
  1269. menuItem.state = menuItem.tag == 9 ? .on : .off
  1270. } else if type == .strikeOut {
  1271. menuItem.state = menuItem.tag == 10 ? .on : .off
  1272. } else if type == .ink {
  1273. menuItem.state = menuItem.tag == 13 ? .on : .off
  1274. } else if type == .freeText {
  1275. menuItem.state = menuItem.tag == 3 ? .on : .off
  1276. } else if type == .anchored {
  1277. menuItem.state = menuItem.tag == 1 ? .on : .off
  1278. } else if type == .square {
  1279. menuItem.state = menuItem.tag == 6 ? .on : .off
  1280. } else if type == .circle {
  1281. menuItem.state = menuItem.tag == 7 ? .on : .off
  1282. } else if type == .line {
  1283. menuItem.state = menuItem.tag == 4 ? .on : .off
  1284. } else if type == .link {
  1285. menuItem.state = menuItem.tag == 2 ? .on : .off
  1286. } else {
  1287. menuItem.state = .off
  1288. }
  1289. return !self.listView.hideNotes
  1290. }
  1291. if menuItem.action == #selector(changeAnnotationMode_itemAction) {
  1292. // if ([[menuItem menu] numberOfItems] > ANNOTATION_MODE_COUNT)
  1293. // [menuItem setState:[self toolMode] == SKNoteToolMode && [self annotationMode] == (SKNoteType)[menuItem tag] ? NSOnState : NSOffState];
  1294. // else
  1295. // [menuItem setState:[self annotationMode] == (SKNoteType)[menuItem tag] ? NSOnState : NSOffState];
  1296. if self.listView.annotationType.rawValue == menuItem.tag {
  1297. menuItem.state = .on
  1298. } else {
  1299. menuItem.state = .off
  1300. }
  1301. return true
  1302. }
  1303. if menuItem.action == #selector(menuItemAction_print) {
  1304. if self.listView.document.permissionsStatus == .user && !self.listView.document.allowsPrinting {
  1305. return false
  1306. }
  1307. }
  1308. if menuItem.action == #selector(highlightFormFiled) {
  1309. let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
  1310. menuItem.state = enabled ? .on : .off
  1311. return true
  1312. }
  1313. if menuItem.action == #selector(highlightLinks) {
  1314. let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
  1315. menuItem.state = enabled ? .on : .off
  1316. return true
  1317. }
  1318. guard let action = menuItem.action else {
  1319. return false
  1320. }
  1321. if KMSystemMenu.isToolSelector(sel: action) {
  1322. if action == KMSystemMenu.Tool.autoSelectContentSelector {
  1323. let toolMode = self.listView?.toolMode ?? .none
  1324. return toolMode == .selectToolMode
  1325. } else if action == KMSystemMenu.Tool.textToolSelector {
  1326. let toolMode = self.listView?.toolMode ?? .textToolMode
  1327. menuItem.state = toolMode == .textToolMode ? .on : .off
  1328. return true
  1329. } else if action == KMSystemMenu.Tool.scrolToolSelector {
  1330. let toolMode = self.listView?.toolMode ?? .textToolMode
  1331. menuItem.state = toolMode == .moveToolMode ? .on : .off
  1332. return true
  1333. } else if action == KMSystemMenu.Tool.zoomToolSelector {
  1334. let toolMode = self.listView?.toolMode ?? .textToolMode
  1335. menuItem.state = toolMode == .magnifyToolMode ? .on : .off
  1336. return true
  1337. } else if action == KMSystemMenu.Tool.selectToolSelector {
  1338. let toolMode = self.listView?.toolMode ?? .textToolMode
  1339. menuItem.state = toolMode == .selectToolMode ? .on : .off
  1340. return true
  1341. } else if action == KMSystemMenu.Tool.changeToolModeSelector {
  1342. let aType = self.listView?.annotationType ?? .unkown
  1343. if aType.isMarkup() || aType == .freeText || aType == .anchored || aType.isSquare() || aType == .link {
  1344. menuItem.state = .on
  1345. } else {
  1346. menuItem.state = .off
  1347. }
  1348. return true
  1349. }
  1350. }
  1351. if KMSystemMenu.isViewSelector(sel: action) {
  1352. if action == KMSystemMenu.View.toggleLeftSidePaneSelector {
  1353. if self.model.leftPanelOpen {
  1354. menuItem.title = NSLocalizedString("Hide Panel", comment: "Menu item title")
  1355. } else {
  1356. menuItem.title = NSLocalizedString("Show Panel", comment: "Menu item title")
  1357. }
  1358. return true
  1359. } else if action == KMSystemMenu.View.changeLeftSidePaneStateSelector {
  1360. if menuItem.tag == 3 { // 快照
  1361. menuItem.state = self.leftSideViewController.type.methodType == .snapshot ? .on : .off
  1362. }
  1363. return true
  1364. } else if action == KMSystemMenu.View.themesColorSelector {
  1365. let mode = menuItem.tag
  1366. var viewMode: KMPDFViewMode = .normal
  1367. if let storedViewMode = UserDefaults.standard.value(forKey: "kPDFViewModeKey") as? Int {
  1368. viewMode = KMPDFViewMode(rawValue: UInt(storedViewMode)) ?? .normal
  1369. }
  1370. if mode == 0 {
  1371. menuItem.state = viewMode == .normal ? .on : .off
  1372. } else if mode == 1 {
  1373. menuItem.state = viewMode == .soft ? .on : .off
  1374. } else if mode == 2 {
  1375. menuItem.state = viewMode == .night ? .on : .off
  1376. } else if mode == 3 {
  1377. menuItem.state = viewMode == .green ? .on : .off
  1378. } else if mode == 4 {
  1379. menuItem.state = viewMode == .themes1 ? .on : .off
  1380. } else if mode == 5 {
  1381. menuItem.state = viewMode == .themes2 ? .on : .off
  1382. } else if mode == 6 {
  1383. menuItem.state = viewMode == .themes3 ? .on : .off
  1384. } else if mode == 7 {
  1385. menuItem.state = viewMode == .themes4 ? .on : .off
  1386. }
  1387. var data: Data? = nil
  1388. if let themesData = UserDefaults.standard.object(forKey: "kKMPDFViewModeThemesArray") as? Data {
  1389. data = themesData
  1390. }
  1391. var themesCount = 0
  1392. let appArray = NSKeyedUnarchiver.unarchiveObject(with: data ?? Data()) as? [Any] ?? []
  1393. if appArray.count > 0 {
  1394. themesCount = menuItem.tag - appArray.count
  1395. } else {
  1396. themesCount = menuItem.tag - 4
  1397. }
  1398. if themesCount >= 0 {
  1399. menuItem.isHidden = true
  1400. return false
  1401. }else {
  1402. menuItem.isHidden = false
  1403. return true
  1404. }
  1405. // return true
  1406. } else if action == KMSystemMenu.View.splitViewActionSelector {
  1407. let mode = menuItem.tag
  1408. if mode == 0 { // hor
  1409. menuItem.state = self.listView.viewSplitMode == .horizontal ? .on : .off
  1410. } else if mode == 1 { // verti
  1411. menuItem.state = self.listView.viewSplitMode == .vertical ? .on : .off
  1412. } else if mode == 2 { // single
  1413. menuItem.state = self.listView.viewSplitMode == .disable ? .on : .off
  1414. }
  1415. } else if action == KMSystemMenu.View.toggleToolbarShowSelector {
  1416. menuItem.title = self.toolbarController.mainToolBarisVisable ? KMLocalizedString("Hide Toolbar") : KMLocalizedString("Show Toolbar")
  1417. }
  1418. }
  1419. if KMSystemMenu.isAnnotationSelector(sel: action) {
  1420. if action == KMSystemMenu.Annotation.editNoteSelector {
  1421. if self.interactionMode == .presentation {
  1422. return false
  1423. }
  1424. guard let anno = self.listView?.activeAnnotation else {
  1425. return false
  1426. }
  1427. return anno.isEditable()
  1428. }
  1429. }
  1430. if action == NSSelectorFromString("changeDisplayBox:") {
  1431. if menuItem.tag == 0 {
  1432. menuItem.state = self.listView.displayBox == .mediaBox ? .on : .off
  1433. } else if menuItem.tag == 1 {
  1434. menuItem.state = self.listView.displayBox == .cropBox ? .on : .off
  1435. }
  1436. }
  1437. return true
  1438. }
  1439. }