|
@@ -25,8 +25,8 @@ class KMAnnotationViewController: KMSideViewController {
|
|
|
|
|
|
var annotations: [KMBOTAAnnotationSection] = [] {
|
|
|
didSet {
|
|
|
- self.updateExtempViewState()
|
|
|
self.annotationOutlineView.inputData = annotations
|
|
|
+ self.updateExtempViewState()
|
|
|
}
|
|
|
}
|
|
|
var screenAnnotations: [KMBOTAAnnotationSection] = [] {
|
|
@@ -38,7 +38,7 @@ class KMAnnotationViewController: KMSideViewController {
|
|
|
//注释状态
|
|
|
var annotationShowState: KMAnnotationViewShowType = .none {
|
|
|
didSet {
|
|
|
- self.updateExtempViewState()
|
|
|
+ self.reloadData()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -139,113 +139,123 @@ extension KMAnnotationViewController {
|
|
|
}
|
|
|
|
|
|
func reloadAnnotation() {
|
|
|
- var dataArray: [KMBOTAAnnotationSection] = []
|
|
|
- var annotationArray: [CPDFAnnotation] = []
|
|
|
- for i in 0 ..< self.listView.document.pageCount {
|
|
|
- var annotationItemArray: [KMBOTAAnnotationItem] = []
|
|
|
- let page = self.listView.document.page(at: i)
|
|
|
- let types = ["Highlight","Underline","Strikeout","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Redact","Sign"]
|
|
|
- var pageAnnotations: [CPDFAnnotation] = KMOCToolClass.filterAnnotation(page!.annotations,types: types) as! [CPDFAnnotation]
|
|
|
- //添加签名注释
|
|
|
- for annotation in page!.annotations {
|
|
|
- if annotation.isKind(of: CPDFSignatureAnnotation.self) {
|
|
|
- pageAnnotations.append(annotation)
|
|
|
- }
|
|
|
- }
|
|
|
+ if self.listView != nil {
|
|
|
+ var dataArray: [KMBOTAAnnotationSection] = []
|
|
|
+ var annotationArray: [CPDFAnnotation] = []
|
|
|
+ for i in 0 ..< self.listView.document.pageCount {
|
|
|
+ var annotationItemArray: [KMBOTAAnnotationItem] = []
|
|
|
+ let page = self.listView.document.page(at: i)
|
|
|
+ let types = ["Highlight","Underline","Strikeout","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Redact","Sign"]
|
|
|
+ var pageAnnotations: [CPDFAnnotation] = KMOCToolClass.filterAnnotation(page!.annotations,types: types) as! [CPDFAnnotation]
|
|
|
+ //添加签名注释
|
|
|
+ for annotation in page!.annotations {
|
|
|
+ if annotation.isKind(of: CPDFSignatureAnnotation.self) {
|
|
|
+ pageAnnotations.append(annotation)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for annotation in pageAnnotations {
|
|
|
+ if annotation.annotationShouldDisplay() == false {
|
|
|
+ pageAnnotations.removeObject(annotation)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //转换所有annotation类型
|
|
|
- let section = KMBOTAAnnotationSection()
|
|
|
- for annotation in pageAnnotations {
|
|
|
- let item = KMBOTAAnnotationItem()
|
|
|
- item.section = section
|
|
|
- item.annotation = annotation
|
|
|
- item.index = Int(annotation.page.pageIndex())
|
|
|
- annotationItemArray.append(item)
|
|
|
+ //转换所有annotation类型
|
|
|
+ let section = KMBOTAAnnotationSection()
|
|
|
+ for annotation in pageAnnotations {
|
|
|
+ let item = KMBOTAAnnotationItem()
|
|
|
+ item.section = section
|
|
|
+ item.annotation = annotation
|
|
|
+ item.index = Int(annotation.page.pageIndex())
|
|
|
+ annotationItemArray.append(item)
|
|
|
+ }
|
|
|
+
|
|
|
+ if annotationItemArray.count != 0 {
|
|
|
+ section.annotations = annotationItemArray
|
|
|
+ section.page = page
|
|
|
+ section.isItemExpanded = true
|
|
|
+ dataArray.append(section)
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加所有annotation 用于筛选
|
|
|
+ annotationArray += pageAnnotations
|
|
|
}
|
|
|
|
|
|
- if annotationItemArray.count != 0 {
|
|
|
- section.annotations = annotationItemArray
|
|
|
- section.page = page
|
|
|
- section.isItemExpanded = true
|
|
|
- dataArray.append(section)
|
|
|
- }
|
|
|
+ //转换对象,用于数据显示
|
|
|
+ self.annotations = dataArray
|
|
|
+ self.allAnnotations = annotationArray
|
|
|
|
|
|
- //添加所有annotation 用于筛选
|
|
|
- annotationArray += pageAnnotations
|
|
|
- }
|
|
|
-
|
|
|
- //转换对象,用于数据显示
|
|
|
- self.annotations = dataArray
|
|
|
- self.allAnnotations = annotationArray
|
|
|
-
|
|
|
- if self.annotations.count < 1 {
|
|
|
- self.filtrateButton.isEnabled = false
|
|
|
- } else {
|
|
|
- self.filtrateButton.isEnabled = true
|
|
|
+ if self.annotations.count < 1 {
|
|
|
+ self.filtrateButton.isEnabled = false
|
|
|
+ } else {
|
|
|
+ self.filtrateButton.isEnabled = true
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func annotationSort(sortArray:[[Any]]) {
|
|
|
- var typeArr: [Any] = []
|
|
|
- var colorArr: [Any] = []
|
|
|
- var authorArr: [Any] = []
|
|
|
-
|
|
|
- let sud = UserDefaults.standard
|
|
|
- let typeData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Type" + self.listView.document.documentURL.path) as? Data
|
|
|
- if typeData != nil {
|
|
|
- typeArr = NSKeyedUnarchiver.unarchiveObject(with: typeData!) as! [Any]
|
|
|
- }
|
|
|
-
|
|
|
- let colorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Color" + self.listView.document.documentURL.path) as? Data
|
|
|
- if colorData != nil {
|
|
|
- colorArr = NSKeyedUnarchiver.unarchiveObject(with: colorData!) as! [Any]
|
|
|
- }
|
|
|
-
|
|
|
- let authorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Author" + self.listView.document.documentURL.path) as? Data
|
|
|
- if authorData != nil {
|
|
|
- authorArr = NSKeyedUnarchiver.unarchiveObject(with: authorData!) as! [Any]
|
|
|
- }
|
|
|
-
|
|
|
- if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
|
|
|
- self.filtrateButton.image = NSImage(named: "KMImageNameAnnotationsFiltrate")
|
|
|
- self.reloadAnnotation()
|
|
|
- } else {
|
|
|
- self.filtrateButton.image = NSImage(named: "icon_annotation_screening_select")
|
|
|
- var dataArray: [KMBOTAAnnotationSection] = []
|
|
|
- for i in 0 ..< self.listView.document.pageCount {
|
|
|
- var annotationItemArray: [KMBOTAAnnotationItem] = []
|
|
|
- let page = self.listView.document.page(at: i)
|
|
|
- if page!.annotations.count > 0 {
|
|
|
- var filterAnnotations: [CPDFAnnotation] = page!.annotations
|
|
|
- if typeArr.count > 0 {
|
|
|
- filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations, types: typeArr) as! [CPDFAnnotation])
|
|
|
- }
|
|
|
- if (colorArr.count > 0) {
|
|
|
- filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,colors: colorArr) as! [CPDFAnnotation])
|
|
|
- }
|
|
|
- if (authorArr.count > 0) {
|
|
|
- filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,authors: authorArr) as! [CPDFAnnotation])
|
|
|
- }
|
|
|
-
|
|
|
- let section = KMBOTAAnnotationSection()
|
|
|
- for annotation in filterAnnotations {
|
|
|
- let item = KMBOTAAnnotationItem()
|
|
|
- item.section = section
|
|
|
- item.annotation = annotation
|
|
|
- item.index = Int(page!.pageIndex())
|
|
|
- annotationItemArray.append(item)
|
|
|
- }
|
|
|
-
|
|
|
- if annotationItemArray.count != 0 {
|
|
|
- section.annotations = annotationItemArray
|
|
|
- section.page = page
|
|
|
- section.isItemExpanded = true
|
|
|
- dataArray.append(section)
|
|
|
+ if self.listView != nil {
|
|
|
+ var typeArr: [Any] = []
|
|
|
+ var colorArr: [Any] = []
|
|
|
+ var authorArr: [Any] = []
|
|
|
+
|
|
|
+ let sud = UserDefaults.standard
|
|
|
+ let typeData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Type" + self.listView.document.documentURL.path) as? Data
|
|
|
+ if typeData != nil {
|
|
|
+ typeArr = NSKeyedUnarchiver.unarchiveObject(with: typeData!) as! [Any]
|
|
|
+ }
|
|
|
+
|
|
|
+ let colorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Color" + self.listView.document.documentURL.path) as? Data
|
|
|
+ if colorData != nil {
|
|
|
+ colorArr = NSKeyedUnarchiver.unarchiveObject(with: colorData!) as! [Any]
|
|
|
+ }
|
|
|
+
|
|
|
+ let authorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Author" + self.listView.document.documentURL.path) as? Data
|
|
|
+ if authorData != nil {
|
|
|
+ authorArr = NSKeyedUnarchiver.unarchiveObject(with: authorData!) as! [Any]
|
|
|
+ }
|
|
|
+
|
|
|
+ if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
|
|
|
+ self.filtrateButton.image = NSImage(named: "KMImageNameAnnotationsFiltrate")
|
|
|
+ self.reloadAnnotation()
|
|
|
+ } else {
|
|
|
+ self.filtrateButton.image = NSImage(named: "icon_annotation_screening_select")
|
|
|
+ var dataArray: [KMBOTAAnnotationSection] = []
|
|
|
+ for i in 0 ..< self.listView.document.pageCount {
|
|
|
+ var annotationItemArray: [KMBOTAAnnotationItem] = []
|
|
|
+ let page = self.listView.document.page(at: i)
|
|
|
+ if page!.annotations.count > 0 {
|
|
|
+ var filterAnnotations: [CPDFAnnotation] = page!.annotations
|
|
|
+ if typeArr.count > 0 {
|
|
|
+ filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations, types: typeArr) as! [CPDFAnnotation])
|
|
|
+ }
|
|
|
+ if (colorArr.count > 0) {
|
|
|
+ filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,colors: colorArr) as! [CPDFAnnotation])
|
|
|
+ }
|
|
|
+ if (authorArr.count > 0) {
|
|
|
+ filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,authors: authorArr) as! [CPDFAnnotation])
|
|
|
+ }
|
|
|
+
|
|
|
+ let section = KMBOTAAnnotationSection()
|
|
|
+ for annotation in filterAnnotations {
|
|
|
+ let item = KMBOTAAnnotationItem()
|
|
|
+ item.section = section
|
|
|
+ item.annotation = annotation
|
|
|
+ item.index = Int(page!.pageIndex())
|
|
|
+ annotationItemArray.append(item)
|
|
|
+ }
|
|
|
+
|
|
|
+ if annotationItemArray.count != 0 {
|
|
|
+ section.annotations = annotationItemArray
|
|
|
+ section.page = page
|
|
|
+ section.isItemExpanded = true
|
|
|
+ dataArray.append(section)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ self.annotations = dataArray
|
|
|
}
|
|
|
-
|
|
|
- self.annotations = dataArray
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -255,14 +265,8 @@ extension KMAnnotationViewController {
|
|
|
func updateExtempViewState() {
|
|
|
if self.emptyView != nil {
|
|
|
var hidden = false
|
|
|
- if self.annotationShowState == .none {
|
|
|
- for section in annotations {
|
|
|
- if section.annotations?.count != 0 {
|
|
|
- hidden = true
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- hidden = false
|
|
|
+ if self.annotationOutlineView.outlineView.numberOfRows != 0 {
|
|
|
+ hidden = true
|
|
|
}
|
|
|
self.emptyView.isHidden = hidden
|
|
|
self.annotationOutlineView.isHidden = !hidden
|