Explorar o código

AI - 首页重写、纠错功能补充加载Loading;切换不同Tab时,页面内容记录

wanjun hai 1 ano
pai
achega
b011dfc579

+ 12 - 0
PDF Office/PDF Master/Class/Appearance/Image.xcassets/Home/ic_ai_ErrorCorrection_empty.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "Error Correction.pdf",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 153 - 0
PDF Office/PDF Master/Class/Appearance/Image.xcassets/Home/ic_ai_ErrorCorrection_empty.imageset/Error Correction.pdf

@@ -0,0 +1,153 @@
+%PDF-1.7
+
+1 0 obj
+  << >>
+endobj
+
+2 0 obj
+  << /Length 3 0 R >>
+stream
+/DeviceRGB CS
+/DeviceRGB cs
+q
+1.000000 0.000000 -0.000000 1.000000 6.125488 12.120667 cm
+0.968627 0.972549 0.980392 scn
+45.674370 83.079384 m
+45.674370 81.010094 46.801437 79.200027 48.474174 78.230583 c
+48.474174 72.701637 l
+28.905325 71.321877 13.474174 55.596268 13.474174 36.399990 c
+13.474174 31.464695 14.494150 26.758720 16.342194 22.467163 c
+17.296360 20.251312 18.471260 18.145935 19.840508 16.176331 c
+20.194759 15.666748 19.763590 13.066673 18.546988 8.376015 c
+18.002670 6.277390 19.903755 4.336990 22.011211 4.846062 c
+26.983902 6.047241 29.737696 6.475441 30.272682 6.130478 c
+32.318039 4.812065 34.504395 3.680580 36.805470 2.761841 c
+41.262089 0.982246 46.149059 -0.000008 51.274174 -0.000008 c
+72.150543 -0.000008 89.074173 16.296814 89.074173 36.399990 c
+89.074173 55.596268 73.643021 71.321877 54.074173 72.701637 c
+54.074173 78.230354 l
+55.747128 79.199745 56.874371 81.009933 56.874371 83.079384 c
+56.874371 86.168175 54.363159 88.679382 51.274368 88.679382 c
+48.185581 88.679382 45.674370 86.168175 45.674370 83.079384 c
+h
+29.046541 53.432724 m
+29.585522 53.810699 30.195118 54.079292 30.836155 54.229084 c
+34.436951 55.070480 38.839958 55.070480 51.373730 55.070484 c
+51.373787 55.070484 l
+51.373844 55.070484 l
+51.373901 55.070484 l
+51.374565 55.070484 l
+53.008377 55.070484 54.515945 55.073082 55.909233 55.075485 c
+66.170654 55.093178 70.233215 55.100178 72.874573 53.979847 c
+72.906570 53.966274 72.941826 53.951668 72.980141 53.935799 c
+74.338806 53.372993 79.541237 51.217957 79.541237 37.074978 c
+79.541237 22.592926 74.912849 20.910866 72.899368 20.179115 c
+72.874573 20.170105 l
+70.874573 19.443008 63.707901 19.079468 51.374565 19.079468 c
+39.041229 19.079468 31.541231 19.147606 29.874565 20.170105 c
+29.809799 20.209839 29.740503 20.251427 29.667128 20.295456 c
+27.852257 21.384613 23.541233 23.971786 23.541231 37.074978 c
+23.541231 48.643181 27.141390 52.096687 29.046541 53.432724 c
+h
+6.110745 50.022545 m
+4.264367 50.594704 2.303756 49.561745 1.731598 47.715366 c
+0.604448 44.078007 0.000000 40.227291 0.000000 36.246513 c
+0.000000 32.265736 0.604446 28.415020 1.731598 24.777657 c
+2.303757 22.931274 4.264368 21.898323 6.110746 22.470474 c
+7.957124 23.042633 8.990082 25.003250 8.417923 26.849625 c
+7.495697 29.825687 7.000000 32.978302 7.000000 36.246513 c
+7.000000 39.514721 7.495698 42.667339 8.417924 45.643398 c
+8.990082 47.489777 7.957123 49.450386 6.110745 50.022545 c
+h
+96.438187 50.022545 m
+98.284569 50.594704 100.245178 49.561745 100.817337 47.715366 c
+101.944489 44.078007 102.548935 40.227291 102.548935 36.246513 c
+102.548935 32.265736 101.944489 28.415020 100.817337 24.777657 c
+100.245178 22.931274 98.284569 21.898323 96.438187 22.470474 c
+94.591812 23.042633 93.558853 25.003250 94.131012 26.849625 c
+95.053238 29.825687 95.548935 32.978302 95.548935 36.246513 c
+95.548935 39.514721 95.053238 42.667339 94.131012 45.643398 c
+93.558853 47.489777 94.591812 49.450386 96.438187 50.022545 c
+h
+38.008762 29.771294 m
+38.004486 29.766964 38.000195 29.762646 37.995884 29.758335 c
+36.824310 28.586765 34.924816 28.586765 33.753246 29.758335 c
+29.753244 33.758335 l
+28.581673 34.929909 28.581673 36.829403 29.753244 38.000977 c
+30.924818 39.172550 32.824314 39.172550 33.995884 38.000977 c
+35.874317 36.122543 l
+45.752640 46.000896 l
+46.924210 47.172470 48.823700 47.172470 49.995274 46.000896 c
+51.166843 44.829323 51.166843 42.929825 49.995274 41.758251 c
+38.028191 29.791130 l
+38.021751 29.784496 38.015274 29.777885 38.008762 29.771294 c
+h
+55.753242 33.001549 m
+54.581673 31.829971 54.581673 29.930473 55.753242 28.758900 c
+56.924812 27.587326 58.824306 27.587326 59.995876 28.758900 c
+63.874054 32.637089 l
+67.752632 28.758495 l
+68.924202 27.586922 70.823700 27.586922 71.995270 28.758495 c
+73.166840 29.930069 73.166840 31.829567 71.995270 33.001144 c
+68.116684 36.879734 l
+71.995270 40.758327 l
+73.166840 41.929905 73.166840 43.829399 71.995270 45.000977 c
+70.823700 46.172550 68.924202 46.172550 67.752632 45.000977 c
+63.874054 41.122383 l
+59.995876 45.000572 l
+58.824306 46.172146 56.924812 46.172146 55.753242 45.000572 c
+54.581673 43.828995 54.581673 41.929497 55.753242 40.757923 c
+59.631420 36.879734 l
+55.753242 33.001549 l
+h
+f*
+n
+Q
+
+endstream
+endobj
+
+3 0 obj
+  4196
+endobj
+
+4 0 obj
+  << /Annots []
+     /Type /Page
+     /MediaBox [ 0.000000 0.000000 112.000000 112.000000 ]
+     /Resources 1 0 R
+     /Contents 2 0 R
+     /Parent 5 0 R
+  >>
+endobj
+
+5 0 obj
+  << /Kids [ 4 0 R ]
+     /Count 1
+     /Type /Pages
+  >>
+endobj
+
+6 0 obj
+  << /Pages 5 0 R
+     /Type /Catalog
+  >>
+endobj
+
+xref
+0 7
+0000000000 65535 f
+0000000010 00000 n
+0000000034 00000 n
+0000004286 00000 n
+0000004309 00000 n
+0000004484 00000 n
+0000004558 00000 n
+trailer
+<< /ID [ (some) (id) ]
+   /Root 6 0 R
+   /Size 7
+>>
+startxref
+4617
+%%EOF

+ 12 - 0
PDF Office/PDF Master/Class/Appearance/Image.xcassets/Home/ic_ai_rewriting_empty.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "Rewriting.pdf",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2230 - 0
PDF Office/PDF Master/Class/Appearance/Image.xcassets/Home/ic_ai_rewriting_empty.imageset/Rewriting.pdf


+ 260 - 38
PDF Office/PDF Master/Class/Home/ViewController/KMAIRewritingVC.swift

@@ -12,9 +12,6 @@ import Cocoa
     case AIErrorCorrection
 }
 
-//class KMAIRewritingVC: NSViewController {
-//}
-
 class KMAIRewritingVC: NSViewController {
 
     @IBOutlet weak var aiRewritingLabel: NSTextField!
@@ -39,16 +36,19 @@ class KMAIRewritingVC: NSViewController {
     @IBOutlet weak var errorView: NSView!
     @IBOutlet weak var errorImageView: NSImageView!
     @IBOutlet weak var errorLabel: NSTextField!
-
-    @IBOutlet weak var progressView: NSProgressIndicator!
     
     var state: KMAIRewritingState = .AIRewriting
     
-    var isExceed: Bool = false
-    var canRewriting: Bool = false
-    var canCopy: Bool = false
+    var _uiState: KMAITranslationState = .None
+    
     var aiRewritingStr: String = ""
     var aiErrorCorrectionStr: String = ""
+    var aiRewritingResultStr: String = ""
+    var aiErrorCorrectionResultStr: String = ""
+    var aiRewritingErrorStr: String = ""
+    var aiErrorCorrectionErrorStr: String = ""
+    
+    var progressController: SKProgressController?
 
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -61,8 +61,6 @@ class KMAIRewritingVC: NSViewController {
     // MARK: initialize
     
     func initializeUI() -> Void {
-        self.progressView.isHidden = true
-
         self.aiRewritingLabel.textColor = NSColor(hex: "#252629")
         self.aiRewritingLabel.font = NSFont.SFProTextSemibold(20.0)
         self.aiRewritingSubLabel.textColor = NSColor(hex: "#94989C")
@@ -89,6 +87,12 @@ class KMAIRewritingVC: NSViewController {
         self.errorImageView.image = NSImage(named: "icon_error")
         self.errorLabel.textColor = NSColor(hex: "#F3465B")
         self.errorLabel.font = NSFont.SFProTextRegular(12.0)
+        
+        if self.state == .AIRewriting {
+            self.emptyImageView.image = NSImage(named: "ic_ai_rewriting_empty")
+        } else if self.state == .AIErrorCorrection {
+            self.emptyImageView.image = NSImage(named: "ic_ai_ErrorCorrection_empty")
+        }
     }
     
     func initLocalization() -> Void {
@@ -102,6 +106,7 @@ class KMAIRewritingVC: NSViewController {
             self.rewritingTextField.placeholderString = NSLocalizedString("Please enter text content here...", comment: "")
             self.wordsLabel.stringValue = NSLocalizedString("0/150", comment: "")
             self.rewritingTextField.stringValue = self.aiRewritingStr
+            self.resultTextView.string = self.aiRewritingResultStr
             break
         case .AIErrorCorrection:
             self.aiRewritingLabel.stringValue = NSLocalizedString("AI Error Correction", comment: "")
@@ -112,51 +117,261 @@ class KMAIRewritingVC: NSViewController {
             self.rewritingTextField.placeholderString = NSLocalizedString("Please enter text content here...", comment: "")
             self.wordsLabel.stringValue = NSLocalizedString("0/150", comment: "")
             self.rewritingTextField.stringValue = self.aiErrorCorrectionStr
+            self.resultTextView.string = self.aiErrorCorrectionResultStr
             break
         default:
             break
         }
     }
     
+    // MARK: Get、Set
+    
+    var uiState: KMAITranslationState {
+        get {
+            return _uiState
+        }
+        set {
+            _uiState = newValue
+            
+            self.refreshAIUI()
+        }
+    }
+    
+    // MARK: Private Methods
+
+    func refreshAIUI() -> Void {
+        self.wordsLabel.stringValue = String(format: "%d/150", self.rewritingTextField.stringValue.count)
+        self.copyLabel.stringValue = NSLocalizedString("Copy", comment: "")
+
+        if self.uiState == .CanAIRewriting || self.uiState == .CanAIErrorCorrection {
+            self.rewritingBox.fillColor = NSColor(hex: "#1770F4")
+            self.rewritingBox.borderWidth = 0.0
+            self.rewritingLabel.textColor = NSColor(hex: "#FFFFFF")
+            self.copyBox.fillColor = NSColor(hex: "#EDEEF0")
+            self.copyBox.borderWidth = 1.0
+            self.copyBox.borderColor = NSColor(hex: "#DFE1E5")
+            self.copyLabel.textColor = NSColor(hex: "#B1B3B8")
+            self.wordsLabel.textColor = NSColor(hex: "#94989C")
+            self.resultTextBox.fillColor = NSColor(hex: "#FFFFFF")
+            self.resultTextBox.borderWidth = 1.0
+            self.rewritingBox.borderColor = NSColor(hex: "#DFE1E5")
+            self.emptyImageView.isHidden = false
+            self.errorView.isHidden = true
+        } else if self.uiState == .CanCopy {
+            self.rewritingBox.fillColor = NSColor(hex: "#1770F4")
+            self.rewritingBox.borderWidth = 0.0
+            self.rewritingLabel.textColor = NSColor(hex: "#FFFFFF")
+            self.copyBox.fillColor = NSColor(hex: "#FFFFFF")
+            self.copyBox.borderWidth = 1.0
+            self.copyBox.borderColor = NSColor(hex: "#DFE1E5")
+            self.copyLabel.textColor = NSColor(hex: "#252629")
+            self.wordsLabel.textColor = NSColor(hex: "#94989C")
+            self.resultTextBox.fillColor = NSColor(hex: "#FFFFFF")
+            self.resultTextBox.borderWidth = 1.0
+            self.rewritingBox.borderColor = NSColor(hex: "#DFE1E5")
+            self.emptyImageView.isHidden = true
+            self.errorView.isHidden = true
+        } else if self.uiState == .Copyed {
+            self.rewritingBox.fillColor = NSColor(hex: "#1770F4")
+            self.rewritingBox.borderWidth = 0.0
+            self.rewritingLabel.textColor = NSColor(hex: "#FFFFFF")
+            self.copyBox.fillColor = NSColor(hex: "#36383B")
+            self.copyBox.borderWidth = 0.0
+            self.copyLabel.textColor = NSColor(hex: "#FFFFFF")
+            self.copyLabel.stringValue = NSLocalizedString("Copied", comment: "")
+            self.wordsLabel.textColor = NSColor(hex: "#94989C")
+            self.resultTextBox.fillColor = NSColor(hex: "#FFFFFF")
+            self.resultTextBox.borderWidth = 1.0
+            self.rewritingBox.borderColor = NSColor(hex: "#DFE1E5")
+            self.emptyImageView.isHidden = true
+            self.errorView.isHidden = true
+        } else if self.uiState == .Exceed { // 是否超过
+            self.rewritingBox.fillColor = NSColor(hex: "#1770F4")
+            self.rewritingBox.borderWidth = 0.0
+            self.rewritingLabel.textColor = NSColor(hex: "#FFFFFF")
+            self.copyBox.fillColor = NSColor(hex: "#EDEEF0")
+            self.copyBox.borderWidth = 1.0
+            self.copyBox.borderColor = NSColor(hex: "#DFE1E5")
+            self.copyLabel.textColor = NSColor(hex: "#B1B3B8")
+            self.wordsLabel.textColor = NSColor(hex: "#F3465B")
+            self.resultTextBox.fillColor = NSColor(hex: "#FFFFFF")
+            self.resultTextBox.borderWidth = 1.0
+            self.rewritingBox.borderColor = NSColor(hex: "#F3465B")
+            self.emptyImageView.isHidden = true
+            self.errorView.isHidden = false
+            self.errorLabel.stringValue = NSLocalizedString("Limit 150 characters at a time", comment: "")
+        } else if self.uiState == .Error {
+            self.rewritingBox.fillColor = NSColor(hex: "#1770F4")
+            self.rewritingBox.borderWidth = 0.0
+            self.rewritingLabel.textColor = NSColor(hex: "#FFFFFF")
+            self.copyBox.fillColor = NSColor(hex: "#EDEEF0")
+            self.copyBox.borderWidth = 1.0
+            self.copyBox.borderColor = NSColor(hex: "#DFE1E5")
+            self.copyLabel.textColor = NSColor(hex: "#B1B3B8")
+            if self.rewritingTextField.stringValue.count > 150 {
+                self.wordsLabel.textColor = NSColor(hex: "#F3465B")
+            } else {
+                self.wordsLabel.textColor = NSColor(hex: "#94989C")
+            }
+            self.resultTextBox.fillColor = NSColor(hex: "#FFFFFF")
+            self.resultTextBox.borderWidth = 1.0
+            self.rewritingBox.borderColor = NSColor(hex: "#F3465B")
+            self.emptyImageView.isHidden = true
+            self.errorView.isHidden = false
+            if self.state == .AIRewriting {
+                self.errorLabel.stringValue = self.aiRewritingErrorStr
+            } else if self.state == .AIErrorCorrection {
+                self.errorLabel.stringValue = self.aiErrorCorrectionErrorStr
+            }
+        } else {
+            self.rewritingBox.fillColor = NSColor(hex: "#BDDFFD")
+            self.rewritingBox.borderWidth = 0.0
+            self.rewritingLabel.textColor = NSColor(hex: "#F7F8FA")
+            self.copyBox.fillColor = NSColor(hex: "#EDEEF0")
+            self.copyBox.borderWidth = 1.0
+            self.copyBox.borderColor = NSColor(hex: "#DFE1E5")
+            self.copyLabel.textColor = NSColor(hex: "#B1B3B8")
+            self.wordsLabel.textColor = NSColor(hex: "#94989C")
+            self.resultTextBox.fillColor = NSColor(hex: "#FFFFFF")
+            self.resultTextBox.borderWidth = 1.0
+            self.rewritingBox.borderColor = NSColor(hex: "#DFE1E5")
+            self.emptyImageView.isHidden = false
+            self.errorView.isHidden = true
+        }
+    }
+    
+    func acquisition_uiState() -> Void {
+        if self.state == .AIRewriting {
+            if (self.aiRewritingStr.count > 0) && (self.aiRewritingResultStr.count > 0) {
+                let pasteboard = NSPasteboard.general
+                if pasteboard.string(forType: .string)!.count > 0 {
+                    if pasteboard.string(forType: .string)! == self.aiRewritingResultStr {
+                        self.uiState = .CanCopy
+                    } else {
+                        self.uiState = .Copyed
+                    }
+                } else {
+                    self.uiState = .Copyed
+                }
+            } else if (self.aiRewritingStr.count > 0) {
+                if self.aiRewritingStr.count > 150 {
+                    self.uiState = .Exceed
+                } else {
+                    self.uiState = .CanAIRewriting
+                }
+            } else {
+                if self.aiRewritingErrorStr.count > 0 {
+                    self.uiState = .Error
+                } else {
+                    self.uiState = .None
+                }
+            }
+        } else if self.state == .AIErrorCorrection {
+            if (self.aiErrorCorrectionStr.count > 0) && (self.aiErrorCorrectionResultStr.count > 0) {
+                let pasteboard = NSPasteboard.general
+                if pasteboard.string(forType: .string)!.count > 0 {
+                    if pasteboard.string(forType: .string)! == self.aiErrorCorrectionResultStr {
+                        self.uiState = .CanCopy
+                    } else {
+                        self.uiState = .Copyed
+                    }
+                } else {
+                    self.uiState = .Copyed
+                }
+            } else if (self.aiErrorCorrectionStr.count > 0) {
+                if self.aiErrorCorrectionStr.count > 150 {
+                    self.uiState = .Exceed
+                } else {
+                    self.uiState = .CanAIRewriting
+                }
+            } else {
+                if self.aiErrorCorrectionErrorStr.count > 0 {
+                    self.uiState = .Error
+                } else {
+                    self.uiState = .None
+                }
+            }
+        }
+    }
+    
+    func showProgressWindow() {
+        let progress = SKProgressController()
+        if self.state == .AIRewriting {
+            progress.message = NSLocalizedString("Under Rewrite...", comment: "")
+        } else if self.state == . AIErrorCorrection {
+            progress.message = NSLocalizedString("Error Correction...", 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.view.window?.beginSheet(progress.window!)
+    }
+    
+    func hiddenProgressWindow() {
+        if (self.progressController != nil) {
+            self.view.window?.endSheet((self.progressController?.window)!)
+            self.progressController = nil
+        }
+    }
+    
     // MARK: Action
     
     @IBAction func aiRewritingAction(_ sender: NSButton) {
-        if self.canRewriting {
+        if self.uiState == .CanAIRewriting || self.uiState == .CanAIErrorCorrection || self.uiState == .CanCopy || self.uiState == .Copyed || self.uiState == .Exceed || self.uiState == .Error {
             self.errorView.isHidden = true
-            self.progressView.isHidden = false
-            
+            DispatchQueue.main.async {
+                self.showProgressWindow()
+            }
+
             let infoDictionary = Bundle .main.infoDictionary!
             let majorVersion = infoDictionary["CFBundleShortVersionString"]
             KMRequestServerManager.manager.aiRewriting(content: self.rewritingTextField.stringValue, version: "1.0.1", state: self.state) { [unowned self] success, result in
-                self.progressView.isHidden = true
-                let result: NSDictionary = result!.result
+                self.hiddenProgressWindow()
+
                 if success {
-                    self.copyBox.fillColor = NSColor(hex: "#FFFFFF")
-                    self.copyBox.borderColor = NSColor(hex: "#DFE1E5")
-                    self.copyLabel.textColor = NSColor(hex: "#252629")
-                    self.canCopy = true
+                    let result: NSDictionary = result!.result
+                    self.uiState = .CanCopy
                     
                     self.resultTextView.string = ""
                     self.resultTextView.string =  result["content"] as? String ?? ""
+                    if self.state == .AIRewriting {
+                        self.aiRewritingResultStr = result["content"] as? String ?? ""
+                        self.aiRewritingErrorStr = ""
+                    } else if self.state == .AIErrorCorrection {
+                        self.aiErrorCorrectionResultStr = result["content"] as? String ?? ""
+                        self.aiErrorCorrectionErrorStr = ""
+                    }
                 } else {
-                    self.copyBox.borderColor = NSColor(hex: "#DFE1E5")
-                    self.copyBox.fillColor = NSColor(hex: "#EDEEF0")
-                    self.canCopy = false
+                    let result: String = result!.message
                     
-                    self.resultTextView.string = ""
-
-                    self.errorView.isHidden = false
-                    self.errorLabel.stringValue = "error"
+                    DispatchQueue.main.async {
+                        self.resultTextView.string = ""
+                        self.errorLabel.stringValue = result
+                        if self.state == .AIRewriting {
+                            self.aiRewritingErrorStr = result
+                        } else if self.state == .AIErrorCorrection {
+                            self.aiErrorCorrectionErrorStr = result
+                        }
+                        self.uiState = .Error
+                    }
                 }
             }
         }
     }
     
     @IBAction func copyAction(_ sender: NSButton) {
-        if self.canCopy {
+        if self.uiState == .CanCopy || self.uiState == .Copyed {
             let pasteboard = NSPasteboard.general
             pasteboard.clearContents()
             pasteboard.setString(self.resultTextView.string, forType: .string)
+            
+            self.uiState = .Copyed
         }
     }
 }
@@ -172,21 +387,28 @@ extension KMAIRewritingVC: NSTextFieldDelegate {
         self.wordsLabel.stringValue = String(format: "%d/150", object.stringValue.count)
         
         if object.stringValue.count > 0 {
-            self.rewritingBox.fillColor = NSColor(hex: "#1770F4")
-            self.rewritingLabel.textColor = NSColor(hex: "#FFFFFF")
-            self.canRewriting = true
+            if self.state == .AIRewriting {
+                self.uiState = .CanAIRewriting
+            } else if self.state == .AIErrorCorrection {
+                self.uiState = .CanAIErrorCorrection
+            }
         } else {
-            self.rewritingBox.fillColor = NSColor(hex: "#BDDFFD")
-            self.rewritingLabel.textColor = NSColor(hex: "#F7F8FA")
-            self.canRewriting = false
+            self.uiState = .None
         }
         
-        if object.stringValue.count >= 150 {
-            self.wordsLabel.textColor = NSColor(hex: "#F3465B")
-            self.isExceed = true
+        if object.stringValue.count > 150 {
+            self.uiState = .Exceed
+            if self.state == .AIRewriting {
+                self.aiRewritingErrorStr = NSLocalizedString("Limit 150 characters at a time", comment: "")
+            } else if self.state == .AIErrorCorrection {
+                self.aiErrorCorrectionErrorStr = NSLocalizedString("Limit 150 characters at a time", comment: "")
+            }
         } else {
-            self.wordsLabel.textColor = NSColor(hex: "#94989C")
-            self.isExceed = false
+            if self.state == .AIRewriting {
+                self.aiRewritingErrorStr = ""
+            } else if self.state == .AIErrorCorrection {
+                self.aiErrorCorrectionErrorStr = ""
+            }
         }
         
         if self.state == .AIRewriting {

+ 9 - 15
PDF Office/PDF Master/Class/Home/ViewController/KMAIRewritingVC.xib

@@ -16,7 +16,6 @@
                 <outlet property="errorImageView" destination="92Z-hh-WAn" id="g4b-en-gUl"/>
                 <outlet property="errorLabel" destination="rdP-tN-TLc" id="E37-eu-Wpx"/>
                 <outlet property="errorView" destination="Ku7-Fg-Cbu" id="KX8-wO-8Wr"/>
-                <outlet property="progressView" destination="jUa-Yh-Prc" id="xL4-4r-dwP"/>
                 <outlet property="resultLabel" destination="CcX-M0-1q3" id="y4c-Di-r2g"/>
                 <outlet property="resultTextBox" destination="4LD-1L-j3y" id="4x4-YF-FVe"/>
                 <outlet property="resultTextView" destination="t7u-24-0rL" id="9mk-Jg-2nv"/>
@@ -98,7 +97,7 @@
                         <subviews>
                             <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="FtX-Qb-KWb">
                                 <rect key="frame" x="18" y="16" width="884" height="226"/>
-                                <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" id="r6I-eI-IDZ">
+                                <textFieldCell key="cell" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" id="r6I-eI-IDZ">
                                     <font key="font" metaFont="system"/>
                                     <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                     <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -182,14 +181,6 @@
                         <rect key="frame" x="1" y="1" width="920" height="312"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="4sx-UX-pUY">
-                                <rect key="frame" x="404" y="100" width="112" height="112"/>
-                                <constraints>
-                                    <constraint firstAttribute="width" constant="112" id="MdD-ld-8ne"/>
-                                    <constraint firstAttribute="height" constant="112" id="iHR-9b-fwH"/>
-                                </constraints>
-                                <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="ei9-ff-0j6"/>
-                            </imageView>
                             <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="E6R-D2-LdC">
                                 <rect key="frame" x="20" y="16" width="880" height="280"/>
                                 <clipView key="contentView" drawsBackground="NO" id="qAu-R2-m8b">
@@ -245,6 +236,14 @@
                                     <constraint firstItem="rdP-tN-TLc" firstAttribute="centerY" secondItem="92Z-hh-WAn" secondAttribute="centerY" id="zXG-pF-Q1J"/>
                                 </constraints>
                             </customView>
+                            <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="4sx-UX-pUY">
+                                <rect key="frame" x="404" y="100" width="112" height="112"/>
+                                <constraints>
+                                    <constraint firstAttribute="width" constant="112" id="MdD-ld-8ne"/>
+                                    <constraint firstAttribute="height" constant="112" id="iHR-9b-fwH"/>
+                                </constraints>
+                                <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="ei9-ff-0j6"/>
+                            </imageView>
                         </subviews>
                         <constraints>
                             <constraint firstItem="E6R-D2-LdC" firstAttribute="leading" secondItem="YQK-PU-YI0" secondAttribute="leading" constant="20" id="1TR-SU-1bb"/>
@@ -260,9 +259,6 @@
                         <constraint firstItem="4sx-UX-pUY" firstAttribute="centerY" secondItem="4LD-1L-j3y" secondAttribute="centerY" id="a2Q-Ab-ntv"/>
                     </constraints>
                 </box>
-                <progressIndicator maxValue="100" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="jUa-Yh-Prc">
-                    <rect key="frame" x="485" y="399" width="16" height="16"/>
-                </progressIndicator>
             </subviews>
             <constraints>
                 <constraint firstItem="4LD-1L-j3y" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="32" id="2DE-fN-S6m"/>
@@ -280,8 +276,6 @@
                 <constraint firstAttribute="trailing" secondItem="nAH-C5-vHu" secondAttribute="trailing" constant="32" id="aMq-Hw-FfN"/>
                 <constraint firstAttribute="bottom" secondItem="4LD-1L-j3y" secondAttribute="bottom" constant="54" id="apc-oC-7Q1"/>
                 <constraint firstAttribute="trailing" secondItem="lIX-7t-9jP" secondAttribute="trailing" constant="32" id="avX-D5-lW9"/>
-                <constraint firstItem="jUa-Yh-Prc" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="i4K-Kx-guf"/>
-                <constraint firstItem="jUa-Yh-Prc" firstAttribute="centerY" secondItem="Hz6-mo-xeY" secondAttribute="centerY" id="kKZ-8J-v0c"/>
                 <constraint firstItem="m6U-x3-0JF" firstAttribute="top" secondItem="nAH-C5-vHu" secondAttribute="bottom" constant="12" id="qfY-wb-k87"/>
                 <constraint firstItem="4LD-1L-j3y" firstAttribute="top" secondItem="bYV-sq-gG7" secondAttribute="bottom" constant="12" id="we8-1D-IF7"/>
                 <constraint firstItem="CcX-M0-1q3" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="32" id="zpm-Kx-3Np"/>

+ 2 - 0
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -551,6 +551,7 @@ import KMAdvertisement
             self.rightFullBox.contentView = self.aiRewritingViewController.view
             self.aiRewritingViewController.state = .AIRewriting
             self.aiRewritingViewController.initLocalization()
+            self.aiRewritingViewController.acquisition_uiState()
             break
         case .AIErrorCorrection:
             self.aiErrorCorrectionBox.fillColor = NSColor(hex: "#1770F4", alpha: 0.1)
@@ -563,6 +564,7 @@ import KMAdvertisement
             self.rightFullBox.contentView = self.aiRewritingViewController.view
             self.aiRewritingViewController.state = .AIErrorCorrection
             self.aiRewritingViewController.initLocalization()
+            self.aiRewritingViewController.acquisition_uiState()
             break
         default:
             break

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

@@ -10,6 +10,8 @@ import Cocoa
 @objc enum KMAITranslationState: Int {
     case None = 0
     case CanTranslate
+    case CanAIRewriting
+    case CanAIErrorCorrection
     case CanCopy
     case Copyed
     case Exceed

+ 20 - 21
PDF Office/PDF Master/Class/PDFTools/Convert/Controller/KMConvertBaseWindowController.xib

@@ -1,12 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
-        <deployment identifier="macosx"/>
         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMConvertBaseWindowController" customModule="PDF_Office" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="KMConvertBaseWindowController" customModule="PDF_Master" customModuleProvider="target">
             <connections>
                 <outlet property="backBox" destination="gFg-Q7-54m" id="8ww-CO-9PP"/>
                 <outlet property="batchButton" destination="iFO-Ki-C0L" id="KTA-dQ-WkN"/>
@@ -30,7 +29,7 @@
             <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
             <rect key="contentRect" x="196" y="240" width="586" height="483"/>
-            <rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
+            <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1415"/>
             <value key="minSize" type="size" width="586" height="483"/>
             <value key="maxSize" type="size" width="586" height="483"/>
             <view key="contentView" id="se5-gp-TjO">
@@ -67,7 +66,7 @@
                             <rect key="frame" x="0.0" y="0.0" width="212" height="320"/>
                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                             <subviews>
-                                <customView translatesAutoresizingMaskIntoConstraints="NO" id="mvl-fd-L7y" customClass="KMCustomPDFView" customModule="PDF_Office" customModuleProvider="target">
+                                <customView translatesAutoresizingMaskIntoConstraints="NO" id="mvl-fd-L7y" customClass="KMCustomPDFView" customModule="PDF_Master" customModuleProvider="target">
                                     <rect key="frame" x="16" y="56" width="182" height="248"/>
                                 </customView>
                                 <customView translatesAutoresizingMaskIntoConstraints="NO" id="XyN-M5-Ckr">
@@ -166,21 +165,21 @@
                                 <scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jkb-2v-6fa">
                                     <rect key="frame" x="0.0" y="0.0" width="358" height="391"/>
                                     <clipView key="contentView" id="tI2-Vq-Nms">
-                                        <rect key="frame" x="0.0" y="0.0" width="358" height="391"/>
+                                        <rect key="frame" x="0.0" y="0.0" width="343" height="376"/>
                                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                         <subviews>
                                             <view id="dBH-xr-mGL">
-                                                <rect key="frame" x="0.0" y="0.0" width="343" height="376"/>
+                                                <rect key="frame" x="0.0" y="0.0" width="328" height="361"/>
                                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                             </view>
                                         </subviews>
                                     </clipView>
                                     <scroller key="horizontalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="MLK-hj-eAf">
-                                        <rect key="frame" x="0.0" y="375" width="358" height="16"/>
+                                        <rect key="frame" x="0.0" y="376" width="343" height="15"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                     </scroller>
                                     <scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="L4p-RZ-VGS">
-                                        <rect key="frame" x="342" y="0.0" width="16" height="391"/>
+                                        <rect key="frame" x="343" y="0.0" width="15" height="376"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                     </scroller>
                                 </scrollView>
@@ -275,7 +274,7 @@
             </connections>
             <point key="canvasLocation" x="13" y="100.5"/>
         </window>
-        <customView id="LzC-nd-jo2" customClass="KMConvertWordSettingView" customModule="PDF_Office" customModuleProvider="target">
+        <customView id="LzC-nd-jo2" customClass="KMConvertWordSettingView" customModule="PDF_Master" customModuleProvider="target">
             <rect key="frame" x="0.0" y="0.0" width="276" height="250"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
@@ -293,13 +292,13 @@
                                     <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                                 </textFieldCell>
                             </textField>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="sIu-Jp-911" customClass="KMImageTitleButton" customModule="PDF_Office" customModuleProvider="target">
+                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="sIu-Jp-911" customClass="KMImageTitleButton" customModule="PDF_Master" customModuleProvider="target">
                                 <rect key="frame" x="16" y="-50" width="244" height="22"/>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="22" id="vJn-IG-4gT"/>
                                 </constraints>
                             </customView>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="y6s-OJ-cG8" customClass="KMImageTitleButton" customModule="PDF_Office" customModuleProvider="target">
+                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="y6s-OJ-cG8" customClass="KMImageTitleButton" customModule="PDF_Master" customModuleProvider="target">
                                 <rect key="frame" x="16" y="-80" width="244" height="22"/>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="22" id="obd-W8-at7"/>
@@ -362,7 +361,7 @@
             </connections>
             <point key="canvasLocation" x="118" y="543"/>
         </customView>
-        <customView id="rMz-DL-eLf" customClass="KMConvertOCRSettingItemView" customModule="PDF_Office" customModuleProvider="target">
+        <customView id="rMz-DL-eLf" customClass="KMConvertOCRSettingItemView" customModule="PDF_Master" customModuleProvider="target">
             <rect key="frame" x="0.0" y="0.0" width="276" height="86"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
@@ -382,7 +381,7 @@
                     </buttonCell>
                 </button>
                 <comboBox verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="yE5-BA-JsU">
-                    <rect key="frame" x="24" y="14" width="233" height="25"/>
+                    <rect key="frame" x="23" y="15" width="234" height="23"/>
                     <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" completes="NO" numberOfVisibleItems="5" id="X84-Gf-tPc">
                         <font key="font" metaFont="system"/>
                         <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -411,7 +410,7 @@
             </connections>
             <point key="canvasLocation" x="436" y="466"/>
         </customView>
-        <customView id="pQ2-zT-XVA" customClass="KMConvertPageRangeSettingItemView" customModule="PDF_Office" customModuleProvider="target">
+        <customView id="pQ2-zT-XVA" customClass="KMConvertPageRangeSettingItemView" customModule="PDF_Master" customModuleProvider="target">
             <rect key="frame" x="0.0" y="0.0" width="280" height="76"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
@@ -449,7 +448,7 @@
             </connections>
             <point key="canvasLocation" x="438" y="599"/>
         </customView>
-        <customView id="Aiu-IG-eq4" customClass="KMConvertImageSettingView" customModule="PDF_Office" customModuleProvider="target">
+        <customView id="Aiu-IG-eq4" customClass="KMConvertImageSettingView" customModule="PDF_Master" customModuleProvider="target">
             <rect key="frame" x="0.0" y="0.0" width="276" height="250"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
@@ -468,7 +467,7 @@
                                 </textFieldCell>
                             </textField>
                             <comboBox hidden="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="A3v-M6-Ruh">
-                                <rect key="frame" x="24" y="50" width="215" height="25"/>
+                                <rect key="frame" x="23" y="51" width="216" height="23"/>
                                 <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" completes="NO" numberOfVisibleItems="5" id="KT9-cv-uGO">
                                     <font key="font" metaFont="system"/>
                                     <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -481,7 +480,7 @@
                                 </comboBoxCell>
                             </comboBox>
                             <comboBox verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="yhD-91-oLg">
-                                <rect key="frame" x="24" y="13" width="215" height="25"/>
+                                <rect key="frame" x="23" y="13" width="216" height="23"/>
                                 <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" completes="NO" numberOfVisibleItems="5" id="TKk-wg-Ocx">
                                     <font key="font" metaFont="system"/>
                                     <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -551,7 +550,7 @@
             </connections>
             <point key="canvasLocation" x="118" y="839.5"/>
         </customView>
-        <customView id="Gcl-gP-wFo" customClass="KMConvertCSVSettingView" customModule="PDF_Office" customModuleProvider="target">
+        <customView id="Gcl-gP-wFo" customClass="KMConvertCSVSettingView" customModule="PDF_Master" customModuleProvider="target">
             <rect key="frame" x="0.0" y="0.0" width="276" height="250"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
@@ -569,7 +568,7 @@
                                 </buttonCell>
                             </button>
                             <comboBox verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="uah-L1-IyT">
-                                <rect key="frame" x="32" y="-23" width="214" height="25"/>
+                                <rect key="frame" x="31" y="-22" width="215" height="23"/>
                                 <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" completes="NO" numberOfVisibleItems="5" id="X1R-ss-GZO">
                                     <font key="font" metaFont="system"/>
                                     <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -635,7 +634,7 @@
             </connections>
             <point key="canvasLocation" x="118" y="1154"/>
         </customView>
-        <customView id="xUu-ga-ZZ7" customClass="KMConvertPPTsSettingView" customModule="PDF_Office" customModuleProvider="target">
+        <customView id="xUu-ga-ZZ7" customClass="KMConvertPPTsSettingView" customModule="PDF_Master" customModuleProvider="target">
             <rect key="frame" x="0.0" y="0.0" width="276" height="250"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
@@ -674,7 +673,7 @@
             </connections>
             <point key="canvasLocation" x="118" y="1465"/>
         </customView>
-        <customView id="CNe-Pz-PVB" customClass="KMConvertExcelSettingView" customModule="PDF_Office" customModuleProvider="target">
+        <customView id="CNe-Pz-PVB" customClass="KMConvertExcelSettingView" customModule="PDF_Master" customModuleProvider="target">
             <rect key="frame" x="0.0" y="0.0" width="270" height="321"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>