Browse Source

【BOTA】窗口关闭通知移除

lizhe 1 year ago
parent
commit
b6a78ae971

+ 21 - 7
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMAnnotationViewController.swift

@@ -50,6 +50,7 @@ class KMAnnotationViewController: KMSideViewController {
     
     deinit {
         print("KMAnnotationViewController")
+        self.removeNotification()
     }
     //MARK: View
         
@@ -120,6 +121,10 @@ class KMAnnotationViewController: KMSideViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(reloadDataAfter), name: NSNotification.Name.init(rawValue: "CPDFPageDidRemoveAnnotationNotification"), object: nil)
     }
     
+    func removeNotification() {
+        NotificationCenter.default.removeObserver(self)
+    }
+    
     public func clear() {
         self.annotations.removeAll()
         self.annotationOutlineView.reloadData()
@@ -274,7 +279,7 @@ extension KMAnnotationViewController {
         if !localEvent {
             self.reloadData()
         }
-        localEvent = false
+//        localEvent = false
     }
 
     @objc func documentPageCountChangedNotification(notification: NSNotification) {
@@ -283,7 +288,7 @@ extension KMAnnotationViewController {
             if !localEvent {
                 self.reloadData()
             }
-            localEvent = false
+//            localEvent = false
         }
     }
 
@@ -314,7 +319,7 @@ extension KMAnnotationViewController {
                         self.annotationOutlineView.didSelectItem(view: nil, event: NSEvent(), isNeedDelegate: false)
                     }
                 }
-                localEvent = false
+//                localEvent = false
             }
         }
     }
@@ -360,7 +365,7 @@ extension KMAnnotationViewController {
         let filterVC = KMNoteOutlineFilterViewController()
         filterVC.path = self.listView.document.documentURL.path
         filterVC.notesArray = self.allAnnotations
-        filterVC.applyFilterCallback = { typeArr, colorArr,authArr,isEmpty in
+        filterVC.applyFilterCallback = { [unowned self] (typeArr, colorArr,authArr,isEmpty) in
             menu.cancelTracking()
             self.annotationSort(sortArray: [typeArr!,colorArr!,authArr!])
         }
@@ -551,6 +556,7 @@ extension KMAnnotationViewController: KMAnnotationOutlineViewDelegate {
     func annotationOutlineView(_ outlineView: KMAnnotationOutlineView, didSelectItem: [KMBOTAAnnotationItem]) {
         self.localEvent = true
         self.updateListViewData(annotationItems: didSelectItem)
+        self.localEvent = false
     }
 }
 
@@ -698,6 +704,9 @@ extension KMAnnotationViewController : NSMenuDelegate, NSMenuItemValidation {
 //MARK: undo Redo
 extension KMAnnotationViewController {
     func deleteAnnotations(annotationItems: [KMBOTAAnnotationItem]) {
+        self.removeNotification()
+        self.localEvent = true
+        
         var removeAnnotations: [Any] = []
         var tempAnnotations: [KMBOTAAnnotationItem] = []
         for annotationItem in annotationItems {
@@ -705,7 +714,6 @@ extension KMAnnotationViewController {
             annotationItem.index = annotationItem.section?.annotations?.firstIndex(of: annotationItem)
             let page = annotation?.page
             if ((page?.annotations.contains(annotation!)) != nil) {
-                self.localEvent = true
                 page?.removeAnnotation(annotation)
                 annotationItem.section?.annotations?.removeObject(annotationItem)
             } else {
@@ -722,7 +730,6 @@ extension KMAnnotationViewController {
         }
         
         if removeAnnotations.count != 0 {
-            self.localEvent = true
             self.listView.activeAnnotations.remove(removeAnnotations)
         }
         self.listView.setNeedsDisplayForVisiblePages()
@@ -732,15 +739,20 @@ extension KMAnnotationViewController {
         self.listView.undoManager?.registerUndo(withTarget: self) { [unowned self] targetType in
             self.addAnnotations(annotationItems: tempAnnotations)
         }
+        
+        self.addNotification()
+        self.localEvent = false
     }
     
     func addAnnotations(annotationItems: [KMBOTAAnnotationItem]) {
+        self.removeNotification()
+        self.localEvent = true
+        
         var tempAnnotationItems: [KMBOTAAnnotationItem] = annotationItems
         tempAnnotationItems.sort(){$0.index ?? 0 < $1.index ?? 0}
         
         for annotationItem in tempAnnotationItems {
             if !annotationItem.annotation!.page.annotations.contains(annotationItem.annotation!) {
-                self.localEvent = true
                 annotationItem.annotation?.page.addAnnotation(annotationItem.annotation!)
                 annotationItem.section?.annotations?.insert(annotationItem, at: annotationItem.index ?? 0)
             }
@@ -761,6 +773,8 @@ extension KMAnnotationViewController {
             self.deleteAnnotations(annotationItems: tempAnnotations)
         }
         
+        self.addNotification()
+        self.localEvent = false
     }
     
     @IBAction func undo(_ sender: Any) {

+ 4 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/BookMarks/KMBookMarkViewController.swift

@@ -120,6 +120,10 @@ class KMBookMarkViewController: NSViewController, NSTextFieldDelegate {
         NotificationCenter.default.addObserver(self, selector: #selector(documentPageCountChangedNotification), name: NSNotification.Name.init(rawValue: "CPDFDocumentPageCountChangedNotification"), object: nil)
     }
     
+    func removeNotification() {
+        NotificationCenter.default.removeObserver(self)
+    }
+    
     private func addMenuTitle(view: NSView, event: NSEvent) {
         let menus : NSMenu = NSMenu(title: "")
         menus.delegate = self

+ 7 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -582,5 +582,12 @@ extension KMLeftSideViewController {
         userDefaults.set(authorData, forKey: "KMNoteOutlineFilterSelectArray_Author" + self.listView.document.documentURL.path)
         userDefaults.synchronize()
     }
+    
+    func clearNotification() {
+        self.bookViewController.removeNotification()
+        self.annotationViewController.removeNotification()
+        self.outlineViewController.removeNotification()
+        self.thumbnailViewController.removeNotification()
+    }
 }
 

+ 4 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Outline/KMOutlineViewController.swift

@@ -134,6 +134,10 @@ class KMOutlineViewController: NSViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(KMPDFViewCurrentPageDidChangedNotification), name: NSNotification.Name.init(rawValue: "KMPDFViewCurrentPageDidChanged"), object: nil)
     }
     
+    func removeNotification() {
+        NotificationCenter.default.removeObserver(self)
+    }
+    
     func reloadData() {
         self.BOTAOutlineView.reloadData(expandItemType: .none)
     }

+ 4 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMThumbnailViewController.swift

@@ -82,6 +82,10 @@ class KMThumbnailViewController: NSViewController {
         
     }
     
+    func removeNotification() {
+        NotificationCenter.default.removeObserver(self)
+    }
+    
     //MARK: Public Method
     func reloadData () {
         if self.doublePageMode {

+ 1 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -1546,6 +1546,7 @@ extension KMMainViewController {
         if tabController?.title == self.document?.documentURL.lastPathComponent {
             print("closeTab")
             self.leftSideViewController.clearAnnotationFilterData()
+            self.leftSideViewController.clearNotification()
         }
     }