|
@@ -33,6 +33,9 @@ class KMBOTAOutlineView: BaseXibView {
|
|
|
|
|
|
var dragPDFOutline: KMBOTAOutlineItem!
|
|
var dragPDFOutline: KMBOTAOutlineItem!
|
|
|
|
|
|
|
|
+ var isSearchMode = false
|
|
|
|
+ var searchKey = ""
|
|
|
|
+
|
|
override func draw(_ dirtyRect: NSRect) {
|
|
override func draw(_ dirtyRect: NSRect) {
|
|
super.draw(dirtyRect)
|
|
super.draw(dirtyRect)
|
|
|
|
|
|
@@ -111,6 +114,41 @@ class KMBOTAOutlineView: BaseXibView {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func hasContainString(_ searchString: String, rootOutline outline: CPDFOutline) -> Bool {
|
|
|
|
+ var label = outline.label ?? ""
|
|
|
|
+ var searchLabel = searchString
|
|
|
|
+// if self.outlineIgnoreCaseFlag {
|
|
|
|
+// label = label.lowercased()
|
|
|
|
+// searchLabel = searchLabel.lowercased()
|
|
|
|
+// }
|
|
|
|
+ if label.contains(searchLabel) {
|
|
|
|
+// if ([outline.label rangeOfString:searchString options:self.outlineIgnoreCaseFlag?NSCaseInsensitiveSearch:0].location != NSNotFound){
|
|
|
|
+ return true
|
|
|
|
+ } else {
|
|
|
|
+ var subHas = false
|
|
|
|
+ for i in 0 ..< outline.numberOfChildren {
|
|
|
|
+ if let subOutline = outline.child(at: i) {
|
|
|
|
+ subHas = self.hasContainString(searchString, rootOutline: subOutline)
|
|
|
|
+ } else {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if (subHas) {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return subHas
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func fetchOutlines(for item: KMBOTAOutlineItem, searchString: String) -> [KMBOTAOutlineItem] {
|
|
|
|
+ var items: [KMBOTAOutlineItem] = []
|
|
|
|
+ for childI in item.children {
|
|
|
|
+ if self.hasContainString(searchString, rootOutline: childI.outline) {
|
|
|
|
+ items.append(childI)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return items
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//MARK: NSOutlineViewDataSource,NSOutlineViewDelegate
|
|
//MARK: NSOutlineViewDataSource,NSOutlineViewDelegate
|
|
@@ -118,8 +156,21 @@ extension KMBOTAOutlineView : NSOutlineViewDataSource,NSOutlineViewDelegate {
|
|
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
|
|
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
|
|
let outline = item as? KMBOTAOutlineItem
|
|
let outline = item as? KMBOTAOutlineItem
|
|
if outline != nil {
|
|
if outline != nil {
|
|
|
|
+ if isSearchMode {
|
|
|
|
+ let ols = self.fetchOutlines(for: outline!, searchString: searchKey)
|
|
|
|
+ return ols.count
|
|
|
|
+ }
|
|
return outline?.children.count ?? 0
|
|
return outline?.children.count ?? 0
|
|
} else {
|
|
} else {
|
|
|
|
+ if self.isSearchMode { // 是否为搜索模块
|
|
|
|
+ if self.hasContainString(searchKey, rootOutline: outline!.outline) == false {
|
|
|
|
+// self.showSearchOutlineBlankState(true)
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+// self.showSearchOutlineBlankState(false)
|
|
|
|
+ let ols = self.fetchOutlines(for: outline!, searchString: searchKey)
|
|
|
|
+ return ols.count
|
|
|
|
+ }
|
|
return Int(self.data?.outline.numberOfChildren ?? 0)
|
|
return Int(self.data?.outline.numberOfChildren ?? 0)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -127,8 +178,21 @@ extension KMBOTAOutlineView : NSOutlineViewDataSource,NSOutlineViewDelegate {
|
|
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
|
|
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
|
|
let outline = item as? KMBOTAOutlineItem
|
|
let outline = item as? KMBOTAOutlineItem
|
|
if outline != nil {
|
|
if outline != nil {
|
|
|
|
+ if isSearchMode {
|
|
|
|
+ let ols = self.fetchOutlines(for: outline!, searchString: searchKey)
|
|
|
|
+ return ols.safe_element(for: index) as Any
|
|
|
|
+ }
|
|
return outline?.children[index] as Any
|
|
return outline?.children[index] as Any
|
|
} else {
|
|
} else {
|
|
|
|
+ if self.isSearchMode { // 是否为搜索模块
|
|
|
|
+ if self.hasContainString(searchKey, rootOutline: outline!.outline) == false {
|
|
|
|
+// self.showSearchOutlineBlankState(true)
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+// self.showSearchOutlineBlankState(false)
|
|
|
|
+ let ols = self.fetchOutlines(for: outline!, searchString: searchKey)
|
|
|
|
+ return ols.count
|
|
|
|
+ }
|
|
return self.data?.children[index] as Any
|
|
return self.data?.children[index] as Any
|
|
}
|
|
}
|
|
}
|
|
}
|