ソースを参照

Merge branch 'develop_2025' of git.kdan.cc:Mac_PDF/PDF_Office into develop_2025

niehaoyu 3 ヶ月 前
コミット
90bacf236f

+ 0 - 1
PDF Office/PDF Master/KMClass/Left/Outline/Controller/KMOutlineViewController.swift

@@ -27,7 +27,6 @@ class KMOutlineViewController: KMNBaseViewController {
     
     var dragPDFOutline : KMBOTAOutlineItem!
     var renameTextField : NSTextField!
-//    var listView : CPDFListView!
     var renamePDFOutline : KMBOTAOutlineItem!
     let moreMenu = NSMenu()
     var isLocalEvent = false

+ 3 - 0
PDF Office/PDF Master/KMClass/Left/Outline/Model/KMBOTAOutlineItem.swift

@@ -17,4 +17,7 @@ class KMBOTAOutlineItem: NSObject {
     var select: Bool = false
     var hover: Bool = false
     var isItemExpanded: Bool = false
+    
+    var isSearchMode = false
+    var searchChildren: [KMBOTAOutlineItem] = []
 }

+ 9 - 5
PDF Office/PDF Master/KMClass/Left/Outline/View/KMBOTAOutlineCellView.swift

@@ -86,12 +86,16 @@ class KMBOTAOutlineCellView: NSTableCellView {
             self.iconButton.image = NSImage(named: "KMImageNameArrowRight")
         }
         
-        if data.outline.numberOfChildren > 0 {
-            self.iconButton.isHidden = false
-//            self.iconImageWidthConstrailnt.constant = 22
+        if data.isSearchMode {
+            iconButton.isHidden = data.searchChildren.isEmpty
         } else {
-            self.iconButton.isHidden = true
-//            self.iconImageWidthConstrailnt.constant = 0
+            if data.outline.numberOfChildren > 0 {
+                self.iconButton.isHidden = false
+                //            self.iconImageWidthConstrailnt.constant = 22
+            } else {
+                self.iconButton.isHidden = true
+                //            self.iconImageWidthConstrailnt.constant = 0
+            }
         }
     }
     

+ 118 - 40
PDF Office/PDF Master/KMClass/Left/Outline/View/KMBOTAOutlineView.swift

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