|
@@ -533,8 +533,11 @@ extension KMLeftSideViewController {
|
|
|
self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
|
|
|
}
|
|
|
KMDataManager.ud_set(self.isAscendSort, forKey: Self.Key.noteAscendSortKey)
|
|
|
-
|
|
|
- self.reloadAnnotation()
|
|
|
+ if self.noteSearchMode {
|
|
|
+ self.reloadNoteForSearchMode()
|
|
|
+ } else {
|
|
|
+ self.reloadAnnotation()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@IBAction func noteSearchAction(_ sender: NSButton) {
|
|
@@ -629,7 +632,11 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
KMDataManager.ud_set(self.noteSortType.rawValue, forKey: Self.Key.noteSortTypeKey)
|
|
|
|
|
|
- self.reloadAnnotation()
|
|
|
+ if self.noteSearchMode {
|
|
|
+ self.reloadNoteForSearchMode()
|
|
|
+ } else {
|
|
|
+ self.reloadAnnotation()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func showNoteEmptyView() {
|
|
@@ -818,38 +825,83 @@ extension KMLeftSideViewController {
|
|
|
// self.filtrateButton.isEnabled = true
|
|
|
// }
|
|
|
}
|
|
|
-
|
|
|
- Task { @MainActor in
|
|
|
- self.noteOutlineView.reloadData()
|
|
|
+ self.note_refrshUIIfNeed()
|
|
|
+ }
|
|
|
+
|
|
|
+ func reloadNoteForSearchMode() {
|
|
|
+ if self.noteSearchMode == false {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 处理排序
|
|
|
+ if self.noteSortType == .page {
|
|
|
+ if self.isAscendSort { /// 排序(升序)
|
|
|
+ self.noteSearchArray.sort {
|
|
|
+ let idx0 = $0.anno?.page?.pageIndex() ?? 0
|
|
|
+ let idx1 = $1.anno?.page?.pageIndex() ?? 0
|
|
|
+ return idx0 <= idx1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.noteSearchArray.sort {
|
|
|
+ let idx0 = $0.anno?.page?.pageIndex() ?? 0
|
|
|
+ let idx1 = $1.anno?.page?.pageIndex() ?? 0
|
|
|
+ return idx0 > idx1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if self.noteSortType == .time {
|
|
|
+ if self.isAscendSort { /// 排序(升序)
|
|
|
+ self.noteSearchArray.sort {
|
|
|
+ if $0.anno?.modificationDate() == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if $1.anno?.modificationDate() == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return $0.anno!.modificationDate() <= $1.anno!.modificationDate()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.noteSearchArray.sort {
|
|
|
+ if $0.anno?.modificationDate() == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if $1.anno?.modificationDate() == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return $0.anno!.modificationDate() > $1.anno!.modificationDate()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ self.note_refrshUIIfNeed()
|
|
|
}
|
|
|
|
|
|
// 搜索 Action
|
|
|
func updateNoteFilterPredicate() {
|
|
|
var stringValue = self.noteSearchField.stringValue
|
|
|
- if self.caseInsensitiveNoteSearch { // 忽略大小写
|
|
|
- stringValue = stringValue.lowercased()
|
|
|
- }
|
|
|
-
|
|
|
// 清空数据
|
|
|
self.noteSearchArray.removeAll()
|
|
|
if stringValue.isEmpty {
|
|
|
for model in self.annoListModel?.datas ?? [] {
|
|
|
- guard let note = model.anno else {
|
|
|
+ guard let _ = model.anno else {
|
|
|
continue
|
|
|
}
|
|
|
self.noteSearchArray.append(model)
|
|
|
}
|
|
|
} else {
|
|
|
+ // 忽略大小写
|
|
|
+ let caseInsensite = self.caseInsensitiveNoteSearch
|
|
|
+ if caseInsensite {
|
|
|
+ stringValue = stringValue.lowercased()
|
|
|
+ }
|
|
|
for model in self.annoListModel?.datas ?? [] {
|
|
|
guard let note = model.anno else {
|
|
|
continue
|
|
|
}
|
|
|
- var noteString = KMBOTAAnnotationTool.fetchContentLabelString(annotation: note)
|
|
|
+ var noteString = ""
|
|
|
if let anno = note as? CPDFMarkupAnnotation {
|
|
|
noteString = anno.markupContent()
|
|
|
+ } else {
|
|
|
+ noteString = KMBOTAAnnotationTool.fetchContentLabelString(annotation: note)
|
|
|
}
|
|
|
- if self.caseInsensitiveNoteSearch {
|
|
|
+ if caseInsensite {
|
|
|
noteString = noteString.lowercased()
|
|
|
}
|
|
|
if noteString.contains(stringValue) {
|
|
@@ -857,10 +909,7 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 刷新 UI
|
|
|
- Task { @MainActor in
|
|
|
- self.noteOutlineView.reloadData()
|
|
|
- }
|
|
|
+ self.note_refrshUIIfNeed()
|
|
|
}
|
|
|
|
|
|
@objc func selectSelectedNote(_ sender: AnyObject?) {
|