KMMainViewController+MenuAction.swift 65 KB

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