KMLeftSideViewController+Action.swift 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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. 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. var 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 if (action == @selector(toggleWholeWordSearch:)) {
  500. // [menuItem setState:mwcFlags.wholeWordSearch ? NSOnState : NSOffState];
  501. // return YES;
  502. // } else if (action == @selector(toggleCaseInsensitiveNoteSearch:)) {
  503. // [menuItem setState:mwcFlags.caseInsensitiveNoteSearch ? NSOnState : NSOffState];
  504. // return YES;
  505. // } else if (action == @selector(toggleAutoResizeNoteRows:)) {
  506. // [menuItem setState:mwcFlags.autoResizeNoteRows ? NSOnState : NSOffState];
  507. // return YES;
  508. // } else if (action == @selector(performFindPanelAction:)) {
  509. // if ([self interactionMode] == SKPresentationMode)
  510. // return NO;
  511. // switch ([menuItem tag]) {
  512. // case NSFindPanelActionShowFindPanel:
  513. // return YES;
  514. // case NSFindPanelActionNext:
  515. // case NSFindPanelActionPrevious:
  516. // return YES;
  517. // case NSFindPanelActionSetFindString:
  518. // return [[[self pdfView] currentSelection] hasCharacters];
  519. // default:
  520. // return NO;
  521. // }
  522. // } else
  523. // if (action == @selector(highlightFormFiled:)) {
  524. // BOOL highlightFormFiled = [[NSUserDefaults standardUserDefaults] boolForKey:@"kPDFViewHighlightFormFiledKey"];
  525. // [menuItem setState:highlightFormFiled ? NSOnState : NSOffState];
  526. // return YES;
  527. // } else if (action == @selector(highlightLinks:)) {
  528. // BOOL highlightLinks = [[NSUserDefaults standardUserDefaults] boolForKey:@"kPDFViewHighlightLinksKey"];
  529. // [menuItem setState:highlightLinks ? NSOnState : NSOffState];
  530. // return YES;
  531. // } else if (action == @selector(link:)) {
  532. // return ([self.pdfView toolMode] == SKTextToolMode || [self.pdfView toolMode] == SKNoteToolMode) && [self.pdfView hideNotes] == NO && [self.pdfView.document isLocked] == NO;
  533. // return ([self.pdfView toolMode] == SKTextToolMode || [self.pdfView toolMode] == SKNoteToolMode) && [self.pdfView hideNotes] == NO && [self.pdfView.document isLocked] == NO && [[self.pdfView currentSelection] hasCharacters];
  534. // } else if (action == @selector(deletePage:)) {
  535. // return self.pdfView.document.pageCount > 1 ? YES : NO;
  536. // } else if (action == @selector(toggleAutoFlow:)) {
  537. // [menuItem setState:[self.pdfView isAutoFlow] ? NSOnState : NSOffState];
  538. // return YES;
  539. // } else if (action == @selector(themesColor:)){
  540. // if (KMPDFViewModeNormal== self.pdfView.viewMode) {
  541. // [menuItem setState:(menuItem.tag == 0)?NSOnState:NSOffState];
  542. // } else if (KMPDFViewModeSoft == self.pdfView.viewMode){
  543. // [menuItem setState:(menuItem.tag == 1)?NSOnState:NSOffState];
  544. // } else if (KMPDFViewModeNight == self.pdfView.viewMode){
  545. // [menuItem setState:(menuItem.tag == 2)?NSOnState:NSOffState];
  546. // } else if (KMPDFViewModeGreen == self.pdfView.viewMode){
  547. // [menuItem setState:(menuItem.tag == 3)?NSOnState:NSOffState];
  548. // } else if (KMPDFViewModeThemes1 == self.pdfView.viewMode){
  549. // [menuItem setState:(menuItem.tag == 4)?NSOnState:NSOffState];
  550. // } else if (KMPDFViewModeThemes2 == self.pdfView.viewMode){
  551. // [menuItem setState:(menuItem.tag == 5)?NSOnState:NSOffState];
  552. // } else if (KMPDFViewModeThemes3 == self.pdfView.viewMode){
  553. // [menuItem setState:(menuItem.tag == 6)?NSOnState:NSOffState];
  554. // } else if (KMPDFViewModeThemes4 == self.pdfView.viewMode){
  555. // [menuItem setState:(menuItem.tag == 7)?NSOnState:NSOffState];
  556. // }
  557. // // else {
  558. // // [menuItem setState:(menuItem.tag == 4)?NSOnState:NSOffState];
  559. // // }
  560. // NSData * data = [[NSUserDefaults standardUserDefaults] objectForKey:@"kKMPDFViewModeThemesArray"] ? : nil;
  561. // NSInteger themesCount;
  562. // if (data) {
  563. // NSArray * appArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  564. // NSMutableArray * mutableArray = [NSMutableArray arrayWithArray:appArray];
  565. // themesCount = [menuItem tag] - mutableArray.count;
  566. // } else {
  567. // themesCount = [menuItem tag] - 4;
  568. // }
  569. // if (themesCount >= 0) {
  570. // menuItem.hidden = YES;
  571. // return NO;
  572. // } else {
  573. // menuItem.hidden = NO;
  574. // return YES;
  575. // }
  576. // } else
  577. // if (action == @selector(splitViewAction:)){
  578. // if (KMPDFViewSplitModeHorizontal == self.pdfView.viewSplitMode) {
  579. // [menuItem setState:(menuItem.tag == 0)?NSOnState:NSOffState];
  580. // } else if (KMPDFViewSplitModeVertical == self.pdfView.viewSplitMode) {
  581. // [menuItem setState:(menuItem.tag == 1)?NSOnState:NSOffState];
  582. // } else if (KMPDFViewSplitModeDisable == self.pdfView.viewSplitMode) {
  583. // [menuItem setState:(menuItem.tag == 2)?NSOnState:NSOffState];
  584. // }
  585. // } else
  586. if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
  587. action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  588. action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
  589. action == #selector(outlineContextMenuItemClicked_RemoveEntry) ||
  590. action == #selector(outlineContextMenuItemClicked_Edit) ||
  591. action == #selector(outlineContextMenuItemClicked_SetDestination) ||
  592. action == #selector(outlineContextMenuItemClicked_Rename) ||
  593. action == #selector(outlineContextMenuItemClicked_Promote) ||
  594. action == #selector(outlineContextMenuItemClicked_Demote)) {
  595. if let data = self.listView.document?.isLocked, data {
  596. return false
  597. }
  598. if (self.isSearchOutlineMode) {
  599. if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
  600. action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  601. action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
  602. action == #selector(outlineContextMenuItemClicked_Edit) ||
  603. action == #selector(outlineContextMenuItemClicked_Rename)
  604. ) {
  605. return false
  606. }
  607. }
  608. if (self.tocOutlineView.selectedRowIndexes.count > 1) {
  609. if (menuItem.tag == KMOutlineViewMenuItemTag.remove.rawValue) {
  610. return true
  611. }
  612. return false
  613. } else if (self.tocOutlineView.selectedRowIndexes.count > 0) {
  614. if (action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  615. action == #selector(outlineContextMenuItemClicked_SetDestination)) {
  616. return true
  617. }
  618. }
  619. if (self.tocOutlineView.clickedRow == -1) {
  620. if (action == #selector(outlineContextMenuItemClicked_AddEntry)) {
  621. return true
  622. } else {
  623. return false
  624. }
  625. } else {
  626. let clickedOutline = self.tocOutlineView.item(atRow: self.tocOutlineView.clickedRow) as? CPDFOutline
  627. if let data = clickedOutline?.index, data > 0 {
  628. if (action == #selector(outlineContextMenuItemClicked_Demote)) {
  629. return true
  630. }
  631. } else {
  632. if (action == #selector(outlineContextMenuItemClicked_Demote)) {
  633. return false
  634. }
  635. }
  636. let parentOutLine = clickedOutline?.parent
  637. let grandparentOutLine = parentOutLine?.parent
  638. //if clicked PDFOutline 's parent exist
  639. if (grandparentOutLine != nil) {
  640. //and title is equla "add_AuntOutlineKey"
  641. if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
  642. return true
  643. } else if (action == #selector(outlineContextMenuItemClicked_Promote)){
  644. return true
  645. }
  646. } else {
  647. if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
  648. return false
  649. }else if (action == #selector(outlineContextMenuItemClicked_Promote)){
  650. return false
  651. }
  652. }
  653. }
  654. return true
  655. }
  656. // else
  657. // if ([menuItem action] == @selector(toggleEncryptFilePanel:)) {
  658. // [menuItem setTitle:NSLocalizedString(@"Set Passwords", @"Menu item title")];
  659. // NSURL *fileURL = [self.pdfView.document documentURL];
  660. // if (!fileURL) {
  661. // return YES;
  662. // }
  663. // PDFDocument *pdfDoc = [[[PDFDocument alloc] initWithURL:fileURL] autorelease];
  664. //
  665. // if ([pdfDoc isLocked]) {
  666. // [menuItem setTitle:NSLocalizedString(@"Remove Security", @"Menu item title")];
  667. // }
  668. // } else if (action == @selector(toggleToolbarShow:)) {
  669. // NSToolbar *toolbar = [self.window toolbar];
  670. // if ([toolbar isVisible])
  671. // [menuItem setTitle:NSLocalizedString(@"Hide Toolbar", @"Menu item title")];
  672. // else
  673. // [menuItem setTitle:NSLocalizedString(@"Show Toolbar", @"Menu item title")];
  674. // return YES;
  675. // } else if (action == @selector(readMode:)) {
  676. // menuItem.state = self.isReadMode ? NSControlStateValueOn : NSControlStateValueOff;
  677. // return YES;
  678. // } else if (action == @selector(addForm:)) {
  679. // return YES;
  680. // } else if (action == @selector(toggleOutlineCaseInsensitiveSearch:)){
  681. // [menuItem setState:self.outlineIgnoreCaseFlag?NSControlStateValueOn:NSControlStateValueOff];
  682. // return YES;
  683. // } else if (action == @selector(note_expandAllComments:) ||
  684. // action == @selector(note_foldAllComments:) ||
  685. // action == @selector(exportAnnotationNotes:) ||
  686. // action == @selector(leftSideEmptyAnnotationClick_DeleteAnnotation:) ||
  687. // action == @selector(removeAllAnnotations:)) {
  688. // if (@available(macOS 10.13, *)) {
  689. // if (notes.count == 0) {
  690. // return NO;
  691. // } else {
  692. // return YES;
  693. // }
  694. // } else {
  695. // if (action == @selector(note_expandAllComments:) ||
  696. // action == @selector(note_foldAllComments:)) {
  697. // return NO;
  698. // }
  699. // }
  700. // } else
  701. if (action == #selector(unfoldNoteAction) ||
  702. action == #selector(foldNoteAction)) {
  703. let row = self.noteOutlineView.clickedRow
  704. // NSArray *noteArr = [rightSideController.noteArrayController arrangedObjects];
  705. // PDFAnnotation *foldNote = (PDFAnnotation *)noteArr[row];
  706. let foldNote = self.allAnnotations[row]
  707. // SKNPDFAnnotationNote
  708. if foldNote is CPDFMarkupAnnotation || foldNote is CPDFTextAnnotation {
  709. return true
  710. } else {
  711. return false
  712. }
  713. } else if (action == #selector(menuItemClick_ExportPNG) ||
  714. action == #selector(menuItemClick_ExportJPG) ||
  715. action == #selector(menuItemClick_ExportPDF)) {
  716. if (self.snapshotTableView.selectedRow == -1 ) {
  717. return false
  718. } else {
  719. return true
  720. }
  721. }
  722. // else if (action == @selector(editNoteFromTable:)) {
  723. // NSInteger row = [rightSideController.noteOutlineView clickedRow];
  724. // NSArray * noteArr = [rightSideController.noteArrayController arrangedObjects];
  725. // PDFAnnotation *foldNote = (PDFAnnotation *)noteArr[row];
  726. // if (@available(macOS 10.13, *)) {
  727. // if ([foldNote.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
  728. // return NO;
  729. // }
  730. // }
  731. // if ([foldNote isKindOfClass:[PDFAnnotationStamp class]] ||
  732. // [foldNote isKindOfClass:[KMAnnotationStamp class]]) {
  733. // return NO;
  734. // } else {
  735. // return YES;
  736. // }
  737. // }
  738. else if (action == #selector(menuItemClick_SelectAll)) {
  739. menuItem.state = self.snapshotListIsAllSelected() ? .on : .off
  740. return true
  741. }
  742. // else if (action == @selector(leftSideEmptyAnnotationClick_DeleteOutline:)) {
  743. // PDFOutline * item = [[pdfView document] outlineRoot];
  744. // if (self.isSearchOutlineMode) {
  745. // NSInteger num = 0;
  746. // for (NSUInteger i = 0; i < [item numberOfChildren]; i++) {
  747. // PDFOutline *outline = [item childAtIndex:i];
  748. // if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:outline]) {
  749. // num ++;
  750. // }
  751. // }
  752. // if (num > 0)
  753. // return YES;
  754. // else
  755. // return NO;
  756. // } else {
  757. // if ([item numberOfChildren] > 0)
  758. // return YES;
  759. // else
  760. // return NO;
  761. // }
  762. // }
  763. return true
  764. }
  765. }
  766. // MARK: - NSPopoverDelegate
  767. extension KMLeftSideViewController: NSPopoverDelegate {
  768. func popoverWillClose(_ notification: Notification) {
  769. guard let popover = notification.object as? NSPopover else {
  770. return
  771. }
  772. if let vc = popover.contentViewController as? KMOutlineEditViewController {
  773. self.editOutlineUI(vc)
  774. self.tocOutlineView.reloadData()
  775. }
  776. }
  777. }
  778. // MARK: - NSSearchFieldDelegate
  779. extension KMLeftSideViewController: NSSearchFieldDelegate {
  780. func controlTextDidChange(_ obj: Notification) {
  781. if self.outlineSearchField.isEqual(to: obj.object) {
  782. if (self.outlineSearchField.stringValue.isEmpty == false) {
  783. self.isSearchOutlineMode = true
  784. self.tocOutlineView.reloadData()
  785. self.tocOutlineView.expandItem(nil, expandChildren: true)
  786. self.tocType = .unfold
  787. } else {
  788. self.isSearchOutlineMode = false
  789. self.showSearchOutlineBlankState(false)
  790. self.tocOutlineView.reloadData()
  791. }
  792. // self.leftSideEmptyVC.addOutlineBtn.enabled = !self.isSearchOutlineMode;
  793. self.outlineAddButton.isEnabled = !self.isSearchOutlineMode
  794. } else if self.snapshotSearchField.isEqual(to: obj.object) {
  795. let searchString = self.snapshotSearchField.stringValue
  796. // NSPredicate *filterPredicate = nil;
  797. // if ([searchString length] > 0) {
  798. // NSExpression *lhs = [NSExpression expressionForConstantValue:searchString];
  799. // NSExpression *rhs = [NSExpression expressionForKeyPath:@"string"];
  800. // NSUInteger options = NSDiacriticInsensitivePredicateOption;
  801. // if (mwcFlags.caseInsensitiveNoteSearch)
  802. // options |= NSCaseInsensitivePredicateOption;
  803. // filterPredicate = [NSComparisonPredicate predicateWithLeftExpression:lhs rightExpression:rhs modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType options:options];
  804. // }
  805. // [rightSideController.snapshotArrayController setFilterPredicate:filterPredicate];
  806. // NSArray * snapshots = [rightSideController.snapshotArrayController arrangedObjects];
  807. self.searchSnapshots.removeAll()
  808. if searchString.isEmpty {
  809. self.isSearchSnapshotMode = false
  810. self.searchSnapshots = self.snapshots.filter({ model in
  811. let data = model.windowC?.string.contains(searchString) ?? false
  812. return data
  813. })
  814. } else {
  815. self.isSearchSnapshotMode = true
  816. }
  817. var snapshots = self.searchSnapshots
  818. if self.isSearchSnapshotMode == false {
  819. snapshots = self.snapshots
  820. }
  821. Task { @MainActor in
  822. self.updataLeftSideSnapView()
  823. self.snapshotTableView.reloadData()
  824. }
  825. if (snapshots.count > 0) {
  826. self.leftSideEmptyVC.outlineSearchView.removeFromSuperview()
  827. } else {
  828. let view = self.snapshotTableView.enclosingScrollView
  829. let emptyVcSize = self.leftSideEmptyVC.outlineSearchView.frame.size
  830. 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)
  831. self.leftSideEmptyVC.outlineSearchView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  832. self.snapshotTableView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.outlineSearchView)
  833. }
  834. }
  835. }
  836. }
  837. // MARK: - NSTextFieldDelegate
  838. extension KMLeftSideViewController: NSTextFieldDelegate {
  839. func controlTextDidBeginEditing(_ obj: Notification) {
  840. if self.noteOutlineView.isEqual(to: obj.object) {
  841. // if (mwcFlags.isEditingTable == NO && mwcFlags.isEditingPDF == NO)
  842. // [[self document] objectDidBeginEditing:self];
  843. // mwcFlags.isEditingTable = YES;
  844. }
  845. }
  846. func controlTextDidEndEditing(_ obj: Notification) {
  847. if self.noteOutlineView.isEqual(to: obj.object) {
  848. // if (mwcFlags.isEditingTable && mwcFlags.isEditingPDF == NO)
  849. // [[self document] objectDidEndEditing:self];
  850. // mwcFlags.isEditingTable = NO;
  851. } else if let data = self.renamePDFOutlineTextField?.isEqual(to: obj.object), data {
  852. let textField = obj.object as! NSTextField
  853. if let editPDFOutline = self.renamePDFOutline {
  854. if self.isRenameNoteOutline == false {
  855. if textField.stringValue == editPDFOutline.label {
  856. return
  857. }
  858. }
  859. self.renamePDFOutline(editPDFOutline, label: textField.stringValue)
  860. // [self updateSelectRowHeight];
  861. self.tocOutlineView.reloadData()
  862. }
  863. }
  864. }
  865. }