Forráskód Böngészése

【BOTA】缩略图刷新问题优化

lizhe 1 éve
szülő
commit
3fc9d3b3f6

+ 3 - 0
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -424,6 +424,8 @@ class KMPDFEditViewController: NSViewController {
             self.undoRedoManager.registerUndo(withTarget: self, selector: #selector(rightRotate), object: indexs)
             
             self.refreshUIForKeepSelecteds(indexs: indexs)
+            
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMPDFViewRotatePage"), object: self.listView?.document)
         }
     }
     
@@ -456,6 +458,7 @@ class KMPDFEditViewController: NSViewController {
             self.undoRedoManager.registerUndo(withTarget: self, selector: #selector(leftRotate), object: indexs)
             
             self.refreshUIForKeepSelecteds(indexs: indexs)
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMPDFViewRotatePage"), object: self.listView?.document)
         }
     }
     

+ 37 - 22
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMThumbnailViewController.swift

@@ -47,6 +47,16 @@ class KMThumbnailViewController: NSViewController {
         NotificationCenter.default.removeObserver(self)
         print("KMThumbnailViewController 释放")
     }
+    
+    override func viewWillAppear() {
+        super.viewWillAppear()
+        self.thumbnailView.reloadData()
+    }
+    
+    override func centerSelectionInVisibleArea(_ sender: Any?) {
+        super.centerSelectionInVisibleArea(sender)
+    }
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         self.view.wantsLayer = true
@@ -88,7 +98,6 @@ class KMThumbnailViewController: NSViewController {
         
         NotificationCenter.default.addObserver(self, selector: #selector(AnnotationDidChangeNoti), name: NSNotification.Name.init(rawValue: "CPDFPageDidAddAnnotationNotification"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(AnnotationDidChangeNoti), name: NSNotification.Name.init(rawValue: "CPDFPageDidRemoveAnnotationNotification"), object: nil)
-        
     }
     
     func removeNotification() {
@@ -184,37 +193,43 @@ class KMThumbnailViewController: NSViewController {
     
     //MARK: Noti
     @objc func KMPDFViewCurrentPageDidChangedNotification(notification: NSNotification) {
-        let pdfdocument : CPDFDocument = notification.object as! CPDFDocument
-        if pdfdocument.isEqual(self.listView.document) {
-            if !isLocalEvent {
-//                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { [unowned self] in
-                    self.pdfCurrentPageChange()
-                    self.delegate?.pageDidSelect?(controller: self, pages: [self.listView.currentPageIndex])
-//                }
+        if notification.object is CPDFDocument {
+            let pdfdocument : CPDFDocument = notification.object as! CPDFDocument
+            if pdfdocument.isEqual(self.listView.document) {
+                if !isLocalEvent {
+    //                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { [unowned self] in
+                        self.pdfCurrentPageChange()
+                        self.delegate?.pageDidSelect?(controller: self, pages: [self.listView.currentPageIndex])
+    //                }
+                }
+                isLocalEvent = false
             }
-            isLocalEvent = false
         }
     }
     
     @objc func KMPDFViewPageCountChangedNotification(notification: NSNotification) {
-        let pdfdocument : CPDFDocument = notification.object as! CPDFDocument
-        if pdfdocument.isEqual(self.listView.document) {
-            if !isLocalEvent {
-//                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { [unowned self] in
-                    self.reloadData()
-//                }
+        if notification.object is CPDFDocument {
+            let pdfdocument : CPDFDocument = notification.object as! CPDFDocument
+            if pdfdocument.isEqual(self.listView.document) {
+                if !isLocalEvent {
+    //                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { [unowned self] in
+                        self.reloadData()
+    //                }
+                }
+                isLocalEvent = false
             }
-            isLocalEvent = false
         }
     }
     
     @objc func AnnotationDidChangeNoti(notification: NSNotification) {
-        let pdfAnnotation : CPDFAnnotation = notification.object as! CPDFAnnotation
-        
-        if (pdfAnnotation.page != nil) {
-            var indexs: IndexSet = IndexSet()
-            indexs.insert(IndexSet.Element(pdfAnnotation.page.pageIndex()))
-            self.reloadDataAtIndexs(indexs: indexs)
+        if notification.object is CPDFAnnotation {
+            let pdfAnnotation : CPDFAnnotation = notification.object as! CPDFAnnotation
+            
+            if (pdfAnnotation.page != nil) {
+                var indexs: IndexSet = IndexSet()
+                indexs.insert(IndexSet.Element(pdfAnnotation.page.pageIndex()))
+                self.reloadDataAtIndexs(indexs: indexs)
+            }
         }
     }