|
@@ -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) {
|