KMLeftSideViewController+Action.swift 56 KB

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