Browse Source

【综合】Bota注释列表数据模型化

tangchao 11 months ago
parent
commit
deab0145cb

+ 30 - 65
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift

@@ -571,8 +571,8 @@ extension KMLeftSideViewController {
         if self.noteSearchMode { // 搜索模式
             return self.noteSearchArray.safe_element(for: index) as? CPDFAnnotation
         } else { // 常规模式(非搜索)
-            let section = self.annotations.safe_element(for: index) as? KMBOTAAnnotationSection
-            return section?.annotations?.first?.annotation
+            let model = self.annotations.safe_element(for: index) as? KMBotaAnnotationModel
+            return model?.anno
         }
     }
     
@@ -654,8 +654,8 @@ extension KMLeftSideViewController {
         if anno is CPDFLineAnnotation || anno is CPDFSquareAnnotation || anno is CPDFCircleAnnotation || anno is CPDFInkAnnotation {
             // 形状注释 + Ink 需要显示框住的内容【刷新】
             for item in self.annotations {
-                if let data = item.annotations?.first?.annotation, data.isEqual(to: anno) {
-                    self.noteOutlineView.reloadItem(item.annotations?.first)
+                if anno.isEqual(to: item.anno) {
+                    self.noteOutlineView.reloadItem(item)
                     break
                 }
             }
@@ -676,11 +676,9 @@ extension KMLeftSideViewController {
                 self.filterButtonLayer?.isHidden = false
             }
             
-            var dataArray: [KMBOTAAnnotationSection] = []
             var annotationArray: [CPDFAnnotation] = []
             var allAnnotation: [CPDFAnnotation] = []
             for i in 0 ..< self.pageCount() {
-                var items: [KMBOTAAnnotationItem] = []
                 let page = self.pdfDocument()?.page(at: UInt(i))
                 var annos: [CPDFAnnotation] = []
                 // 处理过滤
@@ -711,25 +709,9 @@ extension KMLeftSideViewController {
                         annos.removeObject(annotation)
                     }
                 }
-
-                //转换所有annotation类型
-                let section = KMBOTAAnnotationSection()
-                for anno in annos {
-                    let item = KMBOTAAnnotationItem()
-                    item.section = section
-                    item.annotation = anno
-                    item.index = Int(anno.page.pageIndex())
-                    items.append(item)
-                    
-                    allAnnotation.append(anno)
-                }
                 
-                if items.count != 0 {
-                    section.annotations = items
-                    section.page = page
-                    section.isItemExpanded = true
-                    dataArray.append(section)
-                }
+                // 添加刷选后的注释
+                allAnnotation += annos
                 
                 //添加所有annotation 用于筛选
                 annotationArray += (page?.annotations ?? [])
@@ -737,7 +719,6 @@ extension KMLeftSideViewController {
             
             //  处理排序
             if self.noteSortType == .page {
-                var datas: [KMBOTAAnnotationSection] = []
                 /// 排序(升序)
                 if self.isAscendSort {
                     allAnnotation.sort {
@@ -752,22 +733,7 @@ extension KMLeftSideViewController {
                         return idx0 > idx1
                     }
                 }
-                for anno in allAnnotation {
-                    let section = KMBOTAAnnotationSection()
-                    let item = KMBOTAAnnotationItem()
-                    item.section = section
-                    item.annotation = anno
-                    item.index = Int(anno.pageIndex())
-                    
-                    section.annotations = [item]
-                    section.page = anno.page
-                    section.isItemExpanded = true
-                    
-                    datas.append(section)
-                }
-                self.annotations = datas
             } else if self.noteSortType == .time {
-                var datas: [KMBOTAAnnotationSection] = []
                 /// 排序(升序)
                 if self.isAscendSort {
                     allAnnotation.sort {
@@ -790,21 +756,22 @@ extension KMLeftSideViewController {
                         return $0.modificationDate() > $1.modificationDate()
                     }
                 }
-                for anno in allAnnotation {
-                    let section = KMBOTAAnnotationSection()
-                    let item = KMBOTAAnnotationItem()
-                    item.section = section
-                    item.annotation = anno
-                    item.index = Int(anno.pageIndex())
-                    
-                    section.annotations = [item]
-                    section.page = anno.page
-                    section.isItemExpanded = true
-                    
-                    datas.append(section)
-                }
-                self.annotations = datas
             }
+            // 数据模型\化
+            var datas: [KMBotaAnnotationModel] = []
+            for anno in allAnnotation {
+                let item = KMBotaAnnotationModel()
+//                item.section = section
+                item.anno = anno
+//                item.index = Int(anno.pageIndex())
+                
+//                section.annotations = [item]
+//                section.page = anno.page
+//                section.isItemExpanded = true
+                
+                datas.append(item)
+            }
+            self.annotations = datas
             
             // 转换对象,用于数据显示
             self.allAnnotations = annotationArray
@@ -830,15 +797,15 @@ extension KMLeftSideViewController {
         // 清空数据
         self.noteSearchArray.removeAll()
         if stringValue.isEmpty {
-            for section in self.annotations {
-                guard let note = section.annotations?.first?.annotation else {
+            for model in self.annotations {
+                guard let note = model.anno else {
                     continue
                 }
                 self.noteSearchArray.append(note)
             }
         } else {
-            for section in self.annotations {
-                guard let note = section.annotations?.first?.annotation else {
+            for model in self.annotations {
+                guard let note = model.anno else {
                     continue
                 }
                 var noteString = KMBOTAAnnotationTool.fetchContentLabelString(annotation: note)
@@ -898,8 +865,8 @@ extension KMLeftSideViewController {
         let rowIndexes = self.noteOutlineView.selectedRowIndexes
         for row in rowIndexes {
             let item = self.noteOutlineView.item(atRow: row)
-            if item is KMBOTAAnnotationItem {
-                if let anno = (item as! KMBOTAAnnotationItem).annotation {
+            if item is KMBotaAnnotationModel {
+                if let anno = (item as! KMBotaAnnotationModel).anno {
                     //                if anno.type == nil {
                     //                item = [(SKNoteText *)item note];
                     //                }
@@ -936,11 +903,9 @@ extension KMLeftSideViewController {
                 }
             }
         } else {
-            for section in self.annotations {
-                for item in section.annotations ?? [] {
-                    if let note = item.annotation, note is CPDFMarkupAnnotation {
-                        mutableArray.append(note)
-                    }
+            for model in self.annotations {
+                if let note = model.anno, note is CPDFMarkupAnnotation {
+                    mutableArray.append(note)
                 }
             }
         }

+ 10 - 24
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -154,7 +154,7 @@ class KMLeftSideViewController: KMSideViewController {
     var isRenameNoteOutline = false
 
     // 注释列表数据源
-    var annotations: [KMBOTAAnnotationSection] = []
+    var annotations: [KMBotaAnnotationModel] = []
     // 所有注释
     var allAnnotations: [CPDFAnnotation] = []
     // 注释搜索模式标记
@@ -1759,12 +1759,7 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
             if self.noteSearchMode {
                 return self.noteSearchArray.count
             }
-            var count = 0
-            for section in self.annotations {
-                if let cnt = section.annotations?.count {
-                    count += cnt
-                }
-            }
+            let count = self.annotations.count
 
             let hasAnno = self.allAnnotations.count >= 1
             self.noteSearchButton.isEnabled = hasAnno
@@ -1822,16 +1817,7 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
             if self.noteSearchMode {
                 return self.noteSearchArray[index]
             }
-            var items: [KMBOTAAnnotationItem] = []
-            for secion in self.annotations {
-                guard let eles = secion.annotations, eles.count > 0 else {
-                    continue
-                }
-                for ele in eles {
-                    items.append(ele)
-                }
-            }
-            return items[index] as Any
+            return self.annotations[index] as Any
         }
         return item as Any
     }
@@ -1877,12 +1863,12 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
             }
             return cell
         } else if outlineView.isEqual(to: self.noteOutlineView) {
-            let model = item as? KMBOTAAnnotationItem
+            let model = item as? KMBotaAnnotationModel
             var note: CPDFAnnotation?
             if self.noteSearchMode {
                 note = item as? CPDFAnnotation
             } else {
-                note = (item as? KMBOTAAnnotationItem)?.annotation
+                note = (item as? KMBotaAnnotationModel)?.anno
             }
             let cell = outlineView.makeView(withIdentifier: KMNoteTableViewCell.km_identifier, owner: self) as! KMNoteTableViewCell
             cell.cellNote = note
@@ -1943,11 +1929,11 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
     
     func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
         if outlineView.isEqual(self.noteOutlineView) {
-            if let model = item as? KMBOTAAnnotationItem {
+            if let model = item as? KMBotaAnnotationModel {
                 if model.foldType == .fold {
                     return model.foldH
                 }
-                if let anno = model.annotation {
+                if let anno = model.anno {
                     return KMBOTAAnnotationTool.fetchCellHeight(annotation: anno, maxSize: CGSize(width: 260+40 - 16, height: 1000))
                 }
             }
@@ -2151,8 +2137,8 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
             var note: CPDFAnnotation?
             if let data = item as? CPDFAnnotation {
                 note = data
-            } else if let data = item as? KMBOTAAnnotationItem {
-                note = data.annotation
+            } else if let data = item as? KMBotaAnnotationModel {
+                note = data.anno
             }
             if let data = note?.type, data.isEmpty == false {
                 if tableColumn?.identifier.rawValue == self.noteColumnId.rawValue {
@@ -2316,7 +2302,7 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
         let noteItems = NSMutableArray()
          
         for item in items {
-            guard let anno = (item as? KMBOTAAnnotationItem)?.annotation else {
+            guard let anno = (item as? KMBotaAnnotationModel)?.anno else {
                 continue
             }
             if anno.type == nil {

+ 1 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Model/KMAnnotationModel.swift

@@ -17,4 +17,5 @@ class KMBotaAnnotationModel: KMAnnotationModel {
     var showAuthor              = true
     
     var foldType: KMFoldType    = .none
+    var foldH: CGFloat = 30
 }

+ 0 - 32
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -596,37 +596,5 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "E0708F20-3526-401B-ACF4-583D9B27D908"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1936"
-            endingLineNumber = "1936"
-            landmarkName = "outlineView(_:viewFor:item:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "C023EB88-2637-4F8B-8EE9-3A029D95964E"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "930"
-            endingLineNumber = "930"
-            landmarkName = "loadUnfoldDate(_:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
    </Breakpoints>
 </Bucket>