Parcourir la source

【2025】【综合】补充Menu菜单搜索相关方法及逻辑

dinglingui il y a 1 semaine
Parent
commit
de16df6686

+ 26 - 10
PDF Office/PDF Master/AppDelegate+MenuAction.swift

@@ -279,6 +279,7 @@ extension AppDelegate {
                          NSSelectorFromString("menuItemAction_unlockFunction:"),
                          NSSelectorFromString("menuItemAction_searchPDF:"),
                          NSSelectorFromString("menuItemAction_performFindPanelAction:"),
+                         NSSelectorFromString("menuItemAction_searchSelect:"),
                          NSSelectorFromString("menuItemAction_showInFinder:"),
                          NSSelectorFromString("menuItemAction_property:"),
                          NSSelectorFromString("menuItemAction_print:"),
@@ -294,6 +295,16 @@ extension AppDelegate {
         let action = menuItem.action
         
         guard let windowVC = self.currentBrowserWindowController() else {
+            let _windowC = NSApp.mainWindow?.windowController as? KMSearchReplaceWindowController
+            if action == NSSelectorFromString("menuItemAction_performFindPanelAction:") {
+                if menuItem.tag == 0 {
+                    return true
+                } else if menuItem.tag == 1 {
+                    return _windowC?.nextButtonSupportEdit() == true
+                } else if menuItem.tag == 2 {
+                    return _windowC?.previousButtonSupportEdit() == true
+                }
+            }
             if action == NSSelectorFromString("menuItemAction_closeDocument:") {
                 return true
             }
@@ -364,7 +375,7 @@ extension AppDelegate {
             } else if action == NSSelectorFromString("menuItemAction_searchPDF:") {
                 
             } else if action == NSSelectorFromString("menuItemAction_performFindPanelAction:") {
-                
+                return false
             } else if action == NSSelectorFromString("menuItemAction_showInFinder:") {
                 
             } else if action == NSSelectorFromString("menuItemAction_property:") {
@@ -375,6 +386,12 @@ extension AppDelegate {
                 return mainVC.validPrint()
             } else if action == NSSelectorFromString("sharePageItemActionWithSender:") {
                 return true
+            } else if action == NSSelectorFromString("menuItemAction_searchSelect:") {
+                if let currentSel = mainVC.listView.currentSelection,currentSel.selectionType() == .text {
+                    return true
+                } else {
+                    return false
+                }
             }
             return true
         }
@@ -589,16 +606,15 @@ extension AppDelegate {
     }
     
     @IBAction func menuItemAction_performFindPanelAction(_ sender: NSMenuItem) {
+        let searchReplaceWindowController = NSApp.mainWindow?.windowController as? KMSearchReplaceWindowController
+        if searchReplaceWindowController != nil {
+            searchReplaceWindowController?.menuItemAction_performFindPanelAction(sender)
+        }
+    }
+    
+    @IBAction func menuItemAction_searchSelect(_ sender: NSMenuItem) {
         if let mainVC = self.mainViewController() {
-            if sender.tag == 0 {
-                mainVC.find_ReplacePDF()
-            } else if sender.tag == 1 {
-                mainVC.fineNext()
-            } else if sender.tag == 2 {
-                mainVC.findPrevious()
-            } else if sender.tag == 3 {
-                mainVC.useSelectionForFind()
-            }
+            mainVC.useSelectionForFind()
         }
     }
     

+ 3 - 3
PDF Office/PDF Master/Base.lproj/Main.storyboard

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>
@@ -392,7 +392,7 @@
                                                     </menuItem>
                                                     <menuItem title="Use Selection for Find" tag="3" keyEquivalent="e" id="X1v-dk-FGj">
                                                         <connections>
-                                                            <action selector="menuItemAction_performFindPanelAction:" target="Voe-Tx-rLC" id="jBe-rf-zhk"/>
+                                                            <action selector="menuItemAction_searchSelect:" target="Voe-Tx-rLC" id="IFb-Mb-CrO"/>
                                                         </connections>
                                                     </menuItem>
                                                 </items>

+ 6 - 23
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -3849,7 +3849,8 @@ struct KMNMWCFlags {
         let handdler = KMNSearchHanddler()
         handdler.type = type
         handdler.searchKey = keyborad
-        handdler.searchKey = replaceText
+        handdler.replaceKey = replaceText
+        handdler.pdfView = listView
         self.showSearchPopWindow(hander: handdler)
     }
     
@@ -3879,6 +3880,7 @@ struct KMNMWCFlags {
         
         self.view.window?.makeFirstResponder(nil)
         let winC = KMSearchReplaceWindowController(with: listView, type: hander.type)
+        winC.mainVC = self
         self.currentWindowController = winC
         
         winC.replaceCallback = { [weak self] in
@@ -3935,8 +3937,8 @@ struct KMNMWCFlags {
         winC.window?.setFrameOrigin(winFramePoint)
         self.view.window?.addChildWindow(winC.window!, ordered: .above)
         winC.window?.makeKeyAndOrderFront(nil) // 让子窗口成为 keyWindow
-        
         winC.handdler = hander
+        winC.reloadData()
     }
     
     func closeSearchPopWindow() {
@@ -3947,29 +3949,10 @@ struct KMNMWCFlags {
     func searchPDF() {
         showSearchPopWindow(type: .search, keyborad: "", replaceText: "", results: [])
     }
-    
-    func find_ReplacePDF() {
-        if KMMemberInfo.shared.isLogin == false {
-            KMLoginWindowsController.shared.showWindow(nil)
-            return
-        }
-        showSearchPopWindow(type: .replace, keyborad: "", replaceText: "", results: [])
-    }
-    
-    func fineNext() {
-        if let searchReplaceWindowController = currentWindowController as? KMSearchReplaceWindowController {
-            searchReplaceWindowController._nextAction(nil)
-        }
-    }
-    
-    func findPrevious() {
-        if let searchReplaceWindowController = currentWindowController as? KMSearchReplaceWindowController {
-            searchReplaceWindowController._previousAction(nil)
-        }
-    }
+
     
     func useSelectionForFind() {
-        if let currentSel = listView.currentSelection,currentSel.selectionType() == .text,currentSel.string().isEmpty != nil {
+        if let currentSel = listView.currentSelection,currentSel.selectionType() == .text {
             showSearchPopWindow(type: .search, keyborad: currentSel.string(), replaceText: "", results: [])
         }
         

+ 58 - 10
PDF Office/PDF Master/KMClass/Left/Search/Window/KMSearchReplaceWindowController.swift

@@ -30,6 +30,8 @@ class KMSearchReplaceWindowController: KMNBaseWindowController {
     
     private var _modalSession: NSApplication.ModalSession?
     
+    weak var mainVC:KMMainViewController?
+    
     var handdler: KMNSearchHanddler = KMNSearchHanddler() {
         didSet {
             if handdler.searchKey?.count ?? 0 > 0 && handdler.searchResults.count == 0 {
@@ -120,17 +122,9 @@ class KMSearchReplaceWindowController: KMNBaseWindowController {
                 
                 self?.itemClick?(1, self?.handdler)
             } else if idx == 3 {
-                self?.switchType(.search, animate: true)
-                self?.itemClick?(3, self?.handdler)
-                if self?.handdler.searchKey?.count ?? 0 > 0 {
-                    self?.search(keyboard: self?.handdler.searchKey ?? "")
-                }
+                self?.changeSearchType(type: .search)
             } else if idx == 4 {
-                self?.switchType(.replace, animate: true)
-                self?.itemClick?(4, self?.handdler)
-                if self?.handdler.searchKey?.count ?? 0 > 0 {
-                    self?.search(keyboard: self?.handdler.searchKey ?? "")
-                }
+                self?.changeSearchType(type: .replace)
             }
         }
         
@@ -186,6 +180,23 @@ class KMSearchReplaceWindowController: KMNBaseWindowController {
         }
     }
     
+    private func changeSearchType(type:KMNBotaSearchType) {
+        if type == .search {
+            self.switchType(.search, animate: true)
+            self.itemClick?(3, self.handdler)
+            if self.handdler.searchKey?.count ?? 0 > 0 {
+                self.search(keyboard: self.handdler.searchKey ?? "")
+            }
+
+        } else if type == .replace {
+            self.switchType(.replace, animate: true)
+            self.itemClick?(4, self.handdler)
+            if self.handdler.searchKey?.count ?? 0 > 0 {
+                self.search(keyboard: self.handdler.searchKey ?? "")
+            }
+        }
+    }
+    
     override func updateUILanguage() {
         super.updateUILanguage()
     }
@@ -203,6 +214,27 @@ class KMSearchReplaceWindowController: KMNBaseWindowController {
         }
     }
     
+    func nextButtonSupportEdit()->Bool {
+        if(nextButton.properties.isDisabled == false) {
+            return true
+        }
+        return false
+    }
+    
+    func previousButtonSupportEdit()->Bool {
+        if(previousButton.properties.isDisabled == false) {
+            return true
+        }
+        return false
+    }
+    
+    func searchSupportEdit()->Bool {
+        if(self.handdler.searchResults.isEmpty == false) {
+            return true
+        }
+        return false
+    }
+    
     func updateButtonState() {
         let value = searchItemView_.inputValue
         if value.isEmpty || self.handdler.searchResults.isEmpty {
@@ -327,6 +359,22 @@ class KMSearchReplaceWindowController: KMNBaseWindowController {
         self._showIndexTip()
         self.updateButtonState()
     }
+    
+     func menuItemAction_performFindPanelAction(_ sender: NSMenuItem) {
+        if sender.tag == 0 {
+            let searchType = handdler.type
+            if searchType == .search {
+                self.changeSearchType(type: .replace)
+            } else if searchType == .replace {
+                self.changeSearchType(type: .search)
+            }
+        } else if sender.tag == 1 {
+            _nextAction(nil)
+        } else if sender.tag == 2 {
+            _previousAction(nil)
+        }
+    }
+    
 }
 
 //MARK: Actions