KMLeftSideViewController+Action.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. //
  2. // KMLeftSideViewController+Action.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/12/22.
  6. //
  7. import Foundation
  8. // MARK: - Action
  9. extension KMLeftSideViewController {
  10. @IBAction func leftSideViewMoreButtonAction(_ sender: AnyObject?) {
  11. guard let button = sender as? NSButton else {
  12. NSSound.beep()
  13. return
  14. }
  15. let tag = button.tag
  16. if (tag == 300) {
  17. var selectedRow = 0
  18. if (self.snapshotTableView.selectedRow >= 0) {
  19. selectedRow = self.snapshotTableView.selectedRow;
  20. } else {
  21. return
  22. }
  23. let model = self.snapshots[selectedRow]
  24. let controller = model.windowC
  25. let menu = NSMenu()
  26. let itemExport = menu.addItem(title: KMLocalizedString("Export", "Menu item title"), action: nil, target: self)
  27. let subMenu = NSMenu()
  28. var t = subMenu.addItem(title: KMLocalizedString("PNG", "Menu item title"), action: #selector(menuItemClick_ExportPNG), target: self)
  29. t?.representedObject = controller
  30. t = subMenu.addItem(title: KMLocalizedString("JPG", "Menu item title"), action: #selector(menuItemClick_ExportJPG), target: self)
  31. t?.representedObject = controller
  32. t = subMenu.addItem(title: KMLocalizedString("PDF", "Menu item title"), action: #selector(menuItemClick_ExportPDF), target: self)
  33. t?.representedObject = controller
  34. itemExport?.submenu = subMenu
  35. let itemPrint = menu.addItem(title: KMLocalizedString("Print", "Menu item title"), action: #selector(menuItemClick_Print), target: self)
  36. itemPrint?.representedObject = controller
  37. menu.addItem(.separator())
  38. let itemSelectAll = menu.addItem(title: KMLocalizedString("Select All", "Menu item title"), action: #selector(menuItemClick_SelectAll), target: self)
  39. itemSelectAll?.representedObject = controller
  40. menu.addItem(.separator())
  41. let itemDeleteAllSnapshot = menu.addItem(title: KMLocalizedString("Delete All Snapshots", "Menu item title"), action: #selector(deleteAllSnapshot), target: self)
  42. itemDeleteAllSnapshot?.representedObject = controller
  43. if let data = NSApp.currentEvent {
  44. NSMenu.popUpContextMenu(menu, with: data, for: button)
  45. }
  46. } else if (tag == 302) {
  47. self.outlineMoreMenu(button)
  48. } else if (tag == 304) {
  49. self.annoListMoreMenu(button)
  50. }
  51. }
  52. func searchFieldChangeAction(_ editContent: String) {
  53. if self.findState == .note {
  54. self.updateNoteFilterPredicate()
  55. } else {
  56. self.updateSnapshotFilterPredicate()
  57. }
  58. if editContent.count > 0 {
  59. let findPboard = NSPasteboard(name: .find)
  60. findPboard.clearContents()
  61. findPboard.writeObjects([editContent as NSPasteboardWriting])
  62. }
  63. }
  64. @IBAction func search(_ sender: NSSearchField) {
  65. if sender.stringValue.isEmpty {
  66. self.applySearchTableHeader("")
  67. }
  68. self.delegate?.searchAction?(searchString: sender.stringValue, isCase: self.mwcFlags.caseInsensitiveSearch == 1)
  69. }
  70. // RefreshUI
  71. public func refreshUIForAddAnnotation(annos: [CPDFAnnotation]?, page: CPDFPage?) {
  72. self.updateThumbnail(at: Int(page?.pageIndex() ?? 0))
  73. self.note_reloadDataIfNeed()
  74. }
  75. public func refreshUIForAnnoAttributeDidChange(_ anno: CPDFAnnotation?, attributes: [String : Any]?) {
  76. if let data = anno {
  77. self.note_reloadDataForAnnoIfNeed(anno: data)
  78. }
  79. }
  80. public func annoList_refreshUIForDeleteAnnotations(annos: [CPDFAnnotation]?, page: CPDFPage?) {
  81. if self.type.methodType != .Annotation {
  82. return
  83. }
  84. for anno in annos ?? [] {
  85. if let model = self.fetchAnnoModel(for: anno) {
  86. self.noteSearchArray.removeObject(model)
  87. self.annoListModel?.datas.removeObject(model)
  88. }
  89. }
  90. if self.dataUpdating == false {
  91. self.note_refrshUIIfNeed()
  92. }
  93. }
  94. public func refreshUIForDocumentChanged() {
  95. if self.type.methodType == .Thumbnail {
  96. self.resetThumbnails(ks: false)
  97. } else if self.type.methodType == .Outline {
  98. Task { @MainActor in
  99. self.tocOutlineView.reloadData()
  100. }
  101. } else if self.type.methodType == .Annotation {
  102. self.note_reloadDataIfNeed()
  103. } else if self.type.methodType == .snapshot {
  104. self.reloadSnapshotDataIfNeed()
  105. } else if self.type.methodType == .Search {
  106. if self.searchField.stringValue.isEmpty == false {
  107. self.search(self.searchField)
  108. }
  109. }
  110. }
  111. }
  112. // MARK: - Double Action
  113. extension KMLeftSideViewController {
  114. @objc func toggleSelectedSnapshots(_ sender: AnyObject?) {
  115. let indexs = self.snapshotTableView.selectedRowIndexes
  116. if indexs.isEmpty {
  117. return
  118. }
  119. let model = self.snapshots[indexs.last!]
  120. let windowC = model.windowC
  121. if let data = windowC?.window?.isVisible, data {
  122. windowC?.miniaturize()
  123. } else {
  124. windowC?.deminiaturize()
  125. }
  126. var rowIndexSet = IndexSet()
  127. let row = self.snapshotTableView.selectedRow
  128. if row >= 0 && row < self.snapshots.count {
  129. rowIndexSet.insert(row)
  130. }
  131. var columnIndexSet = IndexSet()
  132. columnIndexSet.insert(0)
  133. self.snapshotTableView.reloadData(forRowIndexes: rowIndexSet, columnIndexes: columnIndexSet)
  134. }
  135. // MARK: - KMInterfaceThemeChangedProtocol
  136. override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
  137. super.interfaceThemeDidChanged(appearance)
  138. self.updateViewColor()
  139. self.leftView.interfaceThemeDidChanged(appearance)
  140. }
  141. }
  142. // MARK: - NSMenuDelegate
  143. extension KMLeftSideViewController: NSMenuDelegate {
  144. func menuNeedsUpdate(_ menu: NSMenu) {
  145. menu.removeAllItems()
  146. if menu.isEqual(to: self.tocOutlineView.menu) {
  147. self.outlineListMenu(menu)
  148. return
  149. }
  150. var item: NSMenuItem?
  151. if menu.isEqual(to: self.thumbnailTableView.menu) {
  152. let row = self.thumbnailTableView.clickedRow
  153. if self.pdfDocument()?.documentURL == nil || self.thumbnailTableView.selectedRowIndexes.contains(row) == false{
  154. return
  155. }
  156. let isLocked = self.isLocked()
  157. let pageCount = self.pageCount()
  158. if (row != -1 && isLocked == false) {
  159. if(self.thumbnailTableView.selectedRowIndexes.count == pageCount) {
  160. item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: nil, target: self)
  161. } else {
  162. item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: #selector(cutPage), target: self)
  163. }
  164. item?.representedObject = IndexSet(integer: row)
  165. item = menu.addItem(title: KMLocalizedString("Copy", "Menu item title"), action: #selector(copyPage), target: self)
  166. item?.representedObject = IndexSet(integer: row)
  167. if (self.copyPages.count > 0) {
  168. item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: #selector(pastePage), target: self)
  169. }else{
  170. item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: nil, target: self)
  171. }
  172. item?.representedObject = IndexSet(integer: row)
  173. menu.addItem(.separator())
  174. if(self.thumbnailTableView.selectedRowIndexes.count == pageCount) {
  175. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: nil, target: self)
  176. } else {
  177. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deletePage), target: self)
  178. }
  179. item?.representedObject = IndexSet(integer: row)
  180. menu.addItem(.separator())
  181. item = menu.addItem(title: KMLocalizedString("Rotate", "Menu item title"), action: #selector(rotatePageMenuAction), target: self)
  182. item?.representedObject = IndexSet(integer: row)
  183. item = menu.addItem(title: KMLocalizedString("Insert", "Menu item title"), action: nil, target: self)
  184. let subMenu = NSMenu()
  185. _ = subMenu.addItem(title: KMLocalizedString("Blank Page", "Menu item title"), action: #selector(quickInsert), target: self)
  186. _ = subMenu.addItem(title: KMLocalizedString("Blank Page - Custom...", "Menu item title"), action: #selector(insert), target: self)
  187. _ = subMenu.addItem(title: KMLocalizedString("From PDF", "Menu item title"), action: #selector(insertPDF), target: self)
  188. item?.submenu = subMenu
  189. item?.representedObject = IndexSet(integer: row)
  190. item = menu.addItem(title: KMLocalizedString("Extract", "Menu item title"), action: #selector(extractPage), target: self)
  191. item?.representedObject = IndexSet(integer: row)
  192. item = menu.addItem(title: KMLocalizedString("Page Edit", "Menu item title"), action: #selector(pageEdit), target: self)
  193. menu.addItem(.separator())
  194. var displayStr = ""
  195. if (self.isDisplayPageSize) {
  196. displayStr = KMLocalizedString("Hide Page Size", "Menu item title")
  197. } else {
  198. displayStr = KMLocalizedString("Display Page Size", "Menu item title")
  199. }
  200. item = menu.addItem(title: displayStr, action: #selector(displayPageSize), target: self)
  201. item?.representedObject = IndexSet(integer: row)
  202. if let doct = self.pdfDocument() {
  203. item = menu.addItem(title: KMLocalizedString("Share", "Menu item title"), action: nil, target: self)
  204. var tName = self.fileNameWithSelectedPages(self.thumbnailTableView.selectedRowIndexes)
  205. if (tName.count > 50) {
  206. tName = tName.substring(to: 50)
  207. }
  208. item?.submenu = NSSharingServicePicker.menu(forSharingItems: [doct.documentURL as Any], subjectContext: tName, withTarget: self, selector: #selector(sharePage), serviceDelegate: nil)
  209. }
  210. }
  211. } else if menu.isEqual(to: self.findTableView.menu) {
  212. var rowIndexes = self.findTableView.selectedRowIndexes
  213. let row = self.findTableView.clickedRow
  214. if (row != -1) {
  215. if rowIndexes.contains(row) == false {
  216. rowIndexes = IndexSet(integer: row)
  217. }
  218. var selections: [CPDFSelection] = []
  219. for (i, data) in self.searchResults.enumerated() {
  220. if rowIndexes.contains(i) {
  221. selections.append(data.selection)
  222. }
  223. }
  224. let hideNotes = self.hideNotes()
  225. let allowsNotes = self.allowsNotes()
  226. if hideNotes == false && allowsNotes {
  227. item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.circle.rawValue)
  228. item?.representedObject = selections
  229. item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.square.rawValue)
  230. item?.representedObject = selections
  231. item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.highlight.rawValue)
  232. item?.representedObject = selections
  233. item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.underline.rawValue)
  234. item?.representedObject = selections
  235. item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.strikeOut.rawValue)
  236. item?.representedObject = selections
  237. }
  238. }
  239. } else if menu.isEqual(to: self.groupedFindTableView.menu) {
  240. var rowIndexes = self.groupedFindTableView.selectedRowIndexes
  241. let row = self.groupedFindTableView.clickedRow
  242. if (row != -1) {
  243. if rowIndexes.contains(row) == false {
  244. rowIndexes = IndexSet(integer: row)
  245. }
  246. // NSArray *selections = [[[leftSideController.groupedFindArrayController arrangedObjects] objectsAtIndexes:rowIndexes] valueForKeyPath:@"@unionOfArrays.matches"];
  247. var selections: [CPDFSelection] = []
  248. for (i, data) in self.groupSearchResults.enumerated() {
  249. if rowIndexes.contains(i) {
  250. for searchM in data.datas {
  251. selections.append(searchM.selection)
  252. }
  253. }
  254. }
  255. item = menu.addItem(title: KMLocalizedString("Select", "Menu item title"), action: #selector(selectSelections), target: self)
  256. item?.representedObject = selections
  257. menu.addItem(.separator())
  258. let hideNotes = self.hideNotes()
  259. let allowsNotes = self.allowsNotes()
  260. if hideNotes == false && allowsNotes {
  261. item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.circle.rawValue)
  262. item?.representedObject = selections
  263. item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.square.rawValue)
  264. item?.representedObject = selections
  265. item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.highlight.rawValue)
  266. item?.representedObject = selections
  267. item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.underline.rawValue)
  268. item?.representedObject = selections
  269. item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.strikeOut.rawValue)
  270. item?.representedObject = selections
  271. }
  272. }
  273. } else if menu.isEqual(to: self.snapshotTableView.menu) {
  274. let row = self.snapshotTableView.clickedRow
  275. if (row != -1) {
  276. let model = self.snapshots[row]
  277. let controller = model.windowC
  278. if let data = controller?.window?.isVisible, data {
  279. item = menu.addItem(title: KMLocalizedString("Hide", "Menu item title"), action: #selector(hideSnapshot), target: self)
  280. item?.representedObject = controller
  281. } else {
  282. item = menu.addItem(title: KMLocalizedString("Show", "Menu item title"), action: #selector(showSnapshot), target: self)
  283. item?.representedObject = controller
  284. }
  285. menu.addItem(.separator())
  286. item = menu.addItem(title: KMLocalizedString("Export", "Menu item title"), action: nil, target: self)
  287. let subMenu = NSMenu()
  288. var t = subMenu.addItem(title: KMLocalizedString("PNG", "Menu item title"), action: #selector(menuItemClick_ExportPNG), target: self)
  289. t?.representedObject = controller
  290. t = subMenu.addItem(title: KMLocalizedString("JPG", "Menu item title"), action: #selector(menuItemClick_ExportJPG), target: self)
  291. t?.representedObject = controller
  292. t = subMenu.addItem(title: KMLocalizedString("PDF", "Menu item title"), action: #selector(menuItemClick_ExportPDF), target: self)
  293. t?.representedObject = controller
  294. item?.submenu = subMenu
  295. item = menu.addItem(title: KMLocalizedString("Print", "Menu item title"), action: #selector(menuItemClick_Print), target: self)
  296. item?.representedObject = controller
  297. menu.addItem(.separator())
  298. item = menu.addItem(title: KMLocalizedString("Copy", "Menu item title"), action: #selector(menuItemClick_Copy), target: self)
  299. item?.representedObject = controller
  300. menu.addItem(.separator())
  301. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteSnapshot), target: self)
  302. item?.representedObject = controller
  303. item = menu.addItem(title: KMLocalizedString("Delete All Snapshots", "Menu item title"), action: #selector(deleteAllSnapshot), target: self)
  304. item?.representedObject = controller
  305. }
  306. } else if menu.isEqual(to: self.noteOutlineView.menu) {
  307. self.annoListMenu(menu)
  308. }
  309. }
  310. }
  311. // MARK: - NSMenuItemValidation
  312. extension KMLeftSideViewController: NSMenuItemValidation {
  313. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  314. let isLocked = self.isLocked()
  315. if isLocked {
  316. return false
  317. }
  318. let action = menuItem.action
  319. if (action == #selector(toggleCaseInsensitiveSearch)) {
  320. let state = KMDataManager.ud_integer(forKey: SKCaseInsensitiveSearchKey)
  321. menuItem.state = state == 1 ? .on : .off
  322. return true
  323. } else if (action == #selector(toggleWholeWordSearch)) {
  324. menuItem.state = self.mwcFlags.wholeWordSearch == 1 ? .on : .off
  325. return true
  326. } else if action == #selector(toggleCaseInsensitiveNoteSearch) {
  327. menuItem.state = self.caseInsensitiveNoteSearch ? .on : .off
  328. return true
  329. }
  330. if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
  331. action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
  332. action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
  333. action == #selector(outlineContextMenuItemClicked_RemoveEntry) ||
  334. action == #selector(outlineContextMenuItemClicked_Edit) ||
  335. action == #selector(outlineContextMenuItemClicked_SetDestination) ||
  336. action == #selector(outlineContextMenuItemClicked_Rename) ||
  337. action == #selector(outlineContextMenuItemClicked_Promote) ||
  338. action == #selector(outlineContextMenuItemClicked_Demote) ||
  339. action == #selector(leftSideEmptyAnnotationClick_DeleteOutline)) { // 大纲列表
  340. return self.outlineListValidateMenuItem(menuItem)
  341. }
  342. if (action == #selector(note_expandAllComments) ||
  343. action == #selector(note_foldAllComments) ||
  344. action == #selector(exportAnnotationNotes) ||
  345. action == #selector(removeAllAnnotations) ||
  346. action == #selector(unfoldNoteAction) ||
  347. action == #selector(foldNoteAction) ||
  348. action == #selector(editNoteFromTable)) { // 注释列表
  349. return self.annoListValidateMenuItem(menuItem)
  350. }
  351. if (action == #selector(menuItemClick_ExportPNG) ||
  352. action == #selector(menuItemClick_ExportJPG) ||
  353. action == #selector(menuItemClick_ExportPDF)) {
  354. if (self.snapshotTableView.selectedRow == -1 ) {
  355. return false
  356. } else {
  357. return true
  358. }
  359. } else if (action == #selector(menuItemClick_SelectAll)) {
  360. menuItem.state = self.snapshotListIsAllSelected() ? .on : .off
  361. return true
  362. }
  363. return true
  364. }
  365. }
  366. // MARK: - NSPopoverDelegate
  367. extension KMLeftSideViewController: NSPopoverDelegate {
  368. func popoverWillClose(_ notification: Notification) {
  369. guard let popover = notification.object as? NSPopover else {
  370. return
  371. }
  372. if let vc = popover.contentViewController as? KMOutlineEditViewController {
  373. self.editOutlineUI(vc)
  374. self.tocOutlineView.reloadData()
  375. }
  376. }
  377. }
  378. // MARK: - NSSearchFieldDelegate
  379. extension KMLeftSideViewController: NSSearchFieldDelegate {
  380. func controlTextDidChange(_ obj: Notification) {
  381. if self.outlineSearchField.isEqual(to: obj.object) {
  382. if (self.outlineSearchField.stringValue.isEmpty == false) {
  383. self.isSearchOutlineMode = true
  384. self.tocOutlineView.reloadData()
  385. self.tocOutlineView.expandItem(nil, expandChildren: true)
  386. self.tocType = .unfold
  387. } else {
  388. self.isSearchOutlineMode = false
  389. self.showSearchOutlineBlankState(false)
  390. self.tocOutlineView.reloadData()
  391. }
  392. self.outlineAddButton.isEnabled = !self.isSearchOutlineMode
  393. } else if self.snapshotSearchField.isEqual(to: obj.object) {
  394. let searchString = self.snapshotSearchField.stringValue
  395. // NSPredicate *filterPredicate = nil;
  396. // if ([searchString length] > 0) {
  397. // NSExpression *lhs = [NSExpression expressionForConstantValue:searchString];
  398. // NSExpression *rhs = [NSExpression expressionForKeyPath:@"string"];
  399. // NSUInteger options = NSDiacriticInsensitivePredicateOption;
  400. // if (mwcFlags.caseInsensitiveNoteSearch)
  401. // options |= NSCaseInsensitivePredicateOption;
  402. // filterPredicate = [NSComparisonPredicate predicateWithLeftExpression:lhs rightExpression:rhs modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType options:options];
  403. // }
  404. // [rightSideController.snapshotArrayController setFilterPredicate:filterPredicate];
  405. // NSArray * snapshots = [rightSideController.snapshotArrayController arrangedObjects];
  406. self.searchSnapshots.removeAll()
  407. if searchString.isEmpty {
  408. self.isSearchSnapshotMode = false
  409. self.searchSnapshots = self.snapshots.filter({ model in
  410. let data = model.windowC?.string.contains(searchString) ?? false
  411. return data
  412. })
  413. } else {
  414. self.isSearchSnapshotMode = true
  415. }
  416. var snapshots = self.searchSnapshots
  417. if self.isSearchSnapshotMode == false {
  418. snapshots = self.snapshots
  419. }
  420. Task { @MainActor in
  421. self.updataLeftSideSnapView()
  422. self.snapshotTableView.reloadData()
  423. }
  424. if (snapshots.count > 0) {
  425. self.leftSideEmptyVC.outlineSearchView.removeFromSuperview()
  426. } else {
  427. let view = self.snapshotTableView.enclosingScrollView
  428. let viewFrmae = view?.frame ?? .zero
  429. let emptyVcSize = self.leftSideEmptyVC.outlineSearchView.frame.size
  430. self.leftSideEmptyVC.outlineSearchView.frame = NSMakeRect((viewFrmae.size.width-emptyVcSize.width)/2.0,(viewFrmae.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  431. self.leftSideEmptyVC.outlineSearchView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  432. self.snapshotTableView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.outlineSearchView)
  433. }
  434. } else if self.noteSearchField.isEqual(to: obj.object) {
  435. if let isEmpty = self.noteSearchField?.stringValue.isEmpty {
  436. self.noteSearchMode = !isEmpty
  437. } else {
  438. self.noteSearchMode = false
  439. }
  440. }
  441. }
  442. }
  443. // MARK: - NSTextFieldDelegate
  444. extension KMLeftSideViewController: NSTextFieldDelegate {
  445. func controlTextDidBeginEditing(_ obj: Notification) {
  446. if self.noteOutlineView.isEqual(to: obj.object) {
  447. // if (mwcFlags.isEditingTable == NO && mwcFlags.isEditingPDF == NO)
  448. // [[self document] objectDidBeginEditing:self];
  449. // mwcFlags.isEditingTable = YES;
  450. }
  451. }
  452. func controlTextDidEndEditing(_ obj: Notification) {
  453. if self.noteOutlineView.isEqual(to: obj.object) {
  454. // if (mwcFlags.isEditingTable && mwcFlags.isEditingPDF == NO)
  455. // [[self document] objectDidEndEditing:self];
  456. // mwcFlags.isEditingTable = NO;
  457. } else if let data = self.renamePDFOutlineTextField?.isEqual(to: obj.object), data {
  458. let tf = obj.object as! NSTextField
  459. if let ol = self.renamePDFOutline {
  460. if self.isRenameNoteOutline == false {
  461. if tf.stringValue == ol.label {
  462. return
  463. }
  464. }
  465. self.renamePDFOutline(ol, label: tf.stringValue)
  466. self.updateSelectRowHeight()
  467. self.tocOutlineView.reloadData()
  468. }
  469. }
  470. }
  471. }
  472. // MARK: - Menu Item Actions
  473. extension KMLeftSideViewController {
  474. @objc func toggleCaseInsensitiveNoteSearch(_ sender: AnyObject?) {
  475. self.caseInsensitiveNoteSearch = !self.caseInsensitiveNoteSearch
  476. if self.searchField.stringValue.isEmpty == false {
  477. self.searchNotes(self.searchField)
  478. }
  479. KMDataManager.ud_set(self.caseInsensitiveNoteSearch, forKey: SKCaseInsensitiveNoteSearchKey)
  480. }
  481. @objc func searchNotes(_ sender: AnyObject?) {
  482. self.noteSearchMode = false
  483. if self.findState == .note {
  484. if self.noteSearchField.isEqual(to: sender) {
  485. self.noteSearchMode = true
  486. }
  487. self.updateNoteFilterPredicate()
  488. } else {
  489. self.updateSnapshotFilterPredicate()
  490. }
  491. let textfield = sender as? NSSearchField
  492. if let data = textfield?.stringValue.isEmpty, data == false {
  493. let findPboard = NSPasteboard(name: .find)
  494. findPboard.clearContents()
  495. // findPboard.writeObjects([textfield!.stringValue])
  496. }
  497. }
  498. func updateSnapshotFilterPredicate() {
  499. let searchString = self.snapshotSearchField.stringValue
  500. self.searchSnapshots.removeAll()
  501. if self.findState == .snapshot && searchString.isEmpty == false {
  502. self.searchSnapshots = self.snapshots.filter({ model in
  503. let data = model.windowC?.string.contains(searchString) ?? false
  504. return data
  505. })
  506. }
  507. Task { @MainActor in
  508. self.updataLeftSideSnapView()
  509. self.snapshotTableView.reloadData()
  510. }
  511. }
  512. func snapshotListIsAllSelected() -> Bool {
  513. if self.snapshots.isEmpty {
  514. return false
  515. }
  516. for model in self.snapshots {
  517. if model.isSelected == false {
  518. return false
  519. }
  520. }
  521. return true
  522. }
  523. }