|
@@ -264,7 +264,7 @@ import Cocoa
|
|
|
|
|
|
if (self.document == nil || self.document!.isLocked == false) {
|
|
if (self.document == nil || self.document!.isLocked == false) {
|
|
self.loadFunctionGuide()
|
|
self.loadFunctionGuide()
|
|
- self.loadAIIconView()
|
|
|
|
|
|
+// self.loadAIIconView()
|
|
}
|
|
}
|
|
|
|
|
|
if (self.document?.isLocked == false) {
|
|
if (self.document?.isLocked == false) {
|
|
@@ -691,7 +691,7 @@ import Cocoa
|
|
if self.aiTipView == nil {
|
|
if self.aiTipView == nil {
|
|
self.aiTipView = AITipIconView.createFromNib()
|
|
self.aiTipView = AITipIconView.createFromNib()
|
|
self.aiTipView.clickHandle = { [weak self] view in
|
|
self.aiTipView.clickHandle = { [weak self] view in
|
|
- self?.showAITypeChooseView()
|
|
|
|
|
|
+// self?.showAITypeChooseView()
|
|
}
|
|
}
|
|
self.aiTipView.rightClickHandle = { view in
|
|
self.aiTipView.rightClickHandle = { view in
|
|
AIInfoManager.default().showAIIcon = false
|
|
AIInfoManager.default().showAIIcon = false
|
|
@@ -723,91 +723,61 @@ import Cocoa
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- 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: "")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _ = NSFont.SFProTextRegularFont(13)
|
|
|
|
- let 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 {
|
|
|
|
- self?.loadAIConfigWindowWithType(type)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- self.aiTypeChooseView.frame = controller.view.bounds
|
|
|
|
- self.aiTypeChooseView.autoresizingMask = [.width, .height]
|
|
|
|
- controller.view.addSubview(self.aiTypeChooseView)
|
|
|
|
|
|
+ func showAITypeChooseView(aiConfigType: AIConfigType) -> Void {
|
|
|
|
|
|
- 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 loadAIConfigWindowWithType(_ type: AIConfigType) -> Void {
|
|
|
|
- if AIInfoManager.default().aiInfo.infoDict.isEmpty == true {
|
|
|
|
-#if VERSION_DMG
|
|
|
|
- KMPurchaseCompareWindowController.dmgPurchaseInstance().showWindow(nil)
|
|
|
|
-#else
|
|
|
|
- AIPurchaseWindowController.currentWC().showWindow(nil)
|
|
|
|
-#endif
|
|
|
|
- return
|
|
|
|
|
|
+ if (self.document != nil) {
|
|
|
|
+ AIChatInfoManager.defaultManager.currentFilePath = (self.document?.documentURL.path)!
|
|
|
|
+ } else {
|
|
|
|
+ AIChatInfoManager.defaultManager.currentFilePath = ""
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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.window?.becomeMain()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- let windowVC = AIConfigWindowController.currentWC()
|
|
|
|
- windowVC.configType = type
|
|
|
|
- if type == .summarize {
|
|
|
|
- windowVC.window?.setFrame(CGRectMake(0, 0, 800, 500), display: true)
|
|
|
|
- FMTrackEventManager.defaultManager.trackEvent(event: "AITools", withProperties: ["AITools_Btn": "AISum"])
|
|
|
|
- } else if type == .reWriting {
|
|
|
|
- windowVC.window?.setFrame(CGRectMake(0, 0, 800, 460), display: true)
|
|
|
|
- FMTrackEventManager.defaultManager.trackEvent(event: "AITools", withProperties: ["AITools_Btn": "AIRewrite"])
|
|
|
|
- } else if type == .proofreading {
|
|
|
|
- windowVC.window?.setFrame(CGRectMake(0, 0, 800, 460), display: true)
|
|
|
|
- FMTrackEventManager.defaultManager.trackEvent(event: "AITools", withProperties: ["AITools_Btn": "AIProofread"])
|
|
|
|
- } else if type == .translate {
|
|
|
|
- windowVC.window?.setFrame(CGRectMake(0, 0, 800, 545), display: true)
|
|
|
|
- FMTrackEventManager.defaultManager.trackEvent(event: "AITools", withProperties: ["AITools_Btn": "AITranslate"])
|
|
|
|
|
|
+ if windowVC.window?.isVisible == true {
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ var windowRect = windowVC.window?.frame
|
|
|
|
+ windowRect!.origin.x = CGRectGetMaxX(self.view.window!.frame) - (windowRect?.size.width)!
|
|
|
|
+ windowRect!.origin.y = CGRectGetMaxY(self.view.window!.frame) - (windowRect?.size.height)! - 64
|
|
|
|
+ windowVC.window?.setFrame(windowRect!, display: true)
|
|
}
|
|
}
|
|
-
|
|
|
|
- windowVC.cancelHandle = { [weak self] windowVC in
|
|
|
|
- self?.view.window?.endSheet(windowVC.window!)
|
|
|
|
|
|
+ windowVC.eventLabel = "AITools_Tbr"
|
|
|
|
+ windowVC.showWindow(nil)
|
|
|
|
+ if (aiConfigType != .none) {
|
|
|
|
+ windowVC.eventLabel = "AITools_Start"
|
|
|
|
+ if self.listView.currentSelection.string().isEmpty == false {
|
|
|
|
+ windowVC.setCurrentPDFSelection(self.listView.currentSelection.string())
|
|
|
|
+ }
|
|
|
|
+ windowVC.chooseAIFunctionWithType(aiConfigType)
|
|
}
|
|
}
|
|
- windowVC.refreshUI()
|
|
|
|
- self.view.window?.beginSheet(windowVC.window!)
|
|
|
|
- windowVC.refreshUI()
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@objc func aiTipIconViewShowStateChangeNoti() {
|
|
@objc func aiTipIconViewShowStateChangeNoti() {
|
|
@@ -1904,7 +1874,7 @@ import Cocoa
|
|
internal func documentDidUnlockNotification(_ sender: Notification) {
|
|
internal func documentDidUnlockNotification(_ sender: Notification) {
|
|
if (self.listView.document != nil && self.listView.document.isEqual(to: sender.object)) {
|
|
if (self.listView.document != nil && self.listView.document.isEqual(to: sender.object)) {
|
|
|
|
|
|
- self.loadAIIconView()
|
|
|
|
|
|
+// self.loadAIIconView()
|
|
|
|
|
|
if (self.myDocument == nil) {
|
|
if (self.myDocument == nil) {
|
|
return
|
|
return
|