KMLeftSideViewController+Action.swift 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. //
  2. // KMLeftSideViewController+Action.swift
  3. // PDF Master
  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. var item = menu.addItem(withTitle: NSLocalizedString("Add Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddEntry), target: self, tag: 1)
  16. item = menu.addItem(withTitle: NSLocalizedString("Add Sub-Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddChildEntry), target: self, tag: 2)
  17. item = menu.addItem(withTitle: NSLocalizedString("Add To A Higher Level", comment: ""), action: #selector(outlineContextMenuItemClicked_AddAuntEntry), target: self, tag: 3)
  18. menu.addItem(.separator())
  19. item = menu.addItem(withTitle: NSLocalizedString("Delete", comment: ""), action: #selector(outlineContextMenuItemClicked_RemoveEntry), target: self, tag: 4)
  20. menu.addItem(.separator())
  21. item = menu.addItem(withTitle: NSLocalizedString("Edit", comment: ""), action: #selector(outlineContextMenuItemClicked_Edit), target: self, tag: 5)
  22. item = menu.addItem(withTitle: NSLocalizedString("Change Destination", comment: ""), action: #selector(outlineContextMenuItemClicked_SetDestination), target: self, tag: 6)
  23. item = menu.addItem(withTitle: NSLocalizedString("Rename", comment: ""), action: #selector(outlineContextMenuItemClicked_Rename), target: self, tag: 7)
  24. menu.addItem(.separator())
  25. item = menu.addItem(withTitle: NSLocalizedString("Promote", comment: ""), action: #selector(outlineContextMenuItemClicked_Promote), target: self, tag: 8)
  26. item = menu.addItem(withTitle: NSLocalizedString("Demote", comment: ""), action: #selector(outlineContextMenuItemClicked_Demote), target: self, tag: 9)
  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. item = menu.addItem(title: KMLocalizedString("Share", "Menu item title"), action: nil, target: self)
  81. // NSString * tName = [self fileNameWithSelectedPages:leftSideController.thumbnailTableView.selectedRowIndexes];
  82. // if (tName.length > 50) {
  83. // tName = [tName substringWithRange:NSMakeRange(0, 50)];
  84. // }
  85. var tName = self.listView.document.documentURL.lastPathComponent
  86. item?.submenu = NSSharingServicePicker.menu(forSharingItems: [self.listView.document.documentURL], subjectContext: tName, withTarget: self, selector: #selector(sharePage), serviceDelegate: nil)
  87. }
  88. } else if menu.isEqual(to: self.findTableView.menu) {
  89. var rowIndexes = self.findTableView.selectedRowIndexes
  90. var row = self.findTableView.clickedRow
  91. if (row != -1) {
  92. if rowIndexes.contains(row) == false {
  93. rowIndexes = IndexSet(integer: row)
  94. }
  95. // NSArray *selections = [[leftSideController.findArrayController arrangedObjects] objectsAtIndexes:rowIndexes];
  96. // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
  97. item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 0)
  98. //// [item setRepresentedObject:selections];
  99. item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 1)
  100. //// [item setRepresentedObject:selections];
  101. item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 2)
  102. //// [item setRepresentedObject:selections];
  103. item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 3)
  104. //// [item setRepresentedObject:selections];
  105. item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 4)
  106. // [item setRepresentedObject:selections];
  107. // }
  108. }
  109. } else if menu.isEqual(to: self.groupedFindTableView.menu) {
  110. var rowIndexes = self.groupedFindTableView.selectedRowIndexes
  111. var row = self.groupedFindTableView.clickedRow
  112. if (row != -1) {
  113. if rowIndexes.contains(row) == false {
  114. rowIndexes = IndexSet(integer: row)
  115. }
  116. // NSArray *selections = [[[leftSideController.groupedFindArrayController arrangedObjects] objectsAtIndexes:rowIndexes] valueForKeyPath:@"@unionOfArrays.matches"];
  117. item = menu.addItem(title: KMLocalizedString("Select", "Menu item title"), action: #selector(selectSelections), target: self)
  118. // [item setRepresentedObject:selections];
  119. menu.addItem(.separator())
  120. // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
  121. item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 0)
  122. // [item setRepresentedObject:selections];
  123. item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 1)
  124. // [item setRepresentedObject:selections];
  125. item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 2)
  126. // [item setRepresentedObject:selections];
  127. item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 3)
  128. // [item setRepresentedObject:selections];
  129. item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 4)
  130. // [item setRepresentedObject:selections];
  131. // }
  132. }
  133. } else if menu.isEqual(to: self.snapshotTableView.menu) {
  134. let row = self.snapshotTableView.clickedRow
  135. if (row != -1) {
  136. let model = self.snapshots[row]
  137. let controller = model.windowC
  138. if let data = controller?.window?.isVisible, data {
  139. item = menu.addItem(title: KMLocalizedString("Hide", "Menu item title"), action: #selector(hideSnapshot), target: self)
  140. item?.representedObject = controller
  141. } else {
  142. item = menu.addItem(title: KMLocalizedString("Show", "Menu item title"), action: #selector(showSnapshot), target: self)
  143. item?.representedObject = controller
  144. }
  145. menu.addItem(.separator())
  146. item = menu.addItem(title: KMLocalizedString("Export", "Menu item title"), action: nil, target: self)
  147. let subMenu = NSMenu()
  148. var t = subMenu.addItem(title: KMLocalizedString("PNG", "Menu item title"), action: #selector(menuItemClick_ExportPNG), target: self)
  149. t?.representedObject = controller
  150. t = subMenu.addItem(title: KMLocalizedString("JPG", "Menu item title"), action: #selector(menuItemClick_ExportJPG), target: self)
  151. t?.representedObject = controller
  152. t = subMenu.addItem(title: KMLocalizedString("PDF", "Menu item title"), action: #selector(menuItemClick_ExportPDF), target: self)
  153. t?.representedObject = controller
  154. item?.submenu = subMenu
  155. item = menu.addItem(title: KMLocalizedString("Print", "Menu item title"), action: #selector(menuItemClick_Print), target: self)
  156. item?.representedObject = controller
  157. menu.addItem(.separator())
  158. item = menu.addItem(title: KMLocalizedString("Copy", "Menu item title"), action: #selector(menuItemClick_Copy), target: self)
  159. item?.representedObject = controller
  160. menu.addItem(.separator())
  161. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteSnapshot), target: self)
  162. item?.representedObject = controller
  163. item = menu.addItem(title: KMLocalizedString("Delete All Snapshots", "Menu item title"), action: #selector(deleteAllSnapshot), target: self)
  164. item?.representedObject = controller
  165. }
  166. } else if menu.isEqual(to: self.noteOutlineView.menu) {
  167. // NSArray *items;
  168. var rowIndexes = self.noteOutlineView.selectedRowIndexes
  169. let row = self.noteOutlineView.clickedRow
  170. if (row != -1) {
  171. if rowIndexes.contains(row) == false {
  172. rowIndexes = IndexSet(integer: row)
  173. // items = [rightSideController.noteOutlineView itemsAtRowIndexes:rowIndexes];
  174. // PDFAnnotation *foldNote = (PDFAnnotation *)notes[row];
  175. var isFold = true
  176. // if ([rightSideController.allFoldNotes containsObject:foldNote]) {
  177. // isFold = NO;
  178. // }
  179. item = menu.addItem(title: KMLocalizedString("Expand", nil), action: #selector(unfoldNoteAction), target: self)
  180. if (isFold) {
  181. item?.state = .off
  182. } else {
  183. item?.state = .on
  184. }
  185. // [item setRepresentedObject:items];
  186. item = menu.addItem(title: KMLocalizedString("Collapse", nil), action: #selector(foldNoteAction), target: self)
  187. if (isFold) {
  188. item?.state = .on
  189. } else {
  190. item?.state = .off
  191. }
  192. // [item setRepresentedObject:items];
  193. //UX改版删除
  194. // if ([self outlineView:rightSideController.noteOutlineView canCopyItems:items]) {
  195. // item = [menu addItemWithTitle:NSLocalizedString(@"Copy", @"Menu item title") action:@selector(copyNotes:) target:self];
  196. // [item setRepresentedObject:items];
  197. // }
  198. menu.addItem(.separator())
  199. if self.listView.hideNotes == false {
  200. // if ([pdfView hideNotes] == NO && [items count] == 1) {
  201. // PDFAnnotation *annotation = [[self noteItems:items] lastObject];
  202. // if ([annotation isEditable]) {
  203. // if ([(PDFAnnotation *)[items lastObject] type] == nil) {
  204. // if ([[(SKNoteText *)[items lastObject] note] isNote]) {
  205. // item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editNoteTextFromTable:) target:self];
  206. // [item setRepresentedObject:annotation];
  207. // }
  208. // } else if ([[rightSideController.noteOutlineView tableColumnWithIdentifier:NOTE_COLUMNID] isHidden]) {
  209. // item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editThisAnnotation:) target:pdfView];
  210. // [item setRepresentedObject:annotation];
  211. // } else {
  212. // item = [menu addItemWithTitle:NSLocalizedString(@"Edit", @"Menu item title") action:@selector(editNoteFromTable:) target:self];
  213. // [item setRepresentedObject:annotation];
  214. // item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editThisAnnotation:) target:pdfView];
  215. // [item setRepresentedObject:annotation];
  216. // [item setKeyEquivalentModifierMask:NSEventModifierFlagOption];
  217. // [item setAlternate:YES];
  218. // }
  219. // }
  220. // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
  221. // if ([pdfView activeAnnotation] == annotation) {
  222. // item = [menu addItemWithTitle:NSLocalizedString(@"Deselect", @"Menu item title") action:@selector(deselectNote:) target:self];
  223. // [item setRepresentedObject:annotation];
  224. // } else {
  225. // item = [menu addItemWithTitle:NSLocalizedString(@"Select", @"Menu item title") action:@selector(selectNote:) target:self];
  226. // [item setRepresentedObject:annotation];
  227. // }
  228. // item = [menu addItemWithTitle:NSLocalizedString(@"Show", @"Menu item title") action:@selector(revealNote:) target:self];
  229. // [item setRepresentedObject:annotation];
  230. // }
  231. // }
  232. // if ([menu numberOfItems] > 0)
  233. // [menu addItem:[NSMenuItem separatorItem]];
  234. // item = [menu addItemWithTitle:[items count] == 1 ? NSLocalizedString(@"Auto Size Row", @"Menu item title") : NSLocalizedString(@"Auto Size Rows", @"Menu item title") action:@selector(autoSizeNoteRows:) target:self];
  235. // [item setRepresentedObject:items];
  236. // item = [menu addItemWithTitle:[items count] == 1 ? NSLocalizedString(@"Undo Auto Size Row", @"Menu item title") : NSLocalizedString(@"Undo Auto Size Rows", @"Menu item title") action:@selector(resetHeightOfNoteRows:) target:self];
  237. // [item setRepresentedObject:items];
  238. // [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
  239. // [item setAlternate:YES];
  240. // [menu addItemWithTitle:NSLocalizedString(@"Auto Size All", @"Menu item title") action:@selector(autoSizeNoteRows:) target:self];
  241. // item = [menu addItemWithTitle:NSLocalizedString(@"Undo Auto Size All", @"Menu item title") action:@selector(resetHeightOfNoteRows:) target:self];
  242. // [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
  243. // [item setAlternate:YES];
  244. // [menu addItemWithTitle:NSLocalizedString(@"Automatically Resize", @"Menu item title") action:@selector(toggleAutoResizeNoteRows:) target:self];
  245. if menu.numberOfItems > 0 {
  246. item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  247. let subMenu = NSMenu()
  248. item?.submenu = subMenu
  249. item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  250. item?.tag = 0
  251. item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  252. item?.tag = 1
  253. item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  254. item?.tag = 2
  255. item = subMenu.addItem(title: NSLocalizedString("Notes as Texts", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  256. item?.tag = 3
  257. item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  258. item?.tag = 4
  259. item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  260. item?.tag = 5
  261. item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  262. item?.tag = 6
  263. menu.addItem(.separator())
  264. // if ([self outlineView:rightSideController.noteOutlineView canDeleteItems:items]) {
  265. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteNotes), target: self)
  266. // [item setRepresentedObject:items];
  267. // }
  268. item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
  269. }
  270. }
  271. }
  272. }
  273. }
  274. // else {
  275. // item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Export Annotations…", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  276. //
  277. // NSMenu *subMenu = [NSMenu menu];
  278. // item.submenu = subMenu;
  279. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  280. // item.tag = 0;
  281. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Bundle", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  282. // item.tag = 1;
  283. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Reader Pro Edition Notes", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  284. // item.tag = 2;
  285. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as Text", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  286. // item.tag = 3;
  287. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  288. // item.tag = 4;
  289. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTFD", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  290. // item.tag = 5;
  291. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as FDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  292. // item.tag = 6;
  293. //
  294. // item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Remove All Annotations", @"MainMenu", @"Menu item title") action:@selector(removeAllAnnotations:) target:self];
  295. // }
  296. // }
  297. }
  298. }
  299. // MARK: - NSMenuItemValidation
  300. extension KMLeftSideViewController: NSMenuItemValidation {
  301. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  302. if (self.listView.document == nil || self.listView.document!.isLocked) {
  303. return false
  304. }
  305. let action = menuItem.action
  306. // if (self.isCompareMode) {
  307. // return NO;
  308. // }
  309. // if (action == @selector(createNewNote:)) {
  310. // BOOL isMarkup = [menuItem tag] == SKHighlightNote || [menuItem tag] == SKUnderlineNote || [menuItem tag] == SKStrikeOutNote;
  311. // isMarkup = NO;
  312. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] allowsNotes] && ([pdfView toolMode] == SKTextToolMode || [pdfView toolMode] == SKNoteToolMode) && [pdfView hideNotes] == NO && (isMarkup == NO || [[pdfView currentSelection] hasCharacters]);
  313. // } else if (action == @selector(editNote:)) {
  314. // PDFAnnotation *annotation = [pdfView activeAnnotation];
  315. // return [self interactionMode] != SKPresentationMode && [annotation isSkimNote] && ([annotation isEditable]);
  316. // } else if (action == @selector(alignLeft:) || action == @selector(alignRight:) || action == @selector(alignCenter:)) {
  317. // PDFAnnotation *annotation = [pdfView activeAnnotation];
  318. // return [self interactionMode] != SKPresentationMode && [annotation isSkimNote] && ([annotation isEditable]) && [annotation respondsToSelector:@selector(setAlignment:)];
  319. // } else if (action == @selector(toggleHideNotes:)) {
  320. // if ([pdfView hideNotes])
  321. // [menuItem setTitle:NSLocalizedString(@"Show Notes", @"Menu item title")];
  322. // else
  323. // [menuItem setTitle:NSLocalizedString(@"Hide Notes", @"Menu item title")];
  324. // return YES;
  325. // } else if (action == @selector(changeDisplaySinglePages:)) {
  326. // [menuItem setState:([pdfView displayMode] & kPDFDisplayTwoUp) == (PDFDisplayMode)[menuItem tag] ? NSOnState : NSOffState];
  327. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  328. // } else if (action == @selector(changeDisplayContinuous:)) {
  329. // [menuItem setState:([pdfView displayMode] & kPDFDisplaySinglePageContinuous) == (PDFDisplayMode)[menuItem tag] ? NSOnState : NSOffState];
  330. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  331. // } else if (action == @selector(changeDisplayMode:)) {
  332. // [menuItem setState:[pdfView displayMode] == (PDFDisplayMode)[menuItem tag] ? NSOnState : NSOffState];
  333. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  334. // } else if (action == @selector(toggleDisplayAsBook:)) {
  335. // [menuItem setState:[pdfView displaysAsBook] ? NSOnState : NSOffState];
  336. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO && ([pdfView displayMode] == kPDFDisplayTwoUp || [pdfView displayMode] == kPDFDisplayTwoUpContinuous);
  337. // } else if (action == @selector(toggleDisplayPageBreaks:)) {
  338. // [menuItem setState:[pdfView displaysPageBreaks] ? NSOnState : NSOffState];
  339. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  340. // } else if (action == @selector(changeDisplayBox:)) {
  341. // [menuItem setState:[pdfView displayBox] == (PDFDisplayBox)[menuItem tag] ? NSOnState : NSOffState];
  342. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  343. // } 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:)) {
  344. // return [pdfView validateMenuItem:menuItem];
  345. // } else
  346. // if (action == @selector(doGoToNextPage:)) {
  347. // return [pdfView canGoToNextPage];
  348. // } else if (action == @selector(doGoToPreviousPage:) ) {
  349. // return [pdfView canGoToPreviousPage];
  350. // } else if (action == @selector(doGoToFirstPage:)) {
  351. // return [pdfView canGoToFirstPage];
  352. // } else if (action == @selector(doGoToLastPage:)) {
  353. // return [pdfView canGoToLastPage];
  354. // } else if (action == @selector(doGoToPage:)) {
  355. // return [[self pdfDocument] isLocked] == NO;
  356. // } else if (action == @selector(allGoToNextPage:)) {
  357. // return [[allMainDocumentPDFViews() valueForKeyPath:@"@min.canGoToNextPage"] boolValue];
  358. // } else if (action == @selector(allGoToPreviousPage:)) {
  359. // return [[allMainDocumentPDFViews() valueForKeyPath:@"@min.canGoToPreviousPage"] boolValue];
  360. // } else if (action == @selector(allGoToFirstPage:)) {
  361. // return [[allMainDocumentPDFViews() valueForKeyPath:@"@min.canGoToFirstPage"] boolValue];
  362. // } else if (action == @selector(allGoToLastPage:)) {
  363. // return [[allMainDocumentPDFViews() valueForKeyPath:@"@min.canGoToLastPage"] boolValue];
  364. // } else if (action == @selector(doGoBack:)) {
  365. // return [pdfView canGoBack];
  366. // } else if (action == @selector(doGoForward:)) {
  367. // return [pdfView canGoForward];
  368. // } else if (action == @selector(goToMarkedPage:)) {
  369. // if (beforeMarkedPageIndex != NSNotFound) {
  370. // [menuItem setTitle:NSLocalizedString(@"Jump Back From Marked Page", @"Menu item title")];
  371. // return YES;
  372. // } else {
  373. // [menuItem setTitle:NSLocalizedString(@"Go To Marked Page", @"Menu item title")];
  374. // return markedPageIndex != NSNotFound && markedPageIndex != [[pdfView currentPage] pageIndex];
  375. // }
  376. // } else if (action == @selector(markPage:)) {
  377. // return [[self pdfDocument] isLocked] == NO;
  378. // } else if (action == @selector(doZoomIn:)) {
  379. // return [self interactionMode] != SKPresentationMode && [pdfView canZoomIn];
  380. // } else if (action == @selector(doZoomOut:)) {
  381. // return [self interactionMode] != SKPresentationMode && [pdfView canZoomOut];
  382. // } else if (action == @selector(doZoomToActualSize:)) {
  383. // return [[self pdfDocument] isLocked] == NO && ([pdfView autoScales] || fabs([pdfView scaleFactor] - 1.0 ) > 0.01);
  384. // } else if (action == @selector(doZoomToPhysicalSize:)) {
  385. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO && ([pdfView autoScales] || fabs([pdfView physicalScaleFactor] - 1.0 ) > 0.01);
  386. // } else if (action == @selector(doMarqueeZoomTool:)) {
  387. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  388. // } else if (action == @selector(doZoomToFit:)) {
  389. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO && [pdfView autoScales] == NO;
  390. // } else if (action == @selector(alternateZoomToFit:)) {
  391. // PDFDisplayMode displayMode = [pdfView displayMode];
  392. // if (displayMode == kPDFDisplaySinglePage || displayMode == kPDFDisplayTwoUp) {
  393. // [menuItem setTitle:NSLocalizedString(@"Zoom To Width", @"Menu item title")];
  394. // } else {
  395. // [menuItem setTitle:NSLocalizedString(@"Zoom To Height", @"Menu item title")];
  396. // }
  397. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  398. // } else
  399. // if (action == @selector(doAutoScale:)) {
  400. // return [[self pdfDocument] isLocked] == NO && [pdfView autoScales] == NO;
  401. // } else if (action == @selector(toggleAutoScale:)) {
  402. // [menuItem setState:[pdfView autoScales] ? NSOnState : NSOffState];
  403. // return [[self pdfDocument] isLocked] == NO;
  404. // } else if (action == @selector(rotateRight:) || action == @selector(rotateLeft:) || action == @selector(rotateAllRight:) || action == @selector(rotateAllLeft:)) {
  405. // return [[self pdfDocument] isLocked] == NO;
  406. // } else if (action == @selector(cropAll:) || action == @selector(crop:) || action == @selector(autoCropAll:) || action == @selector(smartAutoCropAll:)) {
  407. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  408. // } else if (action == @selector(autoSelectContent:)) {
  409. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO && [pdfView toolMode] == SKSelectToolMode;
  410. // } else if (action == @selector(takeSnapshot:)) {
  411. // return [[self pdfDocument] isLocked] == NO;
  412. // } else if (action == @selector(toggleLeftSidePane:)) {
  413. // if ([self leftSidePaneIsOpen])
  414. // [menuItem setTitle:NSLocalizedString(@"Hide Panel", @"Menu item title")];
  415. // else
  416. // [menuItem setTitle:NSLocalizedString(@"Show Panel", @"Menu item title")];
  417. // return YES;
  418. // } else if (action == @selector(toggleRightSidePane:)) {
  419. // if ([self rightSidePaneIsOpen])
  420. // [menuItem setTitle:NSLocalizedString(@"Hide Notes Pane", @"Menu item title")];
  421. // else
  422. // [menuItem setTitle:NSLocalizedString(@"Show Notes Pane", @"Menu item title")];
  423. // return [self interactionMode] != SKPresentationMode;
  424. // } else if (action == @selector(changeLeftSidePaneState:)) {
  425. // [menuItem setState:mwcFlags.leftSidePaneState == (SKLeftSidePaneState)[menuItem tag] ? (([leftSideController.findTableView window] || [leftSideController.groupedFindTableView window]) ? NSMixedState : NSOnState) : NSOffState];
  426. // return (SKLeftSidePaneState)[menuItem tag] == SKSidePaneStateThumbnail || [[pdfView document] outlineRoot];
  427. // } else if (action == @selector(changeRightSidePaneState:)) {
  428. // [menuItem setState:mwcFlags.rightSidePaneState == (SKRightSidePaneState)[menuItem tag] ? NSOnState : NSOffState];
  429. // return [self interactionMode] != SKPresentationMode;
  430. // }
  431. // // else if (action == @selector(toggleSplitPDF:)) {
  432. // // if ([(NSView *)secondaryPdfView window])
  433. // // [menuItem setTitle:NSLocalizedString(@"Hide Split PDF", @"Menu item title")];
  434. // // else
  435. // // [menuItem setTitle:NSLocalizedString(@"Show Split PDF", @"Menu item title")];
  436. // // return [self interactionMode] != SKPresentationMode;
  437. // // }
  438. // else
  439. // if (action == @selector(toggleStatusBar:)) {
  440. // if ([statusBar isVisible])
  441. // [menuItem setTitle:NSLocalizedString(@"Hide Status Bar", @"Menu item title")];
  442. // else
  443. // [menuItem setTitle:NSLocalizedString(@"Show Status Bar", @"Menu item title")];
  444. // return [self interactionMode] == SKNormalMode || [self interactionMode] == SKFullScreenMode;
  445. // } else if (action == @selector(searchPDF:)) {
  446. // return [self interactionMode] != SKPresentationMode;
  447. // } else if (action == @selector(toggleFullscreen:)) {
  448. // if ([self interactionMode] == SKFullScreenMode || [self interactionMode] == SKLegacyFullScreenMode)
  449. // [menuItem setTitle:NSLocalizedString(@"Exit Full Screen", @"Menu item title")];
  450. // else
  451. // [menuItem setTitle:NSLocalizedString(@"Full Screen", @"Menu item title")];
  452. // return [self canEnterFullscreen] || [self canExitFullscreen];
  453. // } else if (action == @selector(togglePresentation:)) {
  454. // if ([self interactionMode] == SKPresentationMode)
  455. // [menuItem setTitle:NSLocalizedString(@"Exit Presentation", @"Menu item title")];
  456. // else
  457. // [menuItem setTitle:NSLocalizedString(@"Presentation", @"Menu item title")];
  458. // return [self canEnterPresentation] || [self canExitPresentation];
  459. // } else if (action == @selector(getInfo:)) {
  460. // return [self interactionMode] != SKPresentationMode;
  461. // } else if (action == @selector(performFit:)) {
  462. // return [self interactionMode] == SKNormalMode && [[self pdfDocument] isLocked] == NO;
  463. // } else if (action == @selector(password:)) {
  464. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] permissionsStatus] != kPDFDocumentPermissionsOwner;
  465. // } else if (action == @selector(toggleReadingBar:)) {
  466. // if ([[self pdfView] hasReadingBar])
  467. // [menuItem setTitle:NSLocalizedString(@"Hide Reading Bar", @"Menu item title")];
  468. // else
  469. // [menuItem setTitle:NSLocalizedString(@"Show Reading Bar", @"Menu item title")];
  470. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  471. // } else
  472. // if (action == @selector(savePDFSettingToDefaults:)) {
  473. // if ([self interactionMode] == SKFullScreenMode || [self interactionMode] == SKLegacyFullScreenMode)
  474. // [menuItem setTitle:NSLocalizedString(@"Use Current View Settings as Default for Full Screen", @"Menu item title")];
  475. // else
  476. // [menuItem setTitle:NSLocalizedString(@"Use Current View Settings as Default", @"Menu item title")];
  477. // return [self interactionMode] != SKPresentationMode && [[self pdfDocument] isLocked] == NO;
  478. // } else if (action == @selector(chooseTransition:)) {
  479. // return [[self pdfDocument] pageCount] > 1;
  480. // } else if (action == @selector(toggleCaseInsensitiveSearch:)) {
  481. // [menuItem setState:mwcFlags.caseInsensitiveSearch ? NSOnState : NSOffState];
  482. // return YES;
  483. // } else if (action == @selector(toggleWholeWordSearch:)) {
  484. // [menuItem setState:mwcFlags.wholeWordSearch ? NSOnState : NSOffState];
  485. // return YES;
  486. // } else if (action == @selector(toggleCaseInsensitiveNoteSearch:)) {
  487. // [menuItem setState:mwcFlags.caseInsensitiveNoteSearch ? NSOnState : NSOffState];
  488. // return YES;
  489. // } else if (action == @selector(toggleAutoResizeNoteRows:)) {
  490. // [menuItem setState:mwcFlags.autoResizeNoteRows ? NSOnState : NSOffState];
  491. // return YES;
  492. // } else if (action == @selector(performFindPanelAction:)) {
  493. // if ([self interactionMode] == SKPresentationMode)
  494. // return NO;
  495. // switch ([menuItem tag]) {
  496. // case NSFindPanelActionShowFindPanel:
  497. // return YES;
  498. // case NSFindPanelActionNext:
  499. // case NSFindPanelActionPrevious:
  500. // return YES;
  501. // case NSFindPanelActionSetFindString:
  502. // return [[[self pdfView] currentSelection] hasCharacters];
  503. // default:
  504. // return NO;
  505. // }
  506. // } else
  507. // if (action == @selector(highlightFormFiled:)) {
  508. // BOOL highlightFormFiled = [[NSUserDefaults standardUserDefaults] boolForKey:@"kPDFViewHighlightFormFiledKey"];
  509. // [menuItem setState:highlightFormFiled ? NSOnState : NSOffState];
  510. // return YES;
  511. // } else if (action == @selector(highlightLinks:)) {
  512. // BOOL highlightLinks = [[NSUserDefaults standardUserDefaults] boolForKey:@"kPDFViewHighlightLinksKey"];
  513. // [menuItem setState:highlightLinks ? NSOnState : NSOffState];
  514. // return YES;
  515. // } else if (action == @selector(link:)) {
  516. // return ([self.pdfView toolMode] == SKTextToolMode || [self.pdfView toolMode] == SKNoteToolMode) && [self.pdfView hideNotes] == NO && [self.pdfView.document isLocked] == NO;
  517. // return ([self.pdfView toolMode] == SKTextToolMode || [self.pdfView toolMode] == SKNoteToolMode) && [self.pdfView hideNotes] == NO && [self.pdfView.document isLocked] == NO && [[self.pdfView currentSelection] hasCharacters];
  518. // } else if (action == @selector(deletePage:)) {
  519. // return self.pdfView.document.pageCount > 1 ? YES : NO;
  520. // } else if (action == @selector(toggleAutoFlow:)) {
  521. // [menuItem setState:[self.pdfView isAutoFlow] ? NSOnState : NSOffState];
  522. // return YES;
  523. // } else if (action == @selector(themesColor:)){
  524. // if (KMPDFViewModeNormal== self.pdfView.viewMode) {
  525. // [menuItem setState:(menuItem.tag == 0)?NSOnState:NSOffState];
  526. // } else if (KMPDFViewModeSoft == self.pdfView.viewMode){
  527. // [menuItem setState:(menuItem.tag == 1)?NSOnState:NSOffState];
  528. // } else if (KMPDFViewModeNight == self.pdfView.viewMode){
  529. // [menuItem setState:(menuItem.tag == 2)?NSOnState:NSOffState];
  530. // } else if (KMPDFViewModeGreen == self.pdfView.viewMode){
  531. // [menuItem setState:(menuItem.tag == 3)?NSOnState:NSOffState];
  532. // } else if (KMPDFViewModeThemes1 == self.pdfView.viewMode){
  533. // [menuItem setState:(menuItem.tag == 4)?NSOnState:NSOffState];
  534. // } else if (KMPDFViewModeThemes2 == self.pdfView.viewMode){
  535. // [menuItem setState:(menuItem.tag == 5)?NSOnState:NSOffState];
  536. // } else if (KMPDFViewModeThemes3 == self.pdfView.viewMode){
  537. // [menuItem setState:(menuItem.tag == 6)?NSOnState:NSOffState];
  538. // } else if (KMPDFViewModeThemes4 == self.pdfView.viewMode){
  539. // [menuItem setState:(menuItem.tag == 7)?NSOnState:NSOffState];
  540. // }
  541. // // else {
  542. // // [menuItem setState:(menuItem.tag == 4)?NSOnState:NSOffState];
  543. // // }
  544. // NSData * data = [[NSUserDefaults standardUserDefaults] objectForKey:@"kKMPDFViewModeThemesArray"] ? : nil;
  545. // NSInteger themesCount;
  546. // if (data) {
  547. // NSArray * appArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  548. // NSMutableArray * mutableArray = [NSMutableArray arrayWithArray:appArray];
  549. // themesCount = [menuItem tag] - mutableArray.count;
  550. // } else {
  551. // themesCount = [menuItem tag] - 4;
  552. // }
  553. // if (themesCount >= 0) {
  554. // menuItem.hidden = YES;
  555. // return NO;
  556. // } else {
  557. // menuItem.hidden = NO;
  558. // return YES;
  559. // }
  560. // } else
  561. // if (action == @selector(splitViewAction:)){
  562. // if (KMPDFViewSplitModeHorizontal == self.pdfView.viewSplitMode) {
  563. // [menuItem setState:(menuItem.tag == 0)?NSOnState:NSOffState];
  564. // } else if (KMPDFViewSplitModeVertical == self.pdfView.viewSplitMode) {
  565. // [menuItem setState:(menuItem.tag == 1)?NSOnState:NSOffState];
  566. // } else if (KMPDFViewSplitModeDisable == self.pdfView.viewSplitMode) {
  567. // [menuItem setState:(menuItem.tag == 2)?NSOnState:NSOffState];
  568. // }
  569. // } else
  570. if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
  571. action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  572. action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
  573. action == #selector(outlineContextMenuItemClicked_RemoveEntry) ||
  574. action == #selector(outlineContextMenuItemClicked_Edit) ||
  575. action == #selector(outlineContextMenuItemClicked_SetDestination) ||
  576. action == #selector(outlineContextMenuItemClicked_Rename) ||
  577. action == #selector(outlineContextMenuItemClicked_Promote) ||
  578. action == #selector(outlineContextMenuItemClicked_Demote)) {
  579. if let data = self.listView.document?.isLocked, data {
  580. return false
  581. }
  582. if (self.isSearchOutlineMode) {
  583. if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
  584. action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  585. action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
  586. action == #selector(outlineContextMenuItemClicked_Edit) ||
  587. action == #selector(outlineContextMenuItemClicked_Rename)
  588. ) {
  589. return false
  590. }
  591. }
  592. if (self.tocOutlineView.selectedRowIndexes.count > 1) {
  593. if (menuItem.tag == KMOutlineViewMenuItemTag.remove.rawValue) {
  594. return true
  595. }
  596. return false
  597. } else if (self.tocOutlineView.selectedRowIndexes.count > 0) {
  598. if (action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  599. action == #selector(outlineContextMenuItemClicked_SetDestination)) {
  600. return true
  601. }
  602. }
  603. if (self.tocOutlineView.clickedRow == -1) {
  604. if (action == #selector(outlineContextMenuItemClicked_AddEntry)) {
  605. return true
  606. } else {
  607. return false
  608. }
  609. } else {
  610. let clickedOutline = self.tocOutlineView.item(atRow: self.tocOutlineView.clickedRow) as? CPDFOutline
  611. if let data = clickedOutline?.index, data > 0 {
  612. if (action == #selector(outlineContextMenuItemClicked_Demote)) {
  613. return true
  614. }
  615. } else {
  616. if (action == #selector(outlineContextMenuItemClicked_Demote)) {
  617. return false
  618. }
  619. }
  620. let parentOutLine = clickedOutline?.parent
  621. let grandparentOutLine = parentOutLine?.parent
  622. //if clicked PDFOutline 's parent exist
  623. if (grandparentOutLine != nil) {
  624. //and title is equla "add_AuntOutlineKey"
  625. if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
  626. return true
  627. } else if (action == #selector(outlineContextMenuItemClicked_Promote)){
  628. return true
  629. }
  630. } else {
  631. if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
  632. return false
  633. }else if (action == #selector(outlineContextMenuItemClicked_Promote)){
  634. return false
  635. }
  636. }
  637. }
  638. return true
  639. }
  640. // else
  641. // if ([menuItem action] == @selector(toggleEncryptFilePanel:)) {
  642. // [menuItem setTitle:NSLocalizedString(@"Set Passwords", @"Menu item title")];
  643. // NSURL *fileURL = [self.pdfView.document documentURL];
  644. // if (!fileURL) {
  645. // return YES;
  646. // }
  647. // PDFDocument *pdfDoc = [[[PDFDocument alloc] initWithURL:fileURL] autorelease];
  648. //
  649. // if ([pdfDoc isLocked]) {
  650. // [menuItem setTitle:NSLocalizedString(@"Remove Security", @"Menu item title")];
  651. // }
  652. // } else if (action == @selector(toggleToolbarShow:)) {
  653. // NSToolbar *toolbar = [self.window toolbar];
  654. // if ([toolbar isVisible])
  655. // [menuItem setTitle:NSLocalizedString(@"Hide Toolbar", @"Menu item title")];
  656. // else
  657. // [menuItem setTitle:NSLocalizedString(@"Show Toolbar", @"Menu item title")];
  658. // return YES;
  659. // } else if (action == @selector(readMode:)) {
  660. // menuItem.state = self.isReadMode ? NSControlStateValueOn : NSControlStateValueOff;
  661. // return YES;
  662. // } else if (action == @selector(addForm:)) {
  663. // return YES;
  664. // } else if (action == @selector(toggleOutlineCaseInsensitiveSearch:)){
  665. // [menuItem setState:self.outlineIgnoreCaseFlag?NSControlStateValueOn:NSControlStateValueOff];
  666. // return YES;
  667. // } else if (action == @selector(note_expandAllComments:) ||
  668. // action == @selector(note_foldAllComments:) ||
  669. // action == @selector(exportAnnotationNotes:) ||
  670. // action == @selector(leftSideEmptyAnnotationClick_DeleteAnnotation:) ||
  671. // action == @selector(removeAllAnnotations:)) {
  672. // if (@available(macOS 10.13, *)) {
  673. // if (notes.count == 0) {
  674. // return NO;
  675. // } else {
  676. // return YES;
  677. // }
  678. // } else {
  679. // if (action == @selector(note_expandAllComments:) ||
  680. // action == @selector(note_foldAllComments:)) {
  681. // return NO;
  682. // }
  683. // }
  684. // } else
  685. // if (action == @selector(unfoldNoteAction:) ||
  686. // action == @selector(foldNoteAction:)) {
  687. // NSInteger row = [rightSideController.noteOutlineView clickedRow];
  688. // NSArray *noteArr = [rightSideController.noteArrayController arrangedObjects];
  689. // PDFAnnotation *foldNote = (PDFAnnotation *)noteArr[row];
  690. // if (@available(macOS 10.13, *)) {
  691. // if ([foldNote isKindOfClass:[PDFAnnotationMarkup class]] ||
  692. // [foldNote isKindOfClass:[SKNPDFAnnotationNote class]]) {
  693. // return YES;
  694. // } else {
  695. // return NO;
  696. // }
  697. // } else {
  698. // return NO;
  699. // }
  700. // } else
  701. if (action == #selector(menuItemClick_ExportPNG) ||
  702. action == #selector(menuItemClick_ExportJPG) ||
  703. action == #selector(menuItemClick_ExportPDF)) {
  704. if (self.snapshotTableView.selectedRow == -1 ) {
  705. return false
  706. } else {
  707. return true
  708. }
  709. }
  710. // else if (action == @selector(editNoteFromTable:)) {
  711. // NSInteger row = [rightSideController.noteOutlineView clickedRow];
  712. // NSArray * noteArr = [rightSideController.noteArrayController arrangedObjects];
  713. // PDFAnnotation *foldNote = (PDFAnnotation *)noteArr[row];
  714. // if (@available(macOS 10.13, *)) {
  715. // if ([foldNote.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
  716. // return NO;
  717. // }
  718. // }
  719. // if ([foldNote isKindOfClass:[PDFAnnotationStamp class]] ||
  720. // [foldNote isKindOfClass:[KMAnnotationStamp class]]) {
  721. // return NO;
  722. // } else {
  723. // return YES;
  724. // }
  725. // }
  726. else if (action == #selector(menuItemClick_SelectAll)) {
  727. menuItem.state = self.snapshotListIsAllSelected() ? .on : .off
  728. return true
  729. }
  730. // else if (action == @selector(leftSideEmptyAnnotationClick_DeleteOutline:)) {
  731. // PDFOutline * item = [[pdfView document] outlineRoot];
  732. // if (self.isSearchOutlineMode) {
  733. // NSInteger num = 0;
  734. // for (NSUInteger i = 0; i < [item numberOfChildren]; i++) {
  735. // PDFOutline *outline = [item childAtIndex:i];
  736. // if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:outline]) {
  737. // num ++;
  738. // }
  739. // }
  740. // if (num > 0)
  741. // return YES;
  742. // else
  743. // return NO;
  744. // } else {
  745. // if ([item numberOfChildren] > 0)
  746. // return YES;
  747. // else
  748. // return NO;
  749. // }
  750. // }
  751. return true
  752. }
  753. }
  754. // MARK: - NSPopoverDelegate
  755. extension KMLeftSideViewController: NSPopoverDelegate {
  756. func popoverWillClose(_ notification: Notification) {
  757. guard let popover = notification.object as? NSPopover else {
  758. return
  759. }
  760. if let vc = popover.contentViewController as? KMOutlineEditViewController {
  761. self.editOutlineUI(vc)
  762. self.tocOutlineView.reloadData()
  763. }
  764. }
  765. }