Bläddra i källkod

【注释回复】补充刷选type

tangchao 1 månad sedan
förälder
incheckning
aac00ae0af

+ 39 - 13
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/Controller/KMNoteOutlineFilterViewController.swift

@@ -11,6 +11,7 @@ extension KMNoteOutlineFilterViewController {
     static let filterSelectTypeKey = "KMNoteOutlineFilterSelectArray_Type"
     static let filterSelectAuthorKey = "KMNoteOutlineFilterSelectArray_Author"
     static let filterSelectColorKey = "KMNoteOutlineFilterSelectArray_Color"
+    static let filterSelectStateKey = "KMNoteOutlineFilterSelectArray_State"
 }
 
 typealias NoteFilterVC = KMNoteOutlineFilterViewController
@@ -161,6 +162,7 @@ class KMNoteOutlineFilterViewController: NSViewController {
     var selectTypeArray: NSMutableArray?
     var selectColorArray: NSMutableArray?
     var selectAuthorArray: NSMutableArray?
+    var selectStateArray: NSMutableArray?
     
     @IBOutlet weak var typeLabel: NSTextField!
     @IBOutlet weak var filterButtonView: NSView!
@@ -316,6 +318,16 @@ class KMNoteOutlineFilterViewController: NSViewController {
             self.selectAuthorArray = NSMutableArray()
         }
         
+        if let data = sud.object(forKey: Self.filterSelectStateKey + (self.listView?.document?.documentURL.path ?? "")) as? NSData {
+            if let array = NSKeyedUnarchiver.unarchiveObject(with: data as Data) as? NSArray {
+                self.selectAuthorArray = NSMutableArray(array: array)
+            }
+        }
+        
+        if self.selectStateArray == nil {
+            self.selectStateArray = NSMutableArray()
+        }
+        
         self.mainScrollView.documentView?.addSubview(self.stateLabel)
         self.stateLabel.mas_makeConstraints { make in
             make?.leading.equalTo()(16)
@@ -355,10 +367,12 @@ class KMNoteOutlineFilterViewController: NSViewController {
         self.selectAuthorArray?.removeAllObjects()
         self.selectColorArray?.removeAllObjects()
         self.selectTypeArray?.removeAllObjects()
+        self.selectStateArray?.removeAllObjects()
         
         self.authorCollectionView.reloadData()
         self.colorCollectionView.reloadData()
         self.typeCollectionView.reloadData()
+        self.collectionView.reloadData()
     }
     
     @IBAction func cancelButtonAction(_ sender: NSButton) {
@@ -371,11 +385,13 @@ class KMNoteOutlineFilterViewController: NSViewController {
         let data1 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: self.selectTypeArray!))
         let data2 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: self.selectColorArray!))
         let data3 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: self.selectAuthorArray!))
+        let data4 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: self.selectStateArray!))
         
         let sud = UserDefaults.standard
         sud.set(data1, forKey: Self.filterSelectTypeKey + (self.listView?.document?.documentURL.path ?? ""))
         sud.set(data2, forKey: Self.filterSelectColorKey + (self.listView?.document?.documentURL.path ?? ""))
         sud.set(data3, forKey: Self.filterSelectAuthorKey + (self.listView?.document?.documentURL.path ?? ""))
+        sud.set(data4, forKey: Self.filterSelectStateKey + (self.listView?.document?.documentURL.path ?? ""))
         sud.synchronize()
         
         var isEmpty = false
@@ -391,6 +407,11 @@ class KMNoteOutlineFilterViewController: NSViewController {
         if (self.selectAuthorArray!.count == 0) {
             self.selectAuthorArray = self._authorMutableArray
         }
+        if (self.selectStateArray!.count == 0) {
+            for state in stateArray_ {
+                self.selectStateArray?.add(NSNumber(value: state.rawValue))
+            }
+        }
         if (self.applyFilterCallback != nil) {
             self.applyFilterCallback!(NSArray(array: self.selectTypeArray!), NSArray(array: self.selectColorArray!), NSArray(array: self.selectAuthorArray!), isEmpty)
         }
@@ -537,21 +558,26 @@ extension KMNoteOutlineFilterViewController: NSCollectionViewDelegate, NSCollect
             return item
         } else if collectionView.isEqual(to: self.collectionView) {
             let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMNoteFilterStateCollevtionViewItem"), for: indexPath) as! KMNoteFilterStateCollevtionViewItem
-//            let author = self._authorMutableArray![indexPath.item]
-//            if let data = self.selectAuthorArray?.contains(author), data {
-//                item.selectAuthor(author as! String, isSelect: true)
-//            } else {
-//                item.selectAuthor(author as! String, isSelect: false)
-//            }
 
-//            item.authorClickCallback = { [weak self] author in
-//                if let data = self?.selectAuthorArray?.contains(author), data {
-//                    self?.selectAuthorArray?.remove(author)
-//                } else {
-//                    self?.selectAuthorArray?.add(author)
-//                }
-//            }
             let state = self.stateArray_[indexPath.item]
+            if let con = self.selectStateArray?.contains(NSNumber(value: state.rawValue)), con {
+                item.isSelected = true
+            } else {
+                item.isSelected = false
+            }
+            item.selectCallback = { [weak self] isSelect in
+                guard let state = self?.stateArray_[indexPath.item] else {
+                    return
+                }
+                let data = NSNumber(value: state.rawValue)
+                KMPrint("kkkkkkkkkkkkkkkkkkkkk")
+                if let con = self?.selectStateArray?.contains(data), con {
+                    self?.selectStateArray?.remove(data)
+                } else {
+                    self?.selectStateArray?.add(data)
+                }
+            }
+//            let state = self.stateArray_[indexPath.item]
             item.label.stringValue = KMPDFAnnotationStateGetString(state: state) ?? ""
             if let data = KMPDFAnnotationStateGetIcon(state: state) {
                 item.iv.image = NSImage(named: data)

+ 5 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/View/KMNoteFilterStateCollevtionViewItem.swift

@@ -12,6 +12,8 @@ class KMNoteFilterStateCollevtionViewItem: NSCollectionViewItem {
     @IBOutlet weak var iv: NSImageView!
     @IBOutlet weak var label: NSTextField!
     
+    var selectCallback:((Bool)->Void)?
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         // Do view setup here.
@@ -33,6 +35,9 @@ class KMNoteFilterStateCollevtionViewItem: NSCollectionViewItem {
                 self.box.fillColor = .clear
                 self.label.textColor = KMAppearance.Layout.h0Color()
             }
+            
+            KMPrint("ooooooooo"+"\(self.isSelected)")
+            self.selectCallback?(self.isSelected)
         }
     }
     

+ 14 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift

@@ -899,7 +899,8 @@ extension KMLeftSideViewController {
             let typeArr: [String] = KMBotaTools.noteFilterAnnoTypes(key: filterKey)
             let colorArr: [Any] = KMBotaTools.noteFilterColors(key: filterKey)
             let authorArr: [Any] = KMBotaTools.noteFilterAuthors(key: filterKey)
-            if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
+            let stateArr: [NSNumber] = KMBotaTools.noteFilterStates(key: filterKey)
+            if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0  && stateArr.count == 0 {
 //                self.filtrateButton.image = NSImage(named: "KMImageNameAnnotationsFiltrate")
                 self.filterButtonLayer?.isHidden = true
             } else {
@@ -914,7 +915,7 @@ extension KMLeftSideViewController {
                 var annos: [CPDFAnnotation] = []
                 // 处理过滤
                 let types = ["Highlight","Underline","Strikeout","Squiggly","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Redact","Sign"/*, "table"*/,"Polyline","Polygon"]
-                if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
+                if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 && stateArr.count == 0 {
                     annos = KMOCToolClass.filterAnnotation(annotations: page?.annotations ?? [],types: types) as? [CPDFAnnotation] ?? []
                     annotationArray += annos
                 } else {
@@ -951,6 +952,17 @@ extension KMLeftSideViewController {
                             }
                         }
                     }
+                    
+                    if stateArr.count > 0 {
+                        for anno in filterAnnos {
+                            let markState = self.noteReplyHanddler.fetchAnnoState(anno) ?? .unMarked
+                            let reviewState = self.noteReplyHanddler.fetchReviewState(anno) ?? .none
+                            if stateArr.contains(NSNumber(value: markState.rawValue)) == false && stateArr.contains(NSNumber(value: reviewState.rawValue)) {
+                                filterAnnos.removeObject(anno)
+                            }
+                        }
+                    }
+                    
                     annos = filterAnnos
                 }
                 //添加签名注释

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

@@ -44,4 +44,11 @@ extension KMBotaTools {
         }
         return []
     }
+    
+    class func noteFilterStates(key: String) -> [NSNumber] {
+        if let data = KMDataManager.ud_object(forKey: NoteFilterVC.filterSelectStateKey + key) as? Data {
+            return (NSKeyedUnarchiver.unarchiveObject(with: data) as? [NSNumber]) ?? []
+        }
+        return []
+    }
 }