KMLeftSideViewController+Action.swift 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. //
  2. // KMLeftSideViewController+Action.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/12/22.
  6. //
  7. import Foundation
  8. // MARK: - Action
  9. extension KMLeftSideViewController {
  10. @IBAction func leftSideViewMoreButtonAction(_ sender: AnyObject?) {
  11. let button = sender as? NSButton
  12. let tag = button?.tag ?? 0
  13. if (tag == 300) {
  14. var selectedRow = 0
  15. if (self.snapshotTableView.selectedRow >= 0) {
  16. selectedRow = self.snapshotTableView.selectedRow;
  17. } else {
  18. return
  19. }
  20. let model = self.snapshots[selectedRow]
  21. let controller = model.windowC
  22. let menu = NSMenu()
  23. let itemExport = menu.addItem(title: KMLocalizedString("Export", "Menu item title"), action: nil, target: self)
  24. let subMenu = NSMenu()
  25. var t = subMenu.addItem(title: KMLocalizedString("PNG", "Menu item title"), action: #selector(menuItemClick_ExportPNG), target: self)
  26. t?.representedObject = controller
  27. t = subMenu.addItem(title: KMLocalizedString("JPG", "Menu item title"), action: #selector(menuItemClick_ExportJPG), target: self)
  28. t?.representedObject = controller
  29. t = subMenu.addItem(title: KMLocalizedString("PDF", "Menu item title"), action: #selector(menuItemClick_ExportPDF), target: self)
  30. t?.representedObject = controller
  31. itemExport?.submenu = subMenu
  32. let itemPrint = menu.addItem(title: KMLocalizedString("Print", "Menu item title"), action: #selector(menuItemClick_Print), target: self)
  33. itemPrint?.representedObject = controller
  34. menu.addItem(.separator())
  35. let itemSelectAll = menu.addItem(title: KMLocalizedString("Select All", "Menu item title"), action: #selector(menuItemClick_SelectAll), target: self)
  36. itemSelectAll?.representedObject = controller
  37. menu.addItem(.separator())
  38. let itemDeleteAllSnapshot = menu.addItem(title: KMLocalizedString("Delete All Snapshots", "Menu item title"), action: #selector(deleteAllSnapshot), target: self)
  39. itemDeleteAllSnapshot?.representedObject = controller
  40. //
  41. NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: sender as! NSButton)
  42. } else if (tag == 302) {
  43. let menu = NSMenu()
  44. let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(toc_expandAllComments), target: self)
  45. expandAllCommentsItem?.representedObject = self.tocOutlineView
  46. let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(toc_foldAllComments), target: self)
  47. expandAllCommentsItem?.representedObject = self.tocOutlineView
  48. let item = self.listView.document.outlineRoot()
  49. var num = 0
  50. for i in 0 ..< Int(item?.numberOfChildren ?? 0) {
  51. let outline = item?.child(at: UInt(i))
  52. if self.tocOutlineView.isItemExpanded(outline) {
  53. num += 1
  54. }
  55. }
  56. if let cnt = item?.numberOfChildren, cnt > 0 && num == 0 {
  57. self.tocType = .fold
  58. } else if let cnt = item?.numberOfChildren, cnt > 0 && num == cnt {
  59. self.tocType = .unfold
  60. } else {
  61. self.tocType = .none
  62. }
  63. if (self.tocType == .unfold) {
  64. expandAllCommentsItem?.state = .on
  65. foldAllCommentsItem?.state = .off
  66. } else if (self.tocType == .fold) {
  67. expandAllCommentsItem?.state = .off
  68. foldAllCommentsItem?.state = .on
  69. } else {
  70. expandAllCommentsItem?.state = .off
  71. foldAllCommentsItem?.state = .off
  72. }
  73. let removeEntryItem = menu.addItem(title: KMLocalizedString("Remove All Outlines", nil), action: #selector(leftSideEmptyAnnotationClick_DeleteOutline), target: self)
  74. removeEntryItem?.representedObject = self.tocOutlineView
  75. NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: sender as! NSButton)
  76. } else if (tag == 304) {
  77. let menu = NSMenu()
  78. let object = KMPopupMenuObject()
  79. object.menuTag = 1001
  80. menu.delegate = object
  81. object.enterControllerCallback = { [weak self] isEnter in
  82. if (isEnter) {
  83. self?.moreButtonLayer?.isHidden = false
  84. } else {
  85. self?.moreButtonLayer?.isHidden = true
  86. }
  87. }
  88. let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(note_expandAllComments), target: self)
  89. expandAllCommentsItem?.representedObject = self.noteOutlineView
  90. let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(note_foldAllComments), target: self)
  91. foldAllCommentsItem?.representedObject = self.noteOutlineView
  92. if (self.foldType == .unfold) {
  93. expandAllCommentsItem?.state = .on
  94. foldAllCommentsItem?.state = .off
  95. } else if (self.foldType == .fold) {
  96. expandAllCommentsItem?.state = .off
  97. foldAllCommentsItem?.state = .on
  98. } else {
  99. expandAllCommentsItem?.state = .off
  100. foldAllCommentsItem?.state = .off
  101. }
  102. let showAnnotationItem = menu.addItem(title: KMLocalizedString("Show Note", nil), action: nil, target: self)
  103. let subMenu = NSMenu()
  104. var t = subMenu.addItem(title: KMLocalizedString("Page", nil), action: #selector(noteShowNoteAction), target: self)
  105. let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false
  106. if pageKey {
  107. t?.state = .off
  108. } else {
  109. t?.state = .on
  110. }
  111. t?.representedObject = self.noteOutlineView
  112. t?.tag = 101
  113. t = subMenu.addItem(title: KMLocalizedString("Time", nil) , action: #selector(noteShowNoteAction), target: self)
  114. let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false
  115. if timeKey {
  116. t?.state = .off
  117. } else {
  118. t?.state = .on
  119. }
  120. t?.representedObject = self.noteOutlineView
  121. t?.tag = 102
  122. t = subMenu.addItem(title: KMLocalizedString("Author", nil) , action: #selector(noteShowNoteAction), target: self)
  123. let authorKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false
  124. if authorKey {
  125. t?.state = .off
  126. } else {
  127. t?.state = .on
  128. }
  129. t?.representedObject = self.noteOutlineView
  130. t?.tag = 103
  131. showAnnotationItem?.submenu = subMenu
  132. menu.addItem(.separator())
  133. let exportAnnotationsItem = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: ""), action: nil, target: self)
  134. let subMenu2 = NSMenu()
  135. var t2 = subMenu2.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  136. t2?.representedObject = self.noteOutlineView
  137. t2?.tag = 0
  138. t2 = subMenu2.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  139. t2?.representedObject = self.noteOutlineView
  140. t2?.tag = 1
  141. t2 = subMenu2.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  142. t2?.representedObject = self.noteOutlineView
  143. t2?.tag = 2
  144. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as Text", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  145. t2?.representedObject = self.noteOutlineView
  146. t2?.tag = 3
  147. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  148. t2?.representedObject = self.noteOutlineView
  149. t2?.tag = 4
  150. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  151. t2?.representedObject = self.noteOutlineView
  152. t2?.tag = 5
  153. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  154. t2?.representedObject = self.noteOutlineView
  155. t2?.tag = 6
  156. exportAnnotationsItem?.submenu = subMenu2
  157. menu.addItem(.separator())
  158. let removeAllAnnotationsItem = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: ""), action: #selector(leftSideEmptyAnnotationClick_DeleteAnnotation), target: self)
  159. removeAllAnnotationsItem?.representedObject = self.noteOutlineView
  160. NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: button!, with: nil)
  161. }
  162. }
  163. }
  164. // MARK: - Double Action
  165. extension KMLeftSideViewController {
  166. @objc func toggleSelectedSnapshots(_ sender: AnyObject?) {
  167. let indexs = self.snapshotTableView.selectedRowIndexes
  168. if indexs.isEmpty {
  169. return
  170. }
  171. let model = self.snapshots[indexs.last!]
  172. let windowC = model.windowC
  173. if let data = windowC?.window?.isVisible, data {
  174. windowC?.miniaturize()
  175. } else {
  176. windowC?.deminiaturize()
  177. }
  178. var rowIndexSet = IndexSet()
  179. let row = self.snapshotTableView.selectedRow
  180. if row >= 0 && row < self.snapshots.count {
  181. rowIndexSet.insert(row)
  182. }
  183. var columnIndexSet = IndexSet()
  184. columnIndexSet.insert(0)
  185. self.snapshotTableView.reloadData(forRowIndexes: rowIndexSet, columnIndexes: columnIndexSet)
  186. }
  187. }
  188. // MARK: - NSMenuDelegate
  189. extension KMLeftSideViewController: NSMenuDelegate {
  190. func menuNeedsUpdate(_ menu: NSMenu) {
  191. if menu.isEqual(to: self.tocOutlineView.menu) {
  192. menu.removeAllItems()
  193. _ = menu.addItem(withTitle: NSLocalizedString("Add Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddEntry), target: self, tag: KMOutlineViewMenuItemTag.addEntry.rawValue)
  194. _ = menu.addItem(withTitle: NSLocalizedString("Add Sub-Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddChildEntry), target: self, tag: KMOutlineViewMenuItemTag.addChild.rawValue)
  195. _ = menu.addItem(withTitle: NSLocalizedString("Add To A Higher Level", comment: ""), action: #selector(outlineContextMenuItemClicked_AddAuntEntry), target: self, tag: KMOutlineViewMenuItemTag.addAunt.rawValue)
  196. menu.addItem(.separator())
  197. _ = menu.addItem(withTitle: NSLocalizedString("Delete", comment: ""), action: #selector(outlineContextMenuItemClicked_RemoveEntry), target: self, tag: KMOutlineViewMenuItemTag.remove.rawValue)
  198. menu.addItem(.separator())
  199. _ = menu.addItem(withTitle: NSLocalizedString("Edit", comment: ""), action: #selector(outlineContextMenuItemClicked_Edit), target: self, tag: KMOutlineViewMenuItemTag.edit.rawValue)
  200. _ = menu.addItem(withTitle: NSLocalizedString("Change Destination", comment: ""), action: #selector(outlineContextMenuItemClicked_SetDestination), target: self, tag: KMOutlineViewMenuItemTag.setDestination.rawValue)
  201. _ = menu.addItem(withTitle: NSLocalizedString("Rename", comment: ""), action: #selector(outlineContextMenuItemClicked_Rename), target: self, tag: KMOutlineViewMenuItemTag.rename.rawValue)
  202. menu.addItem(.separator())
  203. _ = menu.addItem(withTitle: NSLocalizedString("Promote", comment: ""), action: #selector(outlineContextMenuItemClicked_Promote), target: self, tag: KMOutlineViewMenuItemTag.promote.rawValue)
  204. _ = menu.addItem(withTitle: NSLocalizedString("Demote", comment: ""), action: #selector(outlineContextMenuItemClicked_Demote), target: self, tag: KMOutlineViewMenuItemTag.demote.rawValue)
  205. return
  206. }
  207. var item: NSMenuItem?
  208. menu.removeAllItems()
  209. if menu.isEqual(to: self.thumbnailTableView.menu) {
  210. let row = self.thumbnailTableView.clickedRow
  211. if self.listView.document.documentURL == nil || self.thumbnailTableView.selectedRowIndexes.contains(row) == false{
  212. return
  213. }
  214. if (row != -1 && self.listView.document.isLocked == false) {
  215. if(self.thumbnailTableView.selectedRowIndexes.count == self.listView.document.pageCount) {
  216. item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: nil, target: self)
  217. } else {
  218. item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: #selector(cutPage), target: self)
  219. }
  220. item?.representedObject = IndexSet(integer: row)
  221. item = menu.addItem(title: KMLocalizedString("Copy", "Menu item title"), action: #selector(copyPage), target: self)
  222. item?.representedObject = IndexSet(integer: row)
  223. if (self.copyPages.count > 0) {
  224. item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: #selector(pastePage), target: self)
  225. }else{
  226. item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: nil, target: self)
  227. }
  228. item?.representedObject = IndexSet(integer: row)
  229. menu.addItem(.separator())
  230. if(self.thumbnailTableView.selectedRowIndexes.count == self.listView.document.pageCount) {
  231. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: nil, target: self)
  232. } else {
  233. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deletePage), target: self)
  234. }
  235. item?.representedObject = IndexSet(integer: row)
  236. menu.addItem(.separator())
  237. item = menu.addItem(title: KMLocalizedString("Rotate", "Menu item title"), action: #selector(rotatePageMenuAction), target: self)
  238. item?.representedObject = IndexSet(integer: row)
  239. item = menu.addItem(title: KMLocalizedString("Insert", "Menu item title"), action: nil, target: self)
  240. let subMenu = NSMenu()
  241. _ = subMenu.addItem(title: KMLocalizedString("Blank Page", "Menu item title"), action: #selector(quickInsert), target: self)
  242. _ = subMenu.addItem(title: KMLocalizedString("Blank Page - Custom...", "Menu item title"), action: #selector(insert), target: self)
  243. _ = subMenu.addItem(title: KMLocalizedString("From PDF", "Menu item title"), action: #selector(insertPDF), target: self)
  244. item?.submenu = subMenu
  245. item?.representedObject = IndexSet(integer: row)
  246. item = menu.addItem(title: KMLocalizedString("Extract", "Menu item title"), action: #selector(extractPage), target: self)
  247. item?.representedObject = IndexSet(integer: row)
  248. item = menu.addItem(title: KMLocalizedString("Page Edit", "Menu item title"), action: #selector(pageEdit), target: self)
  249. menu.addItem(.separator())
  250. var displayStr = ""
  251. if (self.isDisplayPageSize) {
  252. displayStr = KMLocalizedString("Hide Page Size", "Menu item title")
  253. } else {
  254. displayStr = KMLocalizedString("Display Page Size", "Menu item title")
  255. }
  256. item = menu.addItem(title: displayStr, action: #selector(displayPageSize), target: self)
  257. item?.representedObject = IndexSet(integer: row)
  258. if let doct = self.listView?.document {
  259. item = menu.addItem(title: KMLocalizedString("Share", "Menu item title"), action: nil, target: self)
  260. var tName = self.fileNameWithSelectedPages(self.thumbnailTableView.selectedRowIndexes)
  261. if (tName.count > 50) {
  262. tName = tName.substring(to: 50)
  263. }
  264. item?.submenu = NSSharingServicePicker.menu(forSharingItems: [doct.documentURL as Any], subjectContext: tName, withTarget: self, selector: #selector(sharePage), serviceDelegate: nil)
  265. }
  266. }
  267. } else if menu.isEqual(to: self.findTableView.menu) {
  268. var rowIndexes = self.findTableView.selectedRowIndexes
  269. let row = self.findTableView.clickedRow
  270. if (row != -1) {
  271. if rowIndexes.contains(row) == false {
  272. rowIndexes = IndexSet(integer: row)
  273. }
  274. var selections: [CPDFSelection] = []
  275. for (i, data) in self.searchResults.enumerated() {
  276. if rowIndexes.contains(i) {
  277. selections.append(data.selection)
  278. }
  279. }
  280. // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
  281. if self.listView.hideNotes == false {
  282. item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.circle.rawValue)
  283. item?.representedObject = selections
  284. item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.square.rawValue)
  285. item?.representedObject = selections
  286. item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.highlight.rawValue)
  287. item?.representedObject = selections
  288. item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.underline.rawValue)
  289. item?.representedObject = selections
  290. item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.strikeOut.rawValue)
  291. item?.representedObject = selections
  292. }
  293. }
  294. } else if menu.isEqual(to: self.groupedFindTableView.menu) {
  295. var rowIndexes = self.groupedFindTableView.selectedRowIndexes
  296. let row = self.groupedFindTableView.clickedRow
  297. if (row != -1) {
  298. if rowIndexes.contains(row) == false {
  299. rowIndexes = IndexSet(integer: row)
  300. }
  301. // NSArray *selections = [[[leftSideController.groupedFindArrayController arrangedObjects] objectsAtIndexes:rowIndexes] valueForKeyPath:@"@unionOfArrays.matches"];
  302. var selections: [CPDFSelection] = []
  303. for (i, data) in self.groupSearchResults.enumerated() {
  304. if rowIndexes.contains(i) {
  305. for searchM in data.datas {
  306. selections.append(searchM.selection)
  307. }
  308. }
  309. }
  310. item = menu.addItem(title: KMLocalizedString("Select", "Menu item title"), action: #selector(selectSelections), target: self)
  311. item?.representedObject = selections
  312. menu.addItem(.separator())
  313. // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
  314. if self.listView.hideNotes == false {
  315. item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.circle.rawValue)
  316. item?.representedObject = selections
  317. item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.square.rawValue)
  318. item?.representedObject = selections
  319. item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.highlight.rawValue)
  320. item?.representedObject = selections
  321. item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.underline.rawValue)
  322. item?.representedObject = selections
  323. item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.strikeOut.rawValue)
  324. item?.representedObject = selections
  325. }
  326. }
  327. } else if menu.isEqual(to: self.snapshotTableView.menu) {
  328. let row = self.snapshotTableView.clickedRow
  329. if (row != -1) {
  330. let model = self.snapshots[row]
  331. let controller = model.windowC
  332. if let data = controller?.window?.isVisible, data {
  333. item = menu.addItem(title: KMLocalizedString("Hide", "Menu item title"), action: #selector(hideSnapshot), target: self)
  334. item?.representedObject = controller
  335. } else {
  336. item = menu.addItem(title: KMLocalizedString("Show", "Menu item title"), action: #selector(showSnapshot), target: self)
  337. item?.representedObject = controller
  338. }
  339. menu.addItem(.separator())
  340. item = menu.addItem(title: KMLocalizedString("Export", "Menu item title"), action: nil, target: self)
  341. let subMenu = NSMenu()
  342. var t = subMenu.addItem(title: KMLocalizedString("PNG", "Menu item title"), action: #selector(menuItemClick_ExportPNG), target: self)
  343. t?.representedObject = controller
  344. t = subMenu.addItem(title: KMLocalizedString("JPG", "Menu item title"), action: #selector(menuItemClick_ExportJPG), target: self)
  345. t?.representedObject = controller
  346. t = subMenu.addItem(title: KMLocalizedString("PDF", "Menu item title"), action: #selector(menuItemClick_ExportPDF), target: self)
  347. t?.representedObject = controller
  348. item?.submenu = subMenu
  349. item = menu.addItem(title: KMLocalizedString("Print", "Menu item title"), action: #selector(menuItemClick_Print), target: self)
  350. item?.representedObject = controller
  351. menu.addItem(.separator())
  352. item = menu.addItem(title: KMLocalizedString("Copy", "Menu item title"), action: #selector(menuItemClick_Copy), target: self)
  353. item?.representedObject = controller
  354. menu.addItem(.separator())
  355. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteSnapshot), target: self)
  356. item?.representedObject = controller
  357. item = menu.addItem(title: KMLocalizedString("Delete All Snapshots", "Menu item title"), action: #selector(deleteAllSnapshot), target: self)
  358. item?.representedObject = controller
  359. }
  360. } else if menu.isEqual(to: self.noteOutlineView.menu) {
  361. var items: NSArray?
  362. var rowIndexes = self.noteOutlineView.selectedRowIndexes
  363. let row = self.noteOutlineView.clickedRow
  364. if (row != -1) {
  365. if rowIndexes.contains(row) == false {
  366. rowIndexes = IndexSet(integer: row)
  367. }
  368. items = self.noteOutlineView.itemsAtRowIndexes(rowIndexes) as NSArray
  369. // PDFAnnotation *foldNote = (PDFAnnotation *)notes[row];
  370. let foldNote = self.allAnnotations[row]
  371. var isFold = true
  372. if self.allFoldNotes.contains(foldNote) {
  373. isFold = false
  374. }
  375. item = menu.addItem(title: KMLocalizedString("Expand", nil), action: #selector(unfoldNoteAction), target: self)
  376. if (isFold) {
  377. item?.state = .off
  378. } else {
  379. item?.state = .on
  380. }
  381. item?.representedObject = items
  382. item = menu.addItem(title: KMLocalizedString("Collapse", nil), action: #selector(foldNoteAction), target: self)
  383. if (isFold) {
  384. item?.state = .on
  385. } else {
  386. item?.state = .off
  387. }
  388. item?.representedObject = items
  389. menu.addItem(.separator())
  390. if self.listView.hideNotes == false {
  391. // if ([pdfView hideNotes] == NO && [items count] == 1) {
  392. let annotation = self.noteItems(items!).lastObject as? CPDFAnnotation
  393. if let data = annotation?.isEditable(), data {
  394. if annotation?.type == nil {
  395. if annotation!.isNote() {
  396. // [NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis]
  397. item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editNoteTextFromTable), target: self)
  398. item?.representedObject = annotation
  399. }
  400. } else if let data = self.noteOutlineView.tableColumn(withIdentifier: NSUserInterfaceItemIdentifier("note"))?.isHidden, data {
  401. // [NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis]
  402. item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editThisAnnotation), target: self)
  403. item?.representedObject = annotation
  404. } else {
  405. item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editNoteFromTable), target: self)
  406. item?.representedObject = annotation
  407. item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editThisAnnotation), target: self)
  408. item?.representedObject = annotation
  409. item?.keyEquivalentModifierMask = [.option]
  410. item?.isAlternate = true
  411. }
  412. }
  413. }
  414. if menu.numberOfItems > 0 {
  415. item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  416. let subMenu = NSMenu()
  417. item?.submenu = subMenu
  418. item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  419. item?.tag = 0
  420. item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  421. item?.tag = 1
  422. item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  423. item?.tag = 2
  424. item = subMenu.addItem(title: NSLocalizedString("Notes as Texts", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  425. item?.tag = 3
  426. item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  427. item?.tag = 4
  428. item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  429. item?.tag = 5
  430. item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  431. item?.tag = 6
  432. menu.addItem(.separator())
  433. if self.outlineView(self.noteOutlineView, canDeleteItems: items as! [Any]) {
  434. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteNotes), target: self)
  435. item?.representedObject = items
  436. }
  437. item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
  438. }
  439. } else {
  440. let subMenu = NSMenu()
  441. item?.submenu = subMenu
  442. item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  443. item?.tag = 0
  444. item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  445. item?.tag = 1
  446. item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  447. item?.tag = 2
  448. item = subMenu.addItem(title: NSLocalizedString("Notes as Texts", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  449. item?.tag = 3
  450. item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  451. item?.tag = 4
  452. item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  453. item?.tag = 5
  454. item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  455. item?.tag = 6
  456. item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
  457. }
  458. }
  459. }
  460. }
  461. // MARK: - NSMenuItemValidation
  462. extension KMLeftSideViewController: NSMenuItemValidation {
  463. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  464. if (self.listView.document == nil || self.listView.document!.isLocked) {
  465. return false
  466. }
  467. let action = menuItem.action
  468. // if (self.isCompareMode) {
  469. // return NO;
  470. // }
  471. // if (action == @selector(createNewNote:)) {
  472. // BOOL isMarkup = [menuItem tag] == SKHighlightNote || [menuItem tag] == SKUnderlineNote || [menuItem tag] == SKStrikeOutNote;
  473. // isMarkup = NO;
  474. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] allowsNotes] && ([pdfView toolMode] == SKTextToolMode || [pdfView toolMode] == SKNoteToolMode) && [pdfView hideNotes] == NO && (isMarkup == NO || [[pdfView currentSelection] hasCharacters]);
  475. // } else if (action == @selector(editNote:)) {
  476. // PDFAnnotation *annotation = [pdfView activeAnnotation];
  477. // return [self interactionMode] != SKPresentationMode && [annotation isSkimNote] && ([annotation isEditable]);
  478. // } else if (action == @selector(alignLeft:) || action == @selector(alignRight:) || action == @selector(alignCenter:)) {
  479. // PDFAnnotation *annotation = [pdfView activeAnnotation];
  480. // return [self interactionMode] != SKPresentationMode && [annotation isSkimNote] && ([annotation isEditable]) && [annotation respondsToSelector:@selector(setAlignment:)];
  481. // } else if (action == @selector(toggleHideNotes:)) {
  482. // if ([pdfView hideNotes])
  483. // [menuItem setTitle:NSLocalizedString(@"Show Notes", @"Menu item title")];
  484. // else
  485. // [menuItem setTitle:NSLocalizedString(@"Hide Notes", @"Menu item title")];
  486. // return YES;
  487. // } else if (action == @selector(changeDisplaySinglePages:)) {
  488. // [menuItem setState:([pdfView displayMode] & kPDFDisplayTwoUp) == (PDFDisplayMode)[menuItem tag] ? NSOnState : NSOffState];
  489. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  490. // } else if (action == @selector(changeDisplayContinuous:)) {
  491. // [menuItem setState:([pdfView displayMode] & kPDFDisplaySinglePageContinuous) == (PDFDisplayMode)[menuItem tag] ? NSOnState : NSOffState];
  492. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  493. // } else if (action == @selector(changeDisplayMode:)) {
  494. // [menuItem setState:[pdfView displayMode] == (PDFDisplayMode)[menuItem tag] ? NSOnState : NSOffState];
  495. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  496. // } else if (action == @selector(toggleDisplayAsBook:)) {
  497. // [menuItem setState:[pdfView displaysAsBook] ? NSOnState : NSOffState];
  498. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO && ([pdfView displayMode] == kPDFDisplayTwoUp || [pdfView displayMode] == kPDFDisplayTwoUpContinuous);
  499. // } else if (action == @selector(toggleDisplayPageBreaks:)) {
  500. // [menuItem setState:[pdfView displaysPageBreaks] ? NSOnState : NSOffState];
  501. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  502. // } else if (action == @selector(changeDisplayBox:)) {
  503. // [menuItem setState:[pdfView displayBox] == (PDFDisplayBox)[menuItem tag] ? NSOnState : NSOffState];
  504. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  505. // } else if (action == @selector(delete:) || action == @selector(copy:) || action == @selector(cut:) || action == @selector(paste:) || action == @selector(alternatePaste:) || action == @selector(pasteAsPlainText:) || action == @selector(deselectAll:) || action == @selector(changeAnnotationMode:) || action == @selector(changeToolMode:) || action == @selector(changeToolMode:)) {
  506. // return [pdfView validateMenuItem:menuItem];
  507. // } else
  508. // if (action == @selector(doGoToNextPage:)) {
  509. // return [pdfView canGoToNextPage];
  510. // } else if (action == @selector(doGoToPreviousPage:) ) {
  511. // return [pdfView canGoToPreviousPage];
  512. // } else if (action == @selector(doGoToFirstPage:)) {
  513. // return [pdfView canGoToFirstPage];
  514. // } else if (action == @selector(doGoToLastPage:)) {
  515. // return [pdfView canGoToLastPage];
  516. // } else if (action == @selector(doGoToPage:)) {
  517. // return [[self pdfDocument] isLocked] == NO;
  518. // } else if (action == @selector(allGoToNextPage:)) {
  519. // return [[allMainDocumentPDFViews() valueForKeyPath:@"@min.canGoToNextPage"] boolValue];
  520. // } else if (action == @selector(allGoToPreviousPage:)) {
  521. // return [[allMainDocumentPDFViews() valueForKeyPath:@"@min.canGoToPreviousPage"] boolValue];
  522. // } else if (action == @selector(allGoToFirstPage:)) {
  523. // return [[allMainDocumentPDFViews() valueForKeyPath:@"@min.canGoToFirstPage"] boolValue];
  524. // } else if (action == @selector(allGoToLastPage:)) {
  525. // return [[allMainDocumentPDFViews() valueForKeyPath:@"@min.canGoToLastPage"] boolValue];
  526. // } else if (action == @selector(doGoBack:)) {
  527. // return [pdfView canGoBack];
  528. // } else if (action == @selector(doGoForward:)) {
  529. // return [pdfView canGoForward];
  530. // } else if (action == @selector(goToMarkedPage:)) {
  531. // if (beforeMarkedPageIndex != NSNotFound) {
  532. // [menuItem setTitle:NSLocalizedString(@"Jump Back From Marked Page", @"Menu item title")];
  533. // return YES;
  534. // } else {
  535. // [menuItem setTitle:NSLocalizedString(@"Go To Marked Page", @"Menu item title")];
  536. // return markedPageIndex != NSNotFound && markedPageIndex != [[pdfView currentPage] pageIndex];
  537. // }
  538. // } else if (action == @selector(markPage:)) {
  539. // return [[self pdfDocument] isLocked] == NO;
  540. // } else if (action == @selector(doZoomIn:)) {
  541. // return [self interactionMode] != SKPresentationMode && [pdfView canZoomIn];
  542. // } else if (action == @selector(doZoomOut:)) {
  543. // return [self interactionMode] != SKPresentationMode && [pdfView canZoomOut];
  544. // } else if (action == @selector(doZoomToActualSize:)) {
  545. // return [[self pdfDocument] isLocked] == NO && ([pdfView autoScales] || fabs([pdfView scaleFactor] - 1.0 ) > 0.01);
  546. // } else if (action == @selector(doZoomToPhysicalSize:)) {
  547. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO && ([pdfView autoScales] || fabs([pdfView physicalScaleFactor] - 1.0 ) > 0.01);
  548. // } else if (action == @selector(doMarqueeZoomTool:)) {
  549. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  550. // } else if (action == @selector(doZoomToFit:)) {
  551. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO && [pdfView autoScales] == NO;
  552. // } else if (action == @selector(alternateZoomToFit:)) {
  553. // PDFDisplayMode displayMode = [pdfView displayMode];
  554. // if (displayMode == kPDFDisplaySinglePage || displayMode == kPDFDisplayTwoUp) {
  555. // [menuItem setTitle:NSLocalizedString(@"Zoom To Width", @"Menu item title")];
  556. // } else {
  557. // [menuItem setTitle:NSLocalizedString(@"Zoom To Height", @"Menu item title")];
  558. // }
  559. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  560. // } else
  561. // if (action == @selector(doAutoScale:)) {
  562. // return [[self pdfDocument] isLocked] == NO && [pdfView autoScales] == NO;
  563. // } else if (action == @selector(toggleAutoScale:)) {
  564. // [menuItem setState:[pdfView autoScales] ? NSOnState : NSOffState];
  565. // return [[self pdfDocument] isLocked] == NO;
  566. // } else if (action == @selector(rotateRight:) || action == @selector(rotateLeft:) || action == @selector(rotateAllRight:) || action == @selector(rotateAllLeft:)) {
  567. // return [[self pdfDocument] isLocked] == NO;
  568. // } else if (action == @selector(cropAll:) || action == @selector(crop:) || action == @selector(autoCropAll:) || action == @selector(smartAutoCropAll:)) {
  569. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  570. // } else if (action == @selector(autoSelectContent:)) {
  571. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO && [pdfView toolMode] == SKSelectToolMode;
  572. // } else if (action == @selector(takeSnapshot:)) {
  573. // return [[self pdfDocument] isLocked] == NO;
  574. // } else if (action == @selector(toggleLeftSidePane:)) {
  575. // if ([self leftSidePaneIsOpen])
  576. // [menuItem setTitle:NSLocalizedString(@"Hide Panel", @"Menu item title")];
  577. // else
  578. // [menuItem setTitle:NSLocalizedString(@"Show Panel", @"Menu item title")];
  579. // return YES;
  580. // } else if (action == @selector(toggleRightSidePane:)) {
  581. // if ([self rightSidePaneIsOpen])
  582. // [menuItem setTitle:NSLocalizedString(@"Hide Notes Pane", @"Menu item title")];
  583. // else
  584. // [menuItem setTitle:NSLocalizedString(@"Show Notes Pane", @"Menu item title")];
  585. // return [self interactionMode] != SKPresentationMode;
  586. // } else if (action == @selector(changeLeftSidePaneState:)) {
  587. // [menuItem setState:mwcFlags.leftSidePaneState == (SKLeftSidePaneState)[menuItem tag] ? (([leftSideController.findTableView window] || [leftSideController.groupedFindTableView window]) ? NSMixedState : NSOnState) : NSOffState];
  588. // return (SKLeftSidePaneState)[menuItem tag] == SKSidePaneStateThumbnail || [[pdfView document] outlineRoot];
  589. // } else if (action == @selector(changeRightSidePaneState:)) {
  590. // [menuItem setState:mwcFlags.rightSidePaneState == (SKRightSidePaneState)[menuItem tag] ? NSOnState : NSOffState];
  591. // return [self interactionMode] != SKPresentationMode;
  592. // }
  593. // // else if (action == @selector(toggleSplitPDF:)) {
  594. // // if ([(NSView *)secondaryPdfView window])
  595. // // [menuItem setTitle:NSLocalizedString(@"Hide Split PDF", @"Menu item title")];
  596. // // else
  597. // // [menuItem setTitle:NSLocalizedString(@"Show Split PDF", @"Menu item title")];
  598. // // return [self interactionMode] != SKPresentationMode;
  599. // // }
  600. // else
  601. // if (action == @selector(toggleStatusBar:)) {
  602. // if ([statusBar isVisible])
  603. // [menuItem setTitle:NSLocalizedString(@"Hide Status Bar", @"Menu item title")];
  604. // else
  605. // [menuItem setTitle:NSLocalizedString(@"Show Status Bar", @"Menu item title")];
  606. // return [self interactionMode] == SKNormalMode || [self interactionMode] == SKFullScreenMode;
  607. // } else if (action == @selector(searchPDF:)) {
  608. // return [self interactionMode] != SKPresentationMode;
  609. // } else if (action == @selector(toggleFullscreen:)) {
  610. // if ([self interactionMode] == SKFullScreenMode || [self interactionMode] == SKLegacyFullScreenMode)
  611. // [menuItem setTitle:NSLocalizedString(@"Exit Full Screen", @"Menu item title")];
  612. // else
  613. // [menuItem setTitle:NSLocalizedString(@"Full Screen", @"Menu item title")];
  614. // return [self canEnterFullscreen] || [self canExitFullscreen];
  615. // } else if (action == @selector(togglePresentation:)) {
  616. // if ([self interactionMode] == SKPresentationMode)
  617. // [menuItem setTitle:NSLocalizedString(@"Exit Presentation", @"Menu item title")];
  618. // else
  619. // [menuItem setTitle:NSLocalizedString(@"Presentation", @"Menu item title")];
  620. // return [self canEnterPresentation] || [self canExitPresentation];
  621. // } else if (action == @selector(getInfo:)) {
  622. // return [self interactionMode] != SKPresentationMode;
  623. // } else if (action == @selector(performFit:)) {
  624. // return [self interactionMode] == SKNormalMode && [[self pdfDocument] isLocked] == NO;
  625. // } else if (action == @selector(password:)) {
  626. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] permissionsStatus] != kPDFDocumentPermissionsOwner;
  627. // } else if (action == @selector(toggleReadingBar:)) {
  628. // if ([[self pdfView] hasReadingBar])
  629. // [menuItem setTitle:NSLocalizedString(@"Hide Reading Bar", @"Menu item title")];
  630. // else
  631. // [menuItem setTitle:NSLocalizedString(@"Show Reading Bar", @"Menu item title")];
  632. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  633. // } else
  634. // if (action == @selector(savePDFSettingToDefaults:)) {
  635. // if ([self interactionMode] == SKFullScreenMode || [self interactionMode] == SKLegacyFullScreenMode)
  636. // [menuItem setTitle:NSLocalizedString(@"Use Current View Settings as Default for Full Screen", @"Menu item title")];
  637. // else
  638. // [menuItem setTitle:NSLocalizedString(@"Use Current View Settings as Default", @"Menu item title")];
  639. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  640. // } else if (action == @selector(chooseTransition:)) {
  641. // return [[self pdfDocument] pageCount] > 1;
  642. // } else
  643. if (action == #selector(toggleCaseInsensitiveSearch)) {
  644. menuItem.state = self.mwcFlags.caseInsensitiveSearch == 1 ? .on : .off
  645. return true
  646. } else if (action == #selector(toggleWholeWordSearch)) {
  647. menuItem.state = self.mwcFlags.wholeWordSearch == 1 ? .on : .off
  648. return true
  649. }
  650. // else if (action == @selector(toggleCaseInsensitiveNoteSearch:)) {
  651. // [menuItem setState:mwcFlags.caseInsensitiveNoteSearch ? NSOnState : NSOffState];
  652. // return YES;
  653. // } else if (action == @selector(toggleAutoResizeNoteRows:)) {
  654. // [menuItem setState:mwcFlags.autoResizeNoteRows ? NSOnState : NSOffState];
  655. // return YES;
  656. // } else if (action == @selector(performFindPanelAction:)) {
  657. // if ([self interactionMode] == SKPresentationMode)
  658. // return NO;
  659. // switch ([menuItem tag]) {
  660. // case NSFindPanelActionShowFindPanel:
  661. // return YES;
  662. // case NSFindPanelActionNext:
  663. // case NSFindPanelActionPrevious:
  664. // return YES;
  665. // case NSFindPanelActionSetFindString:
  666. // return [[[self pdfView] currentSelection] hasCharacters];
  667. // default:
  668. // return NO;
  669. // }
  670. // } else
  671. // if (action == @selector(highlightFormFiled:)) {
  672. // BOOL highlightFormFiled = [[NSUserDefaults standardUserDefaults] boolForKey:@"kPDFViewHighlightFormFiledKey"];
  673. // [menuItem setState:highlightFormFiled ? NSOnState : NSOffState];
  674. // return YES;
  675. // } else if (action == @selector(highlightLinks:)) {
  676. // BOOL highlightLinks = [[NSUserDefaults standardUserDefaults] boolForKey:@"kPDFViewHighlightLinksKey"];
  677. // [menuItem setState:highlightLinks ? NSOnState : NSOffState];
  678. // return YES;
  679. // } else if (action == @selector(link:)) {
  680. // return ([self.pdfView toolMode] == SKTextToolMode || [self.pdfView toolMode] == SKNoteToolMode) && [self.pdfView hideNotes] == NO && [self.pdfView.document isLocked] == NO;
  681. // return ([self.pdfView toolMode] == SKTextToolMode || [self.pdfView toolMode] == SKNoteToolMode) && [self.pdfView hideNotes] == NO && [self.pdfView.document isLocked] == NO && [[self.pdfView currentSelection] hasCharacters];
  682. // } else if (action == @selector(deletePage:)) {
  683. // return self.pdfView.document.pageCount > 1 ? YES : NO;
  684. // } else if (action == @selector(toggleAutoFlow:)) {
  685. // [menuItem setState:[self.pdfView isAutoFlow] ? NSOnState : NSOffState];
  686. // return YES;
  687. // } else if (action == @selector(themesColor:)){
  688. // if (KMPDFViewModeNormal== self.pdfView.viewMode) {
  689. // [menuItem setState:(menuItem.tag == 0)?NSOnState:NSOffState];
  690. // } else if (KMPDFViewModeSoft == self.pdfView.viewMode){
  691. // [menuItem setState:(menuItem.tag == 1)?NSOnState:NSOffState];
  692. // } else if (KMPDFViewModeNight == self.pdfView.viewMode){
  693. // [menuItem setState:(menuItem.tag == 2)?NSOnState:NSOffState];
  694. // } else if (KMPDFViewModeGreen == self.pdfView.viewMode){
  695. // [menuItem setState:(menuItem.tag == 3)?NSOnState:NSOffState];
  696. // } else if (KMPDFViewModeThemes1 == self.pdfView.viewMode){
  697. // [menuItem setState:(menuItem.tag == 4)?NSOnState:NSOffState];
  698. // } else if (KMPDFViewModeThemes2 == self.pdfView.viewMode){
  699. // [menuItem setState:(menuItem.tag == 5)?NSOnState:NSOffState];
  700. // } else if (KMPDFViewModeThemes3 == self.pdfView.viewMode){
  701. // [menuItem setState:(menuItem.tag == 6)?NSOnState:NSOffState];
  702. // } else if (KMPDFViewModeThemes4 == self.pdfView.viewMode){
  703. // [menuItem setState:(menuItem.tag == 7)?NSOnState:NSOffState];
  704. // }
  705. // // else {
  706. // // [menuItem setState:(menuItem.tag == 4)?NSOnState:NSOffState];
  707. // // }
  708. // NSData * data = [[NSUserDefaults standardUserDefaults] objectForKey:@"kKMPDFViewModeThemesArray"] ? : nil;
  709. // NSInteger themesCount;
  710. // if (data) {
  711. // NSArray * appArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  712. // NSMutableArray * mutableArray = [NSMutableArray arrayWithArray:appArray];
  713. // themesCount = [menuItem tag] - mutableArray.count;
  714. // } else {
  715. // themesCount = [menuItem tag] - 4;
  716. // }
  717. // if (themesCount >= 0) {
  718. // menuItem.hidden = YES;
  719. // return NO;
  720. // } else {
  721. // menuItem.hidden = NO;
  722. // return YES;
  723. // }
  724. // } else
  725. // if (action == @selector(splitViewAction:)){
  726. // if (KMPDFViewSplitModeHorizontal == self.pdfView.viewSplitMode) {
  727. // [menuItem setState:(menuItem.tag == 0)?NSOnState:NSOffState];
  728. // } else if (KMPDFViewSplitModeVertical == self.pdfView.viewSplitMode) {
  729. // [menuItem setState:(menuItem.tag == 1)?NSOnState:NSOffState];
  730. // } else if (KMPDFViewSplitModeDisable == self.pdfView.viewSplitMode) {
  731. // [menuItem setState:(menuItem.tag == 2)?NSOnState:NSOffState];
  732. // }
  733. // } else
  734. if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
  735. action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  736. action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
  737. action == #selector(outlineContextMenuItemClicked_RemoveEntry) ||
  738. action == #selector(outlineContextMenuItemClicked_Edit) ||
  739. action == #selector(outlineContextMenuItemClicked_SetDestination) ||
  740. action == #selector(outlineContextMenuItemClicked_Rename) ||
  741. action == #selector(outlineContextMenuItemClicked_Promote) ||
  742. action == #selector(outlineContextMenuItemClicked_Demote)) {
  743. if let data = self.listView.document?.isLocked, data {
  744. return false
  745. }
  746. if (self.isSearchOutlineMode) {
  747. if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
  748. action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  749. action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
  750. action == #selector(outlineContextMenuItemClicked_Edit) ||
  751. action == #selector(outlineContextMenuItemClicked_Rename)
  752. ) {
  753. return false
  754. }
  755. }
  756. if (self.tocOutlineView.selectedRowIndexes.count > 1) {
  757. if (menuItem.tag == KMOutlineViewMenuItemTag.remove.rawValue) {
  758. return true
  759. }
  760. return false
  761. } else if (self.tocOutlineView.selectedRowIndexes.count > 0) {
  762. if (action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  763. action == #selector(outlineContextMenuItemClicked_SetDestination)) {
  764. return true
  765. }
  766. }
  767. if (self.tocOutlineView.clickedRow == -1) {
  768. if (action == #selector(outlineContextMenuItemClicked_AddEntry)) {
  769. return true
  770. } else {
  771. return false
  772. }
  773. } else {
  774. let clickedOutline = self.tocOutlineView.item(atRow: self.tocOutlineView.clickedRow) as? CPDFOutline
  775. if let data = clickedOutline?.index, data > 0 {
  776. if (action == #selector(outlineContextMenuItemClicked_Demote)) {
  777. return true
  778. }
  779. } else {
  780. if (action == #selector(outlineContextMenuItemClicked_Demote)) {
  781. return false
  782. }
  783. }
  784. let parentOutLine = clickedOutline?.parent
  785. let grandparentOutLine = parentOutLine?.parent
  786. //if clicked PDFOutline 's parent exist
  787. if (grandparentOutLine != nil) {
  788. //and title is equla "add_AuntOutlineKey"
  789. if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
  790. return true
  791. } else if (action == #selector(outlineContextMenuItemClicked_Promote)){
  792. return true
  793. }
  794. } else {
  795. if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
  796. return false
  797. }else if (action == #selector(outlineContextMenuItemClicked_Promote)){
  798. return false
  799. }
  800. }
  801. }
  802. return true
  803. }
  804. // else
  805. // if ([menuItem action] == @selector(toggleEncryptFilePanel:)) {
  806. // [menuItem setTitle:NSLocalizedString(@"Set Passwords", @"Menu item title")];
  807. // NSURL *fileURL = [self.pdfView.document documentURL];
  808. // if (!fileURL) {
  809. // return YES;
  810. // }
  811. // PDFDocument *pdfDoc = [[[PDFDocument alloc] initWithURL:fileURL] autorelease];
  812. //
  813. // if ([pdfDoc isLocked]) {
  814. // [menuItem setTitle:NSLocalizedString(@"Remove Security", @"Menu item title")];
  815. // }
  816. // } else if (action == @selector(toggleToolbarShow:)) {
  817. // NSToolbar *toolbar = [self.window toolbar];
  818. // if ([toolbar isVisible])
  819. // [menuItem setTitle:NSLocalizedString(@"Hide Toolbar", @"Menu item title")];
  820. // else
  821. // [menuItem setTitle:NSLocalizedString(@"Show Toolbar", @"Menu item title")];
  822. // return YES;
  823. // } else if (action == @selector(readMode:)) {
  824. // menuItem.state = self.isReadMode ? NSControlStateValueOn : NSControlStateValueOff;
  825. // return YES;
  826. // } else if (action == @selector(addForm:)) {
  827. // return YES;
  828. // } else if (action == @selector(toggleOutlineCaseInsensitiveSearch:)){
  829. // [menuItem setState:self.outlineIgnoreCaseFlag?NSControlStateValueOn:NSControlStateValueOff];
  830. // return YES;
  831. // } else if (action == @selector(note_expandAllComments:) ||
  832. // action == @selector(note_foldAllComments:) ||
  833. // action == @selector(exportAnnotationNotes:) ||
  834. // action == @selector(leftSideEmptyAnnotationClick_DeleteAnnotation:) ||
  835. // action == @selector(removeAllAnnotations:)) {
  836. // if (@available(macOS 10.13, *)) {
  837. // if (notes.count == 0) {
  838. // return NO;
  839. // } else {
  840. // return YES;
  841. // }
  842. // } else {
  843. // if (action == @selector(note_expandAllComments:) ||
  844. // action == @selector(note_foldAllComments:)) {
  845. // return NO;
  846. // }
  847. // }
  848. // } else
  849. if (action == #selector(unfoldNoteAction) ||
  850. action == #selector(foldNoteAction)) {
  851. let row = self.noteOutlineView.clickedRow
  852. // NSArray *noteArr = [rightSideController.noteArrayController arrangedObjects];
  853. // PDFAnnotation *foldNote = (PDFAnnotation *)noteArr[row];
  854. let foldNote = self.allAnnotations[row]
  855. // SKNPDFAnnotationNote
  856. if foldNote is CPDFMarkupAnnotation || foldNote is CPDFTextAnnotation {
  857. return true
  858. } else {
  859. return false
  860. }
  861. } else if (action == #selector(menuItemClick_ExportPNG) ||
  862. action == #selector(menuItemClick_ExportJPG) ||
  863. action == #selector(menuItemClick_ExportPDF)) {
  864. if (self.snapshotTableView.selectedRow == -1 ) {
  865. return false
  866. } else {
  867. return true
  868. }
  869. }
  870. // else if (action == @selector(editNoteFromTable:)) {
  871. // NSInteger row = [rightSideController.noteOutlineView clickedRow];
  872. // NSArray * noteArr = [rightSideController.noteArrayController arrangedObjects];
  873. // PDFAnnotation *foldNote = (PDFAnnotation *)noteArr[row];
  874. // if (@available(macOS 10.13, *)) {
  875. // if ([foldNote.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
  876. // return NO;
  877. // }
  878. // }
  879. // if ([foldNote isKindOfClass:[PDFAnnotationStamp class]] ||
  880. // [foldNote isKindOfClass:[KMAnnotationStamp class]]) {
  881. // return NO;
  882. // } else {
  883. // return YES;
  884. // }
  885. // }
  886. else if (action == #selector(menuItemClick_SelectAll)) {
  887. menuItem.state = self.snapshotListIsAllSelected() ? .on : .off
  888. return true
  889. }
  890. // else if (action == @selector(leftSideEmptyAnnotationClick_DeleteOutline:)) {
  891. // PDFOutline * item = [[pdfView document] outlineRoot];
  892. // if (self.isSearchOutlineMode) {
  893. // NSInteger num = 0;
  894. // for (NSUInteger i = 0; i < [item numberOfChildren]; i++) {
  895. // PDFOutline *outline = [item childAtIndex:i];
  896. // if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:outline]) {
  897. // num ++;
  898. // }
  899. // }
  900. // if (num > 0)
  901. // return YES;
  902. // else
  903. // return NO;
  904. // } else {
  905. // if ([item numberOfChildren] > 0)
  906. // return YES;
  907. // else
  908. // return NO;
  909. // }
  910. // }
  911. return true
  912. }
  913. }
  914. // MARK: - NSPopoverDelegate
  915. extension KMLeftSideViewController: NSPopoverDelegate {
  916. func popoverWillClose(_ notification: Notification) {
  917. guard let popover = notification.object as? NSPopover else {
  918. return
  919. }
  920. if let vc = popover.contentViewController as? KMOutlineEditViewController {
  921. self.editOutlineUI(vc)
  922. self.tocOutlineView.reloadData()
  923. }
  924. }
  925. }
  926. // MARK: - NSSearchFieldDelegate
  927. extension KMLeftSideViewController: NSSearchFieldDelegate {
  928. func controlTextDidChange(_ obj: Notification) {
  929. if self.outlineSearchField.isEqual(to: obj.object) {
  930. if (self.outlineSearchField.stringValue.isEmpty == false) {
  931. self.isSearchOutlineMode = true
  932. self.tocOutlineView.reloadData()
  933. self.tocOutlineView.expandItem(nil, expandChildren: true)
  934. self.tocType = .unfold
  935. } else {
  936. self.isSearchOutlineMode = false
  937. self.showSearchOutlineBlankState(false)
  938. self.tocOutlineView.reloadData()
  939. }
  940. // self.leftSideEmptyVC.addOutlineBtn.enabled = !self.isSearchOutlineMode;
  941. self.outlineAddButton.isEnabled = !self.isSearchOutlineMode
  942. } else if self.snapshotSearchField.isEqual(to: obj.object) {
  943. let searchString = self.snapshotSearchField.stringValue
  944. // NSPredicate *filterPredicate = nil;
  945. // if ([searchString length] > 0) {
  946. // NSExpression *lhs = [NSExpression expressionForConstantValue:searchString];
  947. // NSExpression *rhs = [NSExpression expressionForKeyPath:@"string"];
  948. // NSUInteger options = NSDiacriticInsensitivePredicateOption;
  949. // if (mwcFlags.caseInsensitiveNoteSearch)
  950. // options |= NSCaseInsensitivePredicateOption;
  951. // filterPredicate = [NSComparisonPredicate predicateWithLeftExpression:lhs rightExpression:rhs modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType options:options];
  952. // }
  953. // [rightSideController.snapshotArrayController setFilterPredicate:filterPredicate];
  954. // NSArray * snapshots = [rightSideController.snapshotArrayController arrangedObjects];
  955. self.searchSnapshots.removeAll()
  956. if searchString.isEmpty {
  957. self.isSearchSnapshotMode = false
  958. self.searchSnapshots = self.snapshots.filter({ model in
  959. let data = model.windowC?.string.contains(searchString) ?? false
  960. return data
  961. })
  962. } else {
  963. self.isSearchSnapshotMode = true
  964. }
  965. var snapshots = self.searchSnapshots
  966. if self.isSearchSnapshotMode == false {
  967. snapshots = self.snapshots
  968. }
  969. Task { @MainActor in
  970. self.updataLeftSideSnapView()
  971. self.snapshotTableView.reloadData()
  972. }
  973. if (snapshots.count > 0) {
  974. self.leftSideEmptyVC.outlineSearchView.removeFromSuperview()
  975. } else {
  976. let view = self.snapshotTableView.enclosingScrollView
  977. let emptyVcSize = self.leftSideEmptyVC.outlineSearchView.frame.size
  978. self.leftSideEmptyVC.outlineSearchView.frame = NSMakeRect((view!.frame.size.width-emptyVcSize.width)/2.0,(view!.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  979. self.leftSideEmptyVC.outlineSearchView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  980. self.snapshotTableView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.outlineSearchView)
  981. }
  982. }
  983. }
  984. }
  985. // MARK: - NSTextFieldDelegate
  986. extension KMLeftSideViewController: NSTextFieldDelegate {
  987. func controlTextDidBeginEditing(_ obj: Notification) {
  988. if self.noteOutlineView.isEqual(to: obj.object) {
  989. // if (mwcFlags.isEditingTable == NO && mwcFlags.isEditingPDF == NO)
  990. // [[self document] objectDidBeginEditing:self];
  991. // mwcFlags.isEditingTable = YES;
  992. }
  993. }
  994. func controlTextDidEndEditing(_ obj: Notification) {
  995. if self.noteOutlineView.isEqual(to: obj.object) {
  996. // if (mwcFlags.isEditingTable && mwcFlags.isEditingPDF == NO)
  997. // [[self document] objectDidEndEditing:self];
  998. // mwcFlags.isEditingTable = NO;
  999. } else if let data = self.renamePDFOutlineTextField?.isEqual(to: obj.object), data {
  1000. let textField = obj.object as! NSTextField
  1001. if let editPDFOutline = self.renamePDFOutline {
  1002. if self.isRenameNoteOutline == false {
  1003. if textField.stringValue == editPDFOutline.label {
  1004. return
  1005. }
  1006. }
  1007. self.renamePDFOutline(editPDFOutline, label: textField.stringValue)
  1008. // [self updateSelectRowHeight];
  1009. self.tocOutlineView.reloadData()
  1010. }
  1011. }
  1012. }
  1013. }