Browse Source

AI - 划词翻译弹窗补充loading状态

wanjun 1 year ago
parent
commit
f9d6da02f5

+ 32 - 0
PDF Office/PDF Master/Class/Home/WindowController/KMAITranslationWindowController.swift

@@ -57,6 +57,7 @@ class KMAITranslationWindowController: NSWindowController {
     var popover: NSPopover?
     var popover: NSPopover?
     var popoverTips: NSPopover?
     var popoverTips: NSPopover?
     var _state: KMAITranslationState = .None
     var _state: KMAITranslationState = .None
+    var progressController: SKProgressController?
 
 
     override func windowDidLoad() {
     override func windowDidLoad() {
         super.windowDidLoad()
         super.windowDidLoad()
@@ -286,6 +287,29 @@ class KMAITranslationWindowController: NSWindowController {
         }
         }
     }
     }
     
     
+    func showProgressWindow() {
+        let progress = SKProgressController()
+        progress.message = NSLocalizedString("translation...", comment: "")
+        progress.window?.backgroundColor = NSColor(hex: "#36383B")
+        progress.window?.contentView?.wantsLayer = true
+        progress.window?.contentView?.layer?.backgroundColor = NSColor(hex: "#36383B").cgColor
+        progress.progressField.textColor = NSColor.white
+        
+        progress.closeBlock = { [unowned self] in
+            
+        }
+        
+        self.progressController = progress
+        self.window?.beginSheet(progress.window!)
+    }
+    
+    func hiddenProgressWindow() {
+        if (self.progressController != nil) {
+            self.window?.endSheet((self.progressController?.window)!)
+            self.progressController = nil
+        }
+    }
+    
     // MARK: Action
     // MARK: Action
     
     
     @IBAction func fromLanguageAction(_ sender: NSButton) {
     @IBAction func fromLanguageAction(_ sender: NSButton) {
@@ -358,6 +382,10 @@ class KMAITranslationWindowController: NSWindowController {
                 KMLoginWindowController.show(window: NSApp.mainWindow!)
                 KMLoginWindowController.show(window: NSApp.mainWindow!)
                 return
                 return
             }
             }
+            
+            DispatchQueue.main.async {
+                self.showProgressWindow()
+            }
 
 
             self.errorView.isHidden = true
             self.errorView.isHidden = true
             self.toContentTextView.string = ""
             self.toContentTextView.string = ""
@@ -365,6 +393,10 @@ class KMAITranslationWindowController: NSWindowController {
             let infoDictionary = Bundle .main.infoDictionary!
             let infoDictionary = Bundle .main.infoDictionary!
             let majorVersion = infoDictionary["CFBundleShortVersionString"]
             let majorVersion = infoDictionary["CFBundleShortVersionString"]
             KMRequestServerManager.manager.aiTranslationTextTrans(q: self.fromContentTextField.stringValue, from: self.fromStr, to: self.toStr, version: "1.0.1") { [unowned self] success, result in
             KMRequestServerManager.manager.aiTranslationTextTrans(q: self.fromContentTextField.stringValue, from: self.fromStr, to: self.toStr, version: "1.0.1") { [unowned self] success, result in
+                DispatchQueue.main.async {
+                    self.hiddenProgressWindow()
+                }
+
                 if success {
                 if success {
                     let result: NSDictionary = result!.result
                     let result: NSDictionary = result!.result