ソースを参照

【右键】- 分享功能

liujiajie 1 年間 前
コミット
f49acf0dc7

+ 2 - 1
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -314,11 +314,12 @@ extension KMMainViewController {
         return stypItem
     }
     func setShareStype() -> NSMenuItem {
-        let stypItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: #selector(showShareAction), target: self)
+        let stypItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: self)
         var string = ""
         if listView.activeAnnotation != nil {
             string = listView.activeAnnotation.contents
         }
+        string = listView.currentSelection.string()
         
         stypItem.submenu = NSSharingServicePicker.menu(forSharingItems: [string], subjectContext: "", withTarget: self, selector: #selector(shareFromService), serviceDelegate: nil)
         return stypItem

+ 70 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+UI.swift

@@ -700,8 +700,78 @@ extension KMMainViewController {
         self.listView.autoFlow()
     }
     @objc func shareFromService(sender: NSMenuItem) {
+        if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
+            return
+        }
+        
+        var string = ""
+        if let freeTextAnnotation = listView.activeAnnotation as? CPDFFreeTextAnnotation {
+            string = freeTextAnnotation.contents ?? ""
+        } else if let markupAnnotation = listView.activeAnnotation as? CPDFMarkupAnnotation {
+            if let page = markupAnnotation.page {
+                if let selection = page.selection(for: markupAnnotation.bounds) {
+                    string = selection.string()
+                }
+            }
+        } else {
+            string = listView.currentSelection.string()
+        }
         
+        let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
+        let model: CTTabStripModel = windowControler.browser.tabStripModel
+        if (model.count() <= 0) {
+            return
+        }
+        
+        if (model.activeTabContents().isHome) {
+            return
+        }
+        
+        let document: KMMainDocument = model.activeTabContents() as! KMMainDocument
+        if string.count > 0 {
+            let represent : NSSharingService = sender.representedObject as! NSSharingService
+            represent.perform(withItems: [string])
+            return
+        }
+
+        // 有使用付费功能
+        Task { @MainActor in
+            if await (KMLightMemberManager.manager.canPayFunction() == false) {
+                let _ = KMSubscribeWaterMarkWindowController.show(window: NSApp.mainWindow!, isContinue: true) { isSubscribeSuccess, isWaterMarkExport, isClose in
+                    if (isClose) {
+                        return
+                    }
+                    if (isSubscribeSuccess) {
+                        let represent : NSSharingService = sender.representedObject as! NSSharingService
+                        represent.perform(withItems: [string])
+                        return
+                    }
+                    if (isWaterMarkExport) {
+                        let doucumentURL = document.fileURL
+                        let docDir = NSTemporaryDirectory()
+                        let documentName : String = doucumentURL!.path.lastPathComponent
+                        let path = docDir.stringByAppendingPathComponent(documentName)
+            
+                        let data = KMTools.saveWatermarkDocument(document: document.mainViewController!.document!, to: URL(fileURLWithPath: path), secureOptions: document.mainViewController!.secureOptions, removePWD: document.mainViewController!.removeSecureFlag)
+                        let writeSuccess = data != nil
+                        if writeSuccess == false {
+                            __NSBeep()
+                            return;
+                        }
+                        
+                        let represent : NSSharingService = sender.representedObject as! NSSharingService
+                        represent.perform(withItems: [string])
+                        return
+                    }
+                }
+                return
+            }
+            
+            let represent : NSSharingService = sender.representedObject as! NSSharingService
+            represent.perform(withItems: [string])
+        }
     }
+    
     @objc func cutAction(sender: NSMenuItem) {
         
     }