|
@@ -193,13 +193,10 @@ extension KMLeftSideViewController {
|
|
|
rowIndexes = IndexSet(integer: row)
|
|
|
}
|
|
|
items = self.noteOutlineView.itemsAtRowIndexes(rowIndexes) as NSArray
|
|
|
- guard let foldNote = self.fetchNote(for: row) else {
|
|
|
+ guard let model = self.fetchAnnoModel(for: row) else {
|
|
|
return
|
|
|
}
|
|
|
- var isFold = true
|
|
|
- if self.allFoldNotes.contains(foldNote) {
|
|
|
- isFold = false
|
|
|
- }
|
|
|
+ var isFold = model.isFold()
|
|
|
item = menu.addItem(title: KMLocalizedString("Expand", nil), action: #selector(unfoldNoteAction), target: self)
|
|
|
item?.state = isFold ? .off : .on
|
|
|
item?.representedObject = items
|
|
@@ -324,7 +321,8 @@ extension KMLeftSideViewController {
|
|
|
action == #selector(note_foldAllComments) ||
|
|
|
action == #selector(exportAnnotationNotes) ||
|
|
|
action == #selector(removeAllAnnotations)) {
|
|
|
- return self.annotations.count > 0
|
|
|
+ let cnt = self.annoListModel?.datas.count ?? 0
|
|
|
+ return cnt > 0
|
|
|
} else if (action == #selector(unfoldNoteAction) ||
|
|
|
action == #selector(foldNoteAction)) {
|
|
|
let row = self.noteOutlineView.clickedRow
|
|
@@ -400,48 +398,44 @@ extension KMLeftSideViewController {
|
|
|
doc?.saveTo(sender)
|
|
|
}
|
|
|
|
|
|
+ // 展开
|
|
|
+
|
|
|
@objc func unfoldNoteAction(_ sender: NSMenuItem) {
|
|
|
if sender.state == .on {
|
|
|
return
|
|
|
}
|
|
|
let row = self.noteOutlineView.clickedRow
|
|
|
- guard let foldNote = self.fetchNote(for: row) else {
|
|
|
+ guard let model = self.fetchAnnoModel(for: row) else {
|
|
|
return
|
|
|
}
|
|
|
- if self.allFoldNotes.contains(foldNote) == false {
|
|
|
- self.allFoldNotes.append(foldNote)
|
|
|
- }
|
|
|
|
|
|
- if self.allFoldNotes.count == self.canFoldNotes.count {
|
|
|
- self.foldType = .unfold
|
|
|
- } else {
|
|
|
- self.foldType = .none
|
|
|
- }
|
|
|
-
|
|
|
+// if self.allFoldNotes.count == self.canFoldNotes.count {
|
|
|
+// self.foldType = .unfold
|
|
|
+// } else {
|
|
|
+// self.foldType = .none
|
|
|
+// }
|
|
|
+ model.foldType = .unfold
|
|
|
let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
|
|
|
(viewS as? KMNoteTableViewCell)?.isFold = false
|
|
|
}
|
|
|
|
|
|
@objc func foldNoteAction(_ sender: NSMenuItem) {
|
|
|
-// if sender.state == .on {
|
|
|
-// return
|
|
|
-// }
|
|
|
+ if sender.state == .on {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
let row = self.noteOutlineView.clickedRow
|
|
|
- guard let foldNote = self.fetchNote(for: row) else {
|
|
|
+ guard let model = self.fetchAnnoModel(for: row) else {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if self.allFoldNotes.contains(foldNote) == false {
|
|
|
- self.allFoldNotes.append(foldNote)
|
|
|
- }
|
|
|
+// if (self.allFoldNotes.count == 0) {
|
|
|
+// self.foldType = .fold
|
|
|
+// } else {
|
|
|
+// self.foldType = .none
|
|
|
+// }
|
|
|
|
|
|
- if (self.allFoldNotes.count == 0) {
|
|
|
- self.foldType = .fold
|
|
|
- } else {
|
|
|
- self.foldType = .none
|
|
|
- }
|
|
|
-
|
|
|
+ model.foldType = .fold
|
|
|
let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
|
|
|
(viewS as? KMNoteTableViewCell)?.isFold = true
|
|
|
}
|
|
@@ -512,7 +506,6 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
KMDataManager.ud_set(self.isAscendSort, forKey: Self.Key.noteAscendSortKey)
|
|
|
|
|
|
-// self.annotationSort(sortArray: [])
|
|
|
self.reloadAnnotation()
|
|
|
}
|
|
|
|
|
@@ -568,12 +561,14 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
|
|
|
func fetchNote(for index: Int) -> CPDFAnnotation? {
|
|
|
+ return self.fetchAnnoModel(for: index)?.anno
|
|
|
+ }
|
|
|
+
|
|
|
+ func fetchAnnoModel(for index: Int) -> KMBotaAnnotationModel? {
|
|
|
if self.noteSearchMode { // 搜索模式
|
|
|
- let model = self.noteSearchArray.safe_element(for: index) as? KMBotaAnnotationModel
|
|
|
- return model?.anno
|
|
|
+ return self.noteSearchArray.safe_element(for: index) as? KMBotaAnnotationModel
|
|
|
} else { // 常规模式(非搜索)
|
|
|
- let model = self.annotations.safe_element(for: index) as? KMBotaAnnotationModel
|
|
|
- return model?.anno
|
|
|
+ return self.annoListModel?.datas.safe_element(for: index) as? KMBotaAnnotationModel
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -653,7 +648,7 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
if anno is CPDFLineAnnotation || anno is CPDFSquareAnnotation || anno is CPDFCircleAnnotation || anno is CPDFInkAnnotation {
|
|
|
// 形状注释 + Ink 需要显示框住的内容【刷新】
|
|
|
- for item in self.annotations {
|
|
|
+ for item in self.annoListModel?.datas ?? [] {
|
|
|
if anno.isEqual(to: item.anno) {
|
|
|
self.noteOutlineView.reloadItem(item)
|
|
|
break
|
|
@@ -758,6 +753,7 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
}
|
|
|
// 数据模型\化
|
|
|
+ let model = KMAnnotationListModel()
|
|
|
var datas: [KMBotaAnnotationModel] = []
|
|
|
for anno in allAnnotation {
|
|
|
let item = KMBotaAnnotationModel()
|
|
@@ -767,7 +763,8 @@ extension KMLeftSideViewController {
|
|
|
item.showAuthor = self.annoListIsShowAnther()
|
|
|
datas.append(item)
|
|
|
}
|
|
|
- self.annotations = datas
|
|
|
+ model.datas = datas
|
|
|
+ self.annoListModel = model
|
|
|
|
|
|
// 转换对象,用于数据显示
|
|
|
self.allAnnotations = annotationArray
|
|
@@ -793,14 +790,14 @@ extension KMLeftSideViewController {
|
|
|
// 清空数据
|
|
|
self.noteSearchArray.removeAll()
|
|
|
if stringValue.isEmpty {
|
|
|
- for model in self.annotations {
|
|
|
+ for model in self.annoListModel?.datas ?? [] {
|
|
|
guard let note = model.anno else {
|
|
|
continue
|
|
|
}
|
|
|
self.noteSearchArray.append(model)
|
|
|
}
|
|
|
} else {
|
|
|
- for model in self.annotations {
|
|
|
+ for model in self.annoListModel?.datas ?? [] {
|
|
|
guard let note = model.anno else {
|
|
|
continue
|
|
|
}
|
|
@@ -889,8 +886,6 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
|
|
|
func loadUnfoldDate(_ foldType: KMFoldType) {
|
|
|
- // 清空所有折叠数组
|
|
|
- self.allFoldNotes.removeAll()
|
|
|
var mutableArray: [CPDFAnnotation] = []
|
|
|
if self.noteSearchMode {
|
|
|
for model in self.noteSearchArray {
|
|
@@ -899,7 +894,7 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- for model in self.annotations {
|
|
|
+ for model in self.annoListModel?.datas ?? [] {
|
|
|
if let note = model.anno, note is CPDFMarkupAnnotation {
|
|
|
mutableArray.append(note)
|
|
|
}
|
|
@@ -911,6 +906,5 @@ extension KMLeftSideViewController {
|
|
|
// }
|
|
|
// }
|
|
|
self.canFoldNotes = mutableArray
|
|
|
- self.allFoldNotes = []
|
|
|
}
|
|
|
}
|