KMLeftSideViewController+Action.swift 61 KB

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