|
@@ -179,7 +179,7 @@ import Cocoa
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(importFromScanner), name: Notification.Name("kDeviceScannerMenuItemNotification"), object: nil)
|
|
|
self.loadFunctionGuide()
|
|
|
|
|
|
- self.loadAIIconView()
|
|
|
+// self.loadAIIconView()
|
|
|
}
|
|
|
|
|
|
override func viewDidAppear() {
|
|
@@ -885,75 +885,40 @@ extension KMHomeViewController {
|
|
|
|
|
|
|
|
|
func showAITypeChooseView() -> Void {
|
|
|
- if AIInfoManager.default().aiInfo.infoDict.isEmpty == true {
|
|
|
-#if VERSION_DMG
|
|
|
- KMPurchaseCompareWindowController.dmgPurchaseInstance().showWindow(nil)
|
|
|
-#else
|
|
|
- AIPurchaseWindowController.currentWC().showWindow(nil)
|
|
|
-#endif
|
|
|
- return
|
|
|
- }
|
|
|
- let controller = NSViewController.init()
|
|
|
- let view = NSView.init()
|
|
|
- controller.view = view
|
|
|
-
|
|
|
- var string: String = NSLocalizedString("AI Summarize", comment: "")
|
|
|
- if string.count < NSLocalizedString("AI Rewrite", comment: "").count {
|
|
|
- string = NSLocalizedString("AI Rewrite", comment: "")
|
|
|
- }
|
|
|
- if string.count < NSLocalizedString("AI Proofread", comment: "").count {
|
|
|
- string = NSLocalizedString("AI Proofread", comment: "")
|
|
|
- }
|
|
|
- if string.count < NSLocalizedString("AI Translate", comment: "").count {
|
|
|
- string = NSLocalizedString("AI Translate", comment: "")
|
|
|
- }
|
|
|
-
|
|
|
- let font = NSFont.SFProTextRegularFont(13)
|
|
|
- var style = NSMutableParagraphStyle.init()
|
|
|
- style.alignment = .center
|
|
|
- style.lineBreakMode = .byCharWrapping
|
|
|
- let size: NSSize = string.boundingRect(with: NSSize(width: 1000, height: 100),
|
|
|
- options: NSString.DrawingOptions(rawValue: 3),
|
|
|
- attributes: [NSAttributedString.Key.font : NSFont.SFProTextRegularFont(13), NSAttributedString.Key.paragraphStyle : style]).size
|
|
|
-
|
|
|
- controller.view.frame = CGRectMake(0, 0, size.width+80, 160)
|
|
|
- if self.aiTypeChooseView == nil {
|
|
|
- self.aiTypeChooseView = AITypeChooseView.createFromNib()
|
|
|
- }
|
|
|
- self.aiTypeChooseView.clickHandle = { [weak self] view, type in
|
|
|
- DispatchQueue.main.async {
|
|
|
- let windowVC = AIConfigWindowController.currentWC()
|
|
|
- windowVC.configType = type
|
|
|
- if type == .summarize {
|
|
|
- windowVC.window?.setFrame(CGRectMake(0, 0, 800, 500), display: true)
|
|
|
- } else if type == .reWriting {
|
|
|
- windowVC.window?.setFrame(CGRectMake(0, 0, 800, 460), display: true)
|
|
|
- } else if type == .proofreading {
|
|
|
- windowVC.window?.setFrame(CGRectMake(0, 0, 800, 460), display: true)
|
|
|
- } else if type == .translate {
|
|
|
- windowVC.window?.setFrame(CGRectMake(0, 0, 800, 545), display: true)
|
|
|
+ let windowVC: AINewConfigWindowController = AINewConfigWindowController.currentWC()
|
|
|
+ windowVC.chooseCurFileHandle = {windowVC in
|
|
|
+ if AIChatInfoManager.defaultManager.currentFilePath.isEmpty == false {
|
|
|
+ let documentArray = NSDocumentController.shared.documents
|
|
|
+ var didFileEdit: Bool = false
|
|
|
+ var curDoc: KMMainDocument!
|
|
|
+ for document in documentArray {
|
|
|
+ if document.fileURL?.path == AIChatInfoManager.defaultManager.currentFilePath {
|
|
|
+ didFileEdit = document.isDocumentEdited
|
|
|
+ curDoc = document as! KMMainDocument
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- windowVC.cancelHandle = { [weak self] windowVC in
|
|
|
- self?.view.window?.endSheet(windowVC.window!)
|
|
|
+ if didFileEdit {
|
|
|
+ let tempFileURL = FileManager.default.temporaryDirectory.appendingPathComponent(AIChatInfoManager.defaultManager.currentFilePath.lastPathComponent)
|
|
|
+ if FileManager.default.fileExists(atPath: tempFileURL.path) {
|
|
|
+ do {
|
|
|
+ try FileManager.default.removeItem(at: tempFileURL)
|
|
|
+
|
|
|
+ } catch {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if curDoc != nil {
|
|
|
+ curDoc.mainViewController?.SaveTempPDFDocumentToURLPath(tempPath: tempFileURL.path)
|
|
|
+ }
|
|
|
}
|
|
|
- windowVC.refreshUI()
|
|
|
- self?.view.window?.beginSheet(windowVC.window!)
|
|
|
- windowVC.refreshUI()
|
|
|
+ windowVC.window?.becomeMain()
|
|
|
}
|
|
|
}
|
|
|
- self.aiTypeChooseView.frame = controller.view.bounds
|
|
|
- self.aiTypeChooseView.autoresizingMask = [.width, .height]
|
|
|
- controller.view.addSubview(self.aiTypeChooseView)
|
|
|
+ windowVC.window?.center()
|
|
|
+ windowVC.eventLabel = "AITools_Onboard"
|
|
|
+ windowVC.showWindow(nil)
|
|
|
|
|
|
- let popover = NSPopover.init()
|
|
|
- popover.contentViewController = controller
|
|
|
- popover.animates = true
|
|
|
- popover.behavior = .transient
|
|
|
- var rect = self.aiTipView.bounds
|
|
|
- rect.origin.y += 20
|
|
|
- popover.show(relativeTo: rect, of: self.aiTipView, preferredEdge: .minY)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
func loadAITipIconGuide() {
|