KMLeftSideViewController+Action.swift 60 KB

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