KMMainViewController+MenuAction.swift 49 KB

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