KMLeftSideViewController+Thumbnail.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // KMLeftSideViewController+Thumbnail.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2024/1/12.
  6. //
  7. import Foundation
  8. // MARK: - Actions
  9. extension KMLeftSideViewController {
  10. public func refreshUIOfThumbnailIfNeed(preference: Bool = false) {
  11. if self.type.methodType != .Thumbnail {
  12. return
  13. }
  14. if preference {
  15. self.reloadThumbnailSize()
  16. }
  17. Task { @MainActor in
  18. self.thumbnailTableView.reloadData()
  19. }
  20. }
  21. public func reloadThumbnailDataIfNeed() {
  22. if self.type.methodType != .Thumbnail {
  23. return
  24. }
  25. self.resetThumbnails()
  26. }
  27. public func reloadThumbnailSize() {
  28. let defaultSize = roundf(KMPreference.shared.thumbPageSize)
  29. // var thumbnailSize = (defaultSize < TINY_SIZE + FUDGE_SIZE) ? TINY_SIZE : (defaultSize < SMALL_SIZE + FUDGE_SIZE) ? SMALL_SIZE : (defaultSize < LARGE_SIZE + FUDGE_SIZE) ? LARGE_SIZE : HUGE_SIZE
  30. var thumbnailSize = TINY_SIZE
  31. if defaultSize < TINY_SIZE + FUDGE_SIZE {
  32. } else {
  33. if defaultSize < SMALL_SIZE + FUDGE_SIZE {
  34. thumbnailSize = SMALL_SIZE
  35. } else {
  36. if defaultSize < LARGE_SIZE + FUDGE_SIZE {
  37. thumbnailSize = LARGE_SIZE
  38. } else {
  39. thumbnailSize = HUGE_SIZE
  40. }
  41. }
  42. }
  43. if (abs(thumbnailSize - Float(self.thumbnailCacheSize)) > FUDGE_SIZE) {
  44. self.thumbnailCacheSize = thumbnailSize.cgFloat
  45. }
  46. Task { @MainActor in
  47. self.thumbnailTableView.reloadData()
  48. }
  49. }
  50. // 显示缩略图模块
  51. func showThumbnail() {
  52. if self.leftView.segmentedControl.selectedSegment == 0 {
  53. } else {
  54. self.leftView.segmentedControl.selectedSegment = 0
  55. }
  56. }
  57. func updateThumbnail(at index: Int) {
  58. if index < self.thumbnails.count {
  59. self.thumbnails[index].dirty = true
  60. /*
  61. 原问题:CrashKit - SKMainWindowController updateThumbnailAtPageIndex:] ([__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond bounds [0 .. 17])
  62. 注释原因:缩略图高亮为自定义后,刷新会将高亮刷新到0行
  63. */
  64. // [leftSideController.thumbnailTableView reloadData];
  65. // BOOL visible = NO;
  66. // PDFPage *page = [[pdfView document] pageAtIndex:anIndex];
  67. // if([self.pdfView.visiblePages containsObject:page]) {
  68. // visible = YES;
  69. // }
  70. // NSInteger curIndex = [pdfView.document indexForPage:pdfView.currentPage];
  71. // if (need && curIndex != anIndex && !visible) {
  72. // [pdfView goToPage:[[pdfView document] pageAtIndex:anIndex]];
  73. // }
  74. }
  75. }
  76. func allThumbnailsNeedUpdate() {
  77. for thumb in self.thumbnails {
  78. thumb.dirty = true
  79. }
  80. self.reloadThumbnailSize()
  81. }
  82. func thumb_selectRowIndexsIfNeed(_ indexs: IndexSet) {
  83. if self.type.methodType != .Thumbnail {
  84. return
  85. }
  86. if indexs.isEmpty {
  87. return
  88. }
  89. Task { @MainActor in
  90. self.thumbnailTableView.selectRowIndexes(indexs, byExtendingSelection: false)
  91. self.thumbnailTableView.scrollRowToVisible(indexs.first ?? 0)
  92. }
  93. }
  94. }