123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- //
- // KMLeftSideViewController+Thumbnail.swift
- // PDF Master
- //
- // Created by tangchao on 2024/1/12.
- //
- import Foundation
- // MARK: - Actions
- extension KMLeftSideViewController {
- public func refreshUIOfThumbnailIfNeed(preference: Bool = false) {
- if self.type.methodType != .Thumbnail {
- return
- }
- if preference {
- self.reloadThumbnailSize()
- }
-
- Task { @MainActor in
- self.thumbnailTableView.reloadData()
- }
- }
-
- public func reloadThumbnailDataIfNeed() {
- if self.type.methodType != .Thumbnail {
- return
- }
- self.resetThumbnails()
- }
-
- public func reloadThumbnailSize() {
- let defaultSize = roundf(KMPreference.shared.thumbPageSize)
- // 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
- var thumbnailSize = TINY_SIZE
- if defaultSize < TINY_SIZE + FUDGE_SIZE {
-
- } else {
- if defaultSize < SMALL_SIZE + FUDGE_SIZE {
- thumbnailSize = SMALL_SIZE
- } else {
- if defaultSize < LARGE_SIZE + FUDGE_SIZE {
- thumbnailSize = LARGE_SIZE
- } else {
- thumbnailSize = HUGE_SIZE
- }
- }
- }
-
- if (abs(thumbnailSize - Float(self.thumbnailCacheSize)) > FUDGE_SIZE) {
- self.thumbnailCacheSize = thumbnailSize.cgFloat
- }
-
- Task { @MainActor in
- self.thumbnailTableView.reloadData()
- }
- }
-
- // 显示缩略图模块
- func showThumbnail() {
- if self.leftView.segmentedControl.selectedSegment == 0 {
-
- } else {
- self.leftView.segmentedControl.selectedSegment = 0
- }
- }
-
- func updateThumbnail(at index: Int) {
- if index < self.thumbnails.count {
- self.thumbnails[index].dirty = true
-
- /*
- 原问题:CrashKit - SKMainWindowController updateThumbnailAtPageIndex:] ([__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond bounds [0 .. 17])
- 注释原因:缩略图高亮为自定义后,刷新会将高亮刷新到0行
- */
- // [leftSideController.thumbnailTableView reloadData];
- // BOOL visible = NO;
- // PDFPage *page = [[pdfView document] pageAtIndex:anIndex];
- // if([self.pdfView.visiblePages containsObject:page]) {
- // visible = YES;
- // }
- // NSInteger curIndex = [pdfView.document indexForPage:pdfView.currentPage];
- // if (need && curIndex != anIndex && !visible) {
- // [pdfView goToPage:[[pdfView document] pageAtIndex:anIndex]];
- // }
- }
- }
-
- func allThumbnailsNeedUpdate() {
- for thumb in self.thumbnails {
- thumb.dirty = true
- }
- self.reloadThumbnailSize()
- }
-
- func thumb_selectRowIndexsIfNeed(_ indexs: IndexSet) {
- if self.type.methodType != .Thumbnail {
- return
- }
-
- if indexs.isEmpty {
- return
- }
-
- Task { @MainActor in
- self.thumbnailTableView.selectRowIndexes(indexs, byExtendingSelection: false)
- self.thumbnailTableView.scrollRowToVisible(indexs.first ?? 0)
- }
- }
- }
|