Browse Source

【用户反馈】选中文本-右键 -翻译(不是AI翻译)/查找 功能无效

lizhe 6 months ago
parent
commit
fff72e351f

+ 7 - 0
PDF Office/PDF Master/Class/PDFTools/FindSearch/KMSearchFindView.swift

@@ -175,6 +175,13 @@ class KMSearchFindView: KMBaseXibView {
         findString = word
         findForward(true)
     }
+    
+    @objc func searchString(_ string: String) {
+        let word = string
+        findField.stringValue = word
+        findString = word
+        findForward(true)
+    }
 
 //    override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
 //        if menuItem.action == #selector(toggleCaseInsensitiveFind(_:)) {

+ 20 - 2
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+UI.swift

@@ -864,10 +864,18 @@ extension KMMainViewController {
        
     }
     @objc func lookUpAction() {
+        let label = self.listView?.currentSelection?.string() ?? ""
+        self.toolbarController.showFindBar()
+        self.toolbarController.findSearchView.searchString(label)
+//        self.toolbarController.findSearchView.find(Any.self)
         
     }
     @objc func searchBaiduAction() {
-        
+        let label = self.listView?.currentSelection?.string() ?? ""
+        let query = label.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
+        if let url = URL(string: "https://www.baidu.com/s?wd=\(query)") {
+            NSWorkspace.shared.open(url)
+        }
     }
     @objc func showInfoInFinder() {
         
@@ -879,7 +887,17 @@ extension KMMainViewController {
         
     }
     @objc func TranslateItemAction() {
-        
+        // 获取选中的文本
+        if let selection = self.listView?.currentSelection?.string() {
+            // 进行翻译
+            let escapedText = selection.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
+            let urlStr = "https://translate.google.com/?sl=auto&tl=zh-CN&text=\(escapedText)"
+            if let url = URL(string: urlStr) {
+                NSWorkspace.shared.open(url)
+            }
+        } else {
+            print("No text selected.")
+        }
     }
     @objc func AutoScrollItemAction() {
         //增加判断,如果是正在滚动,就停止,否则就开始滚动