|
@@ -79,11 +79,39 @@ class KMBOTAOutlineView: BaseXibView {
|
|
|
}
|
|
|
tempData.parent = nil
|
|
|
self.data = tempData
|
|
|
+ if isSearchMode {
|
|
|
+ self.reloadSearchChildren(item: self.data)
|
|
|
+ }
|
|
|
+
|
|
|
self.outlineView.reloadData()
|
|
|
}
|
|
|
+
|
|
|
self.delegate?.BOTAOutlineView(self, didReloadData: self.data ?? KMBOTAOutlineItem())
|
|
|
}
|
|
|
|
|
|
+ func reloadSearchChildren(item: KMBOTAOutlineItem?) {
|
|
|
+ guard let theItem = item else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if theItem.children.isEmpty {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ theItem.isSearchMode = true
|
|
|
+ let models = self.fetchOutlines(for: theItem, searchString: searchKey)
|
|
|
+ theItem.isSearchMode = true
|
|
|
+ theItem.searchChildren = models
|
|
|
+
|
|
|
+ for childM in theItem.children {
|
|
|
+ let models = self.fetchOutlines(for: childM, searchString: searchKey)
|
|
|
+ childM.isSearchMode = true
|
|
|
+ childM.searchChildren = models
|
|
|
+
|
|
|
+ self.reloadSearchChildren(item: childM)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
func addOutlineItem(outlineItem: KMBOTAOutlineItem?, outline: CPDFOutline, expandItemType: KMOutlineViewExpandItemType = .none) -> KMBOTAOutlineItem {
|
|
|
//添加根节点
|
|
|
let item: KMBOTAOutlineItem = KMBOTAOutlineItem()
|
|
@@ -154,67 +182,117 @@ class KMBOTAOutlineView: BaseXibView {
|
|
|
//MARK: NSOutlineViewDataSource,NSOutlineViewDelegate
|
|
|
extension KMBOTAOutlineView : NSOutlineViewDataSource,NSOutlineViewDelegate {
|
|
|
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
|
|
|
- let outline = item as? KMBOTAOutlineItem
|
|
|
- if outline != nil {
|
|
|
- if isSearchMode {
|
|
|
- let ols = self.fetchOutlines(for: outline!, searchString: searchKey)
|
|
|
- return ols.count
|
|
|
- }
|
|
|
- return outline?.children.count ?? 0
|
|
|
- } else {
|
|
|
- guard let data = self.data else {
|
|
|
- return 0
|
|
|
- }
|
|
|
-
|
|
|
+ guard let rootModel = self.data else {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ guard let model = item as? KMBOTAOutlineItem else {
|
|
|
if self.isSearchMode { // 是否为搜索模块
|
|
|
- if self.hasContainString(searchKey, rootOutline: data.outline) == false {
|
|
|
+ if self.hasContainString(searchKey, rootOutline: rootModel.outline) == false {
|
|
|
// self.showSearchOutlineBlankState(true)
|
|
|
return 0
|
|
|
}
|
|
|
+
|
|
|
// self.showSearchOutlineBlankState(false)
|
|
|
- let ols = self.fetchOutlines(for: data, searchString: searchKey)
|
|
|
- outlineView.expandItem(data, expandChildren: false)
|
|
|
- return ols.count
|
|
|
+ rootModel.isItemExpanded = true
|
|
|
+ rootModel.isSearchMode = true
|
|
|
+
|
|
|
+// let models = self.fetchOutlines(for: rootModel, searchString: searchKey)
|
|
|
+// for model in models {
|
|
|
+// model.isItemExpanded = true
|
|
|
+// model.isSearchMode = true
|
|
|
+// }
|
|
|
+
|
|
|
+// rootModel.searchChildren = models
|
|
|
+// return models.count
|
|
|
+ return rootModel.searchChildren.count
|
|
|
}
|
|
|
- return Int(self.data?.outline.numberOfChildren ?? 0)
|
|
|
+
|
|
|
+ rootModel.isSearchMode = false
|
|
|
+// rootModel.searchChildren = []
|
|
|
+// for model in rootModel.children {
|
|
|
+// model.isItemExpanded = true
|
|
|
+// model.isSearchMode = false
|
|
|
+// }
|
|
|
+ return Int(rootModel.outline.numberOfChildren)
|
|
|
}
|
|
|
+ if isSearchMode {
|
|
|
+ model.isItemExpanded = true
|
|
|
+ model.isSearchMode = true
|
|
|
+
|
|
|
+// let models = self.fetchOutlines(for: model, searchString: searchKey)
|
|
|
+// for model in models {
|
|
|
+// model.isItemExpanded = true
|
|
|
+// model.isSearchMode = true
|
|
|
+// }
|
|
|
+// model.searchChildren = models
|
|
|
+// return models.count
|
|
|
+ return model.searchChildren.count
|
|
|
+ }
|
|
|
+
|
|
|
+ model.isSearchMode = false
|
|
|
+// model.searchChildren = []
|
|
|
+// for childM in model.children {
|
|
|
+// model.isItemExpanded = true
|
|
|
+// childM.isSearchMode = false
|
|
|
+// }
|
|
|
+ return model.children.count
|
|
|
}
|
|
|
|
|
|
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
|
|
|
- let outline = item as? KMBOTAOutlineItem
|
|
|
- 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
|
|
|
- } else {
|
|
|
+ guard let rootModel = self.data else {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+
|
|
|
+ guard let model = item as? KMBOTAOutlineItem else {
|
|
|
if self.isSearchMode { // 是否为搜索模块
|
|
|
- guard let data = self.data else {
|
|
|
- return ""
|
|
|
- }
|
|
|
-
|
|
|
- if self.hasContainString(searchKey, rootOutline: data.outline) == false {
|
|
|
+ if self.hasContainString(searchKey, rootOutline: rootModel.outline) == false {
|
|
|
// self.showSearchOutlineBlankState(true)
|
|
|
return ""
|
|
|
}
|
|
|
// self.showSearchOutlineBlankState(false)
|
|
|
- let ols = self.fetchOutlines(for: data, searchString: searchKey)
|
|
|
- return ols.safe_element(for: index) as Any
|
|
|
+ let models = self.fetchOutlines(for: rootModel, searchString: searchKey)
|
|
|
+ for model in models {
|
|
|
+ model.isItemExpanded = true
|
|
|
+ model.isSearchMode = true
|
|
|
+ }
|
|
|
+// rootModel.searchChildren = models
|
|
|
+// return models.safe_element(for: index) as Any
|
|
|
+ return rootModel.searchChildren.safe_element(for: index) as Any
|
|
|
+ }
|
|
|
+ for model in rootModel.children {
|
|
|
+ model.isSearchMode = false
|
|
|
+ }
|
|
|
+ rootModel.searchChildren = []
|
|
|
+ return rootModel.children[index] as Any
|
|
|
+ }
|
|
|
+ if isSearchMode {
|
|
|
+ let models = self.fetchOutlines(for: model, searchString: searchKey)
|
|
|
+ for model in models {
|
|
|
+ model.isItemExpanded = true
|
|
|
+ model.isSearchMode = true
|
|
|
}
|
|
|
- return self.data?.children[index] as Any
|
|
|
+// model.searchChildren = models
|
|
|
+// return models.safe_element(for: index) as Any
|
|
|
+ return model.searchChildren.safe_element(for: index) as Any
|
|
|
}
|
|
|
+ for childM in model.children {
|
|
|
+ childM.isSearchMode = false
|
|
|
+ }
|
|
|
+ model.searchChildren = []
|
|
|
+ return model.children[index] as Any
|
|
|
}
|
|
|
|
|
|
func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
|
|
|
- let outline = item as? KMBOTAOutlineItem
|
|
|
- if outline != nil && outline?.children.count != 0 {
|
|
|
-// if isSearchMode {
|
|
|
-// outlineView.expandItem(outline, expandChildren: true)
|
|
|
-// }
|
|
|
- return true
|
|
|
+ guard let model = item as? KMBOTAOutlineItem else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ if isSearchMode {
|
|
|
+ let datas = self.fetchOutlines(for: model, searchString: searchKey)
|
|
|
+ return !datas.isEmpty
|
|
|
}
|
|
|
- return false
|
|
|
+ return !model.children.isEmpty
|
|
|
}
|
|
|
|
|
|
func outlineView(_ outlineView: NSOutlineView, shouldExpandItem item: Any) -> Bool {
|