|
@@ -217,33 +217,24 @@ extension KMLeftSideViewController {
|
|
|
Task {
|
|
|
let response = await KMAlertTool.runModel(message: KMLocalizedString("This will permanently remove all annotations. Are you sure to continue?", nil), buttons: [KMLocalizedString("Yes", nil), KMLocalizedString("No", nil)])
|
|
|
if response == .alertFirstButtonReturn {
|
|
|
- var annotations = NSMutableArray()
|
|
|
-
|
|
|
+ var annos: [CPDFAnnotation] = []
|
|
|
for i in 0 ..< doc.pageCount {
|
|
|
let page = self.listView.document.page(at: i)
|
|
|
for anno in page?.annotations ?? [] {
|
|
|
if anno is CPDFTextWidgetAnnotation || anno is CPDFButtonWidgetAnnotation || anno is CPDFChoiceWidgetAnnotation {
|
|
|
continue
|
|
|
}
|
|
|
- // if (@available(macOS 10.13, *)) {
|
|
|
// if ([annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
|
|
|
// continue;
|
|
|
// }
|
|
|
- // }
|
|
|
-// if anno is CPDFInkAnnotation {
|
|
|
-// continue
|
|
|
-// }
|
|
|
- annotations.add(anno)
|
|
|
+ annos.append(anno)
|
|
|
}
|
|
|
}
|
|
|
- for anno in annotations {
|
|
|
- if let data = anno as? CPDFAnnotation {
|
|
|
- self.listView.remove(data)
|
|
|
- }
|
|
|
+ for anno in annos {
|
|
|
+ self.listView.remove(anno)
|
|
|
}
|
|
|
|
|
|
self.reloadAnnotation()
|
|
|
- self.noteOutlineView.reloadData()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -335,7 +326,8 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
KMDataManager.ud_set(self.isAscendSort, forKey: Self.Key.noteAscendSortKey)
|
|
|
|
|
|
- self.annotationSort(sortArray: [])
|
|
|
+// self.annotationSort(sortArray: [])
|
|
|
+ self.reloadAnnotation()
|
|
|
}
|
|
|
|
|
|
@IBAction func noteSearchAction(_ sender: NSButton) {
|
|
@@ -374,7 +366,8 @@ extension KMLeftSideViewController {
|
|
|
self?.filterButtonLayer?.isHidden = false
|
|
|
}
|
|
|
|
|
|
- self?.annotationSort(sortArray: [])
|
|
|
+// self?.annotationSort(sortArray: [])
|
|
|
+ self?.reloadAnnotation()
|
|
|
}
|
|
|
filterViewController.cancelCallback = { isCancel in
|
|
|
if (isCancel) {
|
|
@@ -418,7 +411,8 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
KMDataManager.ud_set(self.noteSortType.rawValue, forKey: Self.Key.noteSortTypeKey)
|
|
|
|
|
|
- self.annotationSort(sortArray: [])
|
|
|
+// self.annotationSort(sortArray: [])
|
|
|
+ self.reloadAnnotation()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -557,14 +551,55 @@ extension KMLeftSideViewController {
|
|
|
|
|
|
func reloadAnnotation() {
|
|
|
if self.listView != nil {
|
|
|
+ var typeArr: [Any] = []
|
|
|
+ var colorArr: [Any] = []
|
|
|
+ var authorArr: [Any] = []
|
|
|
+
|
|
|
+ let sud = UserDefaults.standard
|
|
|
+ let typeData = KMDataManager.ud_object(forKey: NoteFilterVC.filterSelectTypeKey + self.listView.document.documentURL.path) as? Data
|
|
|
+ if typeData != nil {
|
|
|
+ typeArr = NSKeyedUnarchiver.unarchiveObject(with: typeData!) as? [Any] ?? []
|
|
|
+ }
|
|
|
+
|
|
|
+ let colorData = sud.object(forKey: NoteFilterVC.filterSelectColorKey + self.listView.document.documentURL.path) as? Data
|
|
|
+ if colorData != nil {
|
|
|
+ colorArr = NSKeyedUnarchiver.unarchiveObject(with: colorData!) as? [Any] ?? []
|
|
|
+ }
|
|
|
+
|
|
|
+ let authorData = sud.object(forKey: NoteFilterVC.filterSelectAuthorKey + 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")
|
|
|
+ } else {
|
|
|
+// self.filtrateButton.image = NSImage(named: "icon_annotation_screening_select")
|
|
|
+ }
|
|
|
+
|
|
|
var dataArray: [KMBOTAAnnotationSection] = []
|
|
|
var annotationArray: [CPDFAnnotation] = []
|
|
|
var allAnnotation: [CPDFAnnotation] = []
|
|
|
for i in 0 ..< self.listView.document.pageCount {
|
|
|
var items: [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 annos: [CPDFAnnotation] = KMOCToolClass.filterAnnotation(annotations: page?.annotations ?? [],types: types) as? [CPDFAnnotation] ?? []
|
|
|
+ var annos: [CPDFAnnotation] = []
|
|
|
+ // 处理过滤
|
|
|
+ if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
|
|
|
+ let types = ["Highlight","Underline","Strikeout","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Redact","Sign"]
|
|
|
+ annos = KMOCToolClass.filterAnnotation(annotations: page?.annotations ?? [],types: types) as? [CPDFAnnotation] ?? []
|
|
|
+ } else {
|
|
|
+ var filterAnnos: [CPDFAnnotation] = page?.annotations ?? []
|
|
|
+ if typeArr.count > 0 {
|
|
|
+ filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos, types: typeArr) as? [CPDFAnnotation]) ?? []
|
|
|
+ }
|
|
|
+ if (colorArr.count > 0) {
|
|
|
+ filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos,colors: colorArr) as? [CPDFAnnotation]) ?? []
|
|
|
+ }
|
|
|
+ if (authorArr.count > 0) {
|
|
|
+ filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos,authors: authorArr) as? [CPDFAnnotation]) ?? []
|
|
|
+ }
|
|
|
+ annos = filterAnnos
|
|
|
+ }
|
|
|
//添加签名注释
|
|
|
for annotation in page?.annotations ?? [] {
|
|
|
if annotation.isKind(of: CPDFSignatureAnnotation.self) {
|
|
@@ -600,19 +635,20 @@ extension KMLeftSideViewController {
|
|
|
annotationArray += annos
|
|
|
}
|
|
|
|
|
|
+ // 处理排序
|
|
|
if self.noteSortType == .page {
|
|
|
/// 排序(升序)
|
|
|
if self.isAscendSort {
|
|
|
dataArray.sort {
|
|
|
let idx0 = $0.page?.pageIndex() ?? 0
|
|
|
let idx1 = $1.page?.pageIndex() ?? 0
|
|
|
- return idx0 > idx1
|
|
|
+ return idx0 <= idx1
|
|
|
}
|
|
|
} else {
|
|
|
dataArray.sort {
|
|
|
let idx0 = $0.page?.pageIndex() ?? 0
|
|
|
let idx1 = $1.page?.pageIndex() ?? 0
|
|
|
- return idx0 <= idx1
|
|
|
+ return idx0 > idx1
|
|
|
}
|
|
|
}
|
|
|
self.annotations = dataArray
|
|
@@ -627,7 +663,7 @@ extension KMLeftSideViewController {
|
|
|
if $1.modificationDate() == nil {
|
|
|
return false
|
|
|
}
|
|
|
- return $0.modificationDate() > $1.modificationDate()
|
|
|
+ return $0.modificationDate() <= $1.modificationDate()
|
|
|
}
|
|
|
} else {
|
|
|
allAnnotation.sort {
|
|
@@ -637,7 +673,7 @@ extension KMLeftSideViewController {
|
|
|
if $1.modificationDate() == nil {
|
|
|
return false
|
|
|
}
|
|
|
- return $0.modificationDate() <= $1.modificationDate()
|
|
|
+ return $0.modificationDate() > $1.modificationDate()
|
|
|
}
|
|
|
}
|
|
|
for anno in allAnnotation {
|
|
@@ -665,286 +701,9 @@ extension KMLeftSideViewController {
|
|
|
// self.filtrateButton.isEnabled = true
|
|
|
// }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- func annotationSort(sortArray:[[Any]]) {
|
|
|
- if self.listView != nil {
|
|
|
- var typeArr: [Any] = []
|
|
|
- var colorArr: [Any] = []
|
|
|
- var authorArr: [Any] = []
|
|
|
-
|
|
|
- let sud = UserDefaults.standard
|
|
|
- let typeData = KMDataManager.ud_object(forKey: NoteFilterVC.filterSelectTypeKey + self.listView.document.documentURL.path) as? Data
|
|
|
- if typeData != nil {
|
|
|
- typeArr = NSKeyedUnarchiver.unarchiveObject(with: typeData!) as? [Any] ?? []
|
|
|
- }
|
|
|
-
|
|
|
- let colorData = sud.object(forKey: NoteFilterVC.filterSelectColorKey + self.listView.document.documentURL.path) as? Data
|
|
|
- if colorData != nil {
|
|
|
- colorArr = NSKeyedUnarchiver.unarchiveObject(with: colorData!) as? [Any] ?? []
|
|
|
- }
|
|
|
-
|
|
|
- let authorData = sud.object(forKey: NoteFilterVC.filterSelectAuthorKey + self.listView.document.documentURL.path) as? Data
|
|
|
- if authorData != nil {
|
|
|
- authorArr = NSKeyedUnarchiver.unarchiveObject(with: authorData!) as? [Any] ?? []
|
|
|
- }
|
|
|
-
|
|
|
- var colorMutableArray = NSMutableArray()
|
|
|
- var typeMutableArray = NSMutableArray()
|
|
|
- var authorMutableArray = NSMutableArray()
|
|
|
- for annotation in self.allAnnotations {
|
|
|
- if annotation.isKind(of: CPDFInkAnnotation.self) == false &&
|
|
|
- annotation.isKind(of: CPDFTextWidgetAnnotation.self) == false &&
|
|
|
- annotation.isKind(of: CPDFButtonWidgetAnnotation.self) == false &&
|
|
|
- annotation.isKind(of: CPDFChoiceWidgetAnnotation.self) == false
|
|
|
-// ![annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature] &&
|
|
|
-// ![annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeText] &&
|
|
|
-// ![annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeButton] &&
|
|
|
-// ![annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeChoice])
|
|
|
- {
|
|
|
- let noteColor = annotation.color ?? .clear
|
|
|
- let noteType = annotation.type ?? ""
|
|
|
- let authorString = annotation.userName() ?? ""
|
|
|
-
|
|
|
- if (noteColor != nil) {
|
|
|
- if (colorMutableArray.count > 0) {
|
|
|
- if colorMutableArray.contains(noteColor) == false {
|
|
|
- colorMutableArray.add(noteColor)
|
|
|
- }
|
|
|
- } else {
|
|
|
- colorMutableArray.add(noteColor)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if noteType.isEmpty == false {
|
|
|
- if (typeMutableArray.count > 0) {
|
|
|
- if typeMutableArray.contains(noteType) == false {
|
|
|
- typeMutableArray.add(noteType)
|
|
|
- }
|
|
|
- } else {
|
|
|
- typeMutableArray.add(noteType)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if authorString.isEmpty == false {
|
|
|
- if (authorMutableArray.count > 0) {
|
|
|
- if authorMutableArray.contains(authorString) == false {
|
|
|
- authorMutableArray.add(authorString)
|
|
|
- }
|
|
|
- } else {
|
|
|
- authorMutableArray.add(authorString)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-// var temporaryArr1 = NSMutableArray()
|
|
|
-// var temporaryArr2 = NSMutableArray()
|
|
|
-// var temporaryArr3 = NSMutableArray()
|
|
|
-// if typeArr.isEmpty == false {
|
|
|
-// for type in typeArr {
|
|
|
-// if typeMutableArray.contains(type) == false {
|
|
|
-// temporaryArr1.add(type)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if colorArr.isEmpty == false {
|
|
|
-// for color in colorArr {
|
|
|
-// if colorMutableArray.contains(color) == false {
|
|
|
-// temporaryArr2.add(type)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if authorArr.isEmpty == false {
|
|
|
-// for author in authorArr {
|
|
|
-// if authorMutableArray.contains(author) == false {
|
|
|
-// temporaryArr3.add(type)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// if (temporaryArr1.count > 0) {
|
|
|
-// for type in temporaryArr1 {
|
|
|
-// guard let typeS = type as? String else {
|
|
|
-// continue
|
|
|
-// }
|
|
|
-//// [typeArr removeObject:type];
|
|
|
-//
|
|
|
-// var flag = -1
|
|
|
-// for (i, data) in typeArr.enumerated() {
|
|
|
-// if data as! String == typeS {
|
|
|
-// flag = i
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if flag != -1 {
|
|
|
-// typeArr.remove(at: flag)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (temporaryArr2.count > 0) {
|
|
|
-// for (NSColor *color in temporaryArr2) {
|
|
|
-// [colorArr removeObject:color];
|
|
|
-// }
|
|
|
-// }
|
|
|
-// for color in temporaryArr2 {
|
|
|
-// guard let colorT = color as? NSColor else {
|
|
|
-// continue
|
|
|
-// }
|
|
|
-//// [typeArr removeObject:type];
|
|
|
-//
|
|
|
-// var flag = -1
|
|
|
-// for (i, data) in colorArr.enumerated() {
|
|
|
-// if data as! NSColor == colorT {
|
|
|
-// flag = i
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if flag != -1 {
|
|
|
-// colorArr.remove(at: flag)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (temporaryArr3.count > 0) {
|
|
|
-// for (NSColor *author in temporaryArr3) {
|
|
|
-// [authorArr removeObject:author];
|
|
|
-// }
|
|
|
-// }
|
|
|
-// for author in temporaryArr3 {
|
|
|
-// guard let authorS = author as? String else {
|
|
|
-// continue
|
|
|
-// }
|
|
|
-//// [typeArr removeObject:type];
|
|
|
-//
|
|
|
-// var flag = -1
|
|
|
-// for (i, data) in authorArr.enumerated() {
|
|
|
-// if data as! String == authorS {
|
|
|
-// flag = i
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if flag != -1 {
|
|
|
-// authorArr.remove(at: flag)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// let data1 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: typeArr))
|
|
|
-// let data2 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: colorArr))
|
|
|
-// let data3 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: authorArr))
|
|
|
-
|
|
|
-// let sud = UserDefaults.standard
|
|
|
-// sud.set(data1, forKey: "KMNoteOutlineFilterSelectArray_Type")
|
|
|
-// sud.set(data2, forKey: "KMNoteOutlineFilterSelectArray_Color")
|
|
|
-// sud.set(data3, forKey: "KMNoteOutlineFilterSelectArray_Author")
|
|
|
-// sud.synchronize()
|
|
|
-
|
|
|
- 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] = []
|
|
|
- var allAnnotation: [CPDFAnnotation] = []
|
|
|
- for i in 0 ..< self.listView.document.pageCount {
|
|
|
- var annotationItemArray: [KMBOTAAnnotationItem] = []
|
|
|
- guard let page = self.listView.document.page(at: i) else {
|
|
|
- continue
|
|
|
- }
|
|
|
- if page.annotations.count > 0 {
|
|
|
- var filterAnnotations: [CPDFAnnotation] = page.annotations
|
|
|
- if typeArr.count > 0 {
|
|
|
- filterAnnotations = (KMOCToolClass.filterAnnotation(annotations: filterAnnotations, types: typeArr) as? [CPDFAnnotation]) ?? []
|
|
|
- }
|
|
|
- if (colorArr.count > 0) {
|
|
|
- filterAnnotations = (KMOCToolClass.filterAnnotation(annotations: filterAnnotations,colors: colorArr) as? [CPDFAnnotation]) ?? []
|
|
|
- }
|
|
|
- if (authorArr.count > 0) {
|
|
|
- filterAnnotations = (KMOCToolClass.filterAnnotation(annotations: 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)
|
|
|
- allAnnotation.append(annotation)
|
|
|
- }
|
|
|
-
|
|
|
- if annotationItemArray.count != 0 {
|
|
|
- section.annotations = annotationItemArray
|
|
|
- section.page = page
|
|
|
- section.isItemExpanded = true
|
|
|
- dataArray.append(section)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if self.noteSortType == .page {
|
|
|
- /// 根据id进行排序(升序)
|
|
|
- if self.isAscendSort {
|
|
|
- dataArray.sort {
|
|
|
- if $0.page == nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- if $1.page == nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- return $0.page!.pageIndex() > $1.page!.pageIndex()
|
|
|
- }
|
|
|
- } else {
|
|
|
- dataArray.sort {
|
|
|
- if $0.page == nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- if $1.page == nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- return $0.page!.pageIndex() <= $1.page!.pageIndex()
|
|
|
- }
|
|
|
- }
|
|
|
- self.annotations = dataArray
|
|
|
- } else if self.noteSortType == .time {
|
|
|
- var datas: [KMBOTAAnnotationSection] = []
|
|
|
- /// 根据id进行排序(升序)
|
|
|
- if self.isAscendSort {
|
|
|
- allAnnotation.sort {
|
|
|
- if $0.modificationDate() == nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- if $1.modificationDate() == nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- return $0.modificationDate() > $1.modificationDate()
|
|
|
- }
|
|
|
- } else {
|
|
|
- allAnnotation.sort {
|
|
|
- if $0.modificationDate() == nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- if $1.modificationDate() == nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- 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
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Task { @MainActor in
|
|
|
- self.noteOutlineView.reloadData()
|
|
|
- }
|
|
|
+
|
|
|
+ Task { @MainActor in
|
|
|
+ self.noteOutlineView.reloadData()
|
|
|
}
|
|
|
}
|
|
|
|