소스 검색

【综合】阅读界面补充AI按钮&逻辑

niehaoyu 1 년 전
부모
커밋
5079534190

+ 9 - 8
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -95,6 +95,7 @@ import Cocoa
     var timer: Timer?
     var timerCounter = 0.0
     
+    //AI相关
     var aiTipView: AITipIconView!
     var aiTypeChooseView: AITypeChooseView!
     
@@ -784,14 +785,14 @@ extension KMHomeViewController {
     }
     
     func showAITypeChooseView() -> Void {
-    //    if ([AIInfoManager defaultManager].aiInfo.infoDict.allKeys.count == 0) {
-    //#if VERSION_DMG
-    //        [[KMPurchaseCompareWindowController DMGPurchaseInstance] showWindow:nil];
-    //#else
-    //        [[AIPurchaseWindowController currentWC] showWindow:nil];
-    //#endif
-    //        return;
-    //    }
+        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

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

@@ -71,6 +71,10 @@ let LOCKED_KEY  = "locked"
     //自动滚动
     var autoFlowOptionsSheetController: KMAutoFlowOptionsSheetController?
     
+    //AI相关
+    var aiTipView: AITipIconView!
+    var aiTypeChooseView: AITypeChooseView!
+    
     //Search
     var searchIndex: Int = 0
     
@@ -259,6 +263,7 @@ let LOCKED_KEY  = "locked"
         
         if (self.document!.isLocked == false) {
             self.loadFunctionGuide()
+            self.loadAIIconView()
         }
         
         if (self.document == nil) {
@@ -726,6 +731,89 @@ let LOCKED_KEY  = "locked"
         return self._getPDFRedactController() != nil
     }
     
+    //MARK: - AI
+    func loadAIIconView() -> Void {
+        self.aiTipView = AITipIconView.createFromNib()
+        self.aiTipView.clickHandle = { [weak self] view in
+            self?.showAITypeChooseView()
+        }
+        self.aiTipView.frame = CGRectMake(CGRectGetWidth(self.view.frame)-84, CGRectGetHeight(self.view.frame)-84-64-50, 72, 72)
+        self.aiTipView.autoresizingMask = [.minXMargin, .minYMargin]
+        self.view.addSubview(self.aiTipView)
+
+    }
+    
+    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)
+                }
+                
+                windowVC.cancelHandle = { [weak self] windowVC in
+                    self?.view.window?.endSheet(windowVC.window!)
+                }
+                self?.view.window?.beginSheet(windowVC.window!)
+                windowVC.refreshUI()
+            }
+        }
+        self.aiTypeChooseView.frame = controller.view.bounds
+        self.aiTypeChooseView.autoresizingMask = [.width, .height]
+        controller.view.addSubview(self.aiTypeChooseView)
+        
+        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)
+
+    }
+    
     //MARK: - 引导
     func loadFunctionGuide() -> Void {
 
@@ -1837,6 +1925,9 @@ let LOCKED_KEY  = "locked"
     
     internal func documentDidUnlockNotification(_ sender: Notification) {
         if (self.listView.document != nil && self.listView.document.isEqual(to: sender.object)) {
+            
+            self.loadAIIconView()
+            
             if (self.myDocument == nil) {
                 return
             }

+ 2 - 0
PDF Office/PDF Master/Class/Purchase/Appstore/KMPurchaseCompareWindowController.h

@@ -12,6 +12,8 @@
 
 + (NSWindowController *)sharedInstance;
 
++ (NSWindowController *)DMGPurchaseInstance;
+
 - (IBAction)startModal:(id)sender;
 - (IBAction)endModal:(id)sender;
 

+ 9 - 0
PDF Office/PDF Master/Class/Purchase/Appstore/KMPurchaseCompareWindowController.m

@@ -320,6 +320,15 @@ static NSString *const KMPurchaseCompareCellIdentifier       = @"KMPurchaseCompa
 #endif
 }
 
++ (NSWindowController *)DMGPurchaseInstance {
+    static KMPurchaseCompareDMGWindowController *singleton = nil;
+    static dispatch_once_t pred;
+    dispatch_once(&pred, ^{
+        singleton = [[KMPurchaseCompareDMGWindowController alloc] init];
+    });
+    return singleton;
+}
+
 #pragma mark - FirstTrial WC
 + (KMPurchaseFirstTrialWindowController *)firstTrialWCCheck {
     //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况三 点到付费功能

+ 56 - 87
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -80,7 +80,7 @@
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "2196"
             endingLineNumber = "2196"
-            landmarkName = "savePDFSettingToDefaults(_:)"
+            landmarkName = "removeAllAnnotation(_:)"
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
@@ -349,8 +349,8 @@
             filePath = "PDF Master/Class/Home/ViewController/KMHomeViewController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "891"
-            endingLineNumber = "891"
+            startingLineNumber = "892"
+            endingLineNumber = "892"
             landmarkName = "checkRepeatTrialAlertController()"
             landmarkType = "7">
          </BreakpointContent>
@@ -365,8 +365,8 @@
             filePath = "PDF Master/Class/Home/ViewController/KMHomeViewController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "893"
-            endingLineNumber = "893"
+            startingLineNumber = "894"
+            endingLineNumber = "894"
             landmarkName = "checkRepeatTrialAlertController()"
             landmarkType = "7">
          </BreakpointContent>
@@ -381,8 +381,8 @@
             filePath = "PDF Master/Class/Home/ViewController/KMHomeViewController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "882"
-            endingLineNumber = "882"
+            startingLineNumber = "883"
+            endingLineNumber = "883"
             landmarkName = "checkRepeatTrialExpiredController()"
             landmarkType = "7">
          </BreakpointContent>
@@ -547,84 +547,6 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "DB926723-14B1-4358-AF9B-3BC932A40699"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "150"
-            endingLineNumber = "150"
-            landmarkName = "_themeChanged(_:)"
-            landmarkType = "7">
-            <Locations>
-               <Location
-                  uuid = "DB926723-14B1-4358-AF9B-3BC932A40699 - d41a0f6c4e43f42c"
-                  shouldBeEnabled = "Yes"
-                  ignoreCount = "0"
-                  continueAfterRunningActions = "No"
-                  symbolName = "PDF_Reaer_Pro.KMBrowserWindowController._themeChanged(Foundation.Notification) -&gt; ()"
-                  moduleName = "PDF Reaer Pro"
-                  usesParentBreakpointCondition = "Yes"
-                  urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
-                  startingColumnNumber = "9223372036854775807"
-                  endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "150"
-                  endingLineNumber = "150"
-                  offsetFromSymbolStart = "97">
-               </Location>
-               <Location
-                  uuid = "DB926723-14B1-4358-AF9B-3BC932A40699 - d41a0f6c4e43f42c"
-                  shouldBeEnabled = "Yes"
-                  ignoreCount = "0"
-                  continueAfterRunningActions = "No"
-                  symbolName = "PDF_Reaer_Pro.KMBrowserWindowController._themeChanged(Foundation.Notification) -&gt; ()"
-                  moduleName = "PDF Reaer Pro"
-                  usesParentBreakpointCondition = "Yes"
-                  urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
-                  startingColumnNumber = "9223372036854775807"
-                  endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "150"
-                  endingLineNumber = "150"
-                  offsetFromSymbolStart = "444">
-               </Location>
-               <Location
-                  uuid = "DB926723-14B1-4358-AF9B-3BC932A40699 - 804018a15d171c1b"
-                  shouldBeEnabled = "Yes"
-                  ignoreCount = "0"
-                  continueAfterRunningActions = "No"
-                  symbolName = "PDF_Reader_Pro.KMBrowserWindowController._themeChanged(Foundation.Notification) -&gt; ()"
-                  moduleName = "PDF Reader Pro"
-                  usesParentBreakpointCondition = "Yes"
-                  urlString = "file:///Users/kdanmobile/Documents/Git/PDF_Office/PDF%20Office/PDF%20Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
-                  startingColumnNumber = "9223372036854775807"
-                  endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "150"
-                  endingLineNumber = "150"
-                  offsetFromSymbolStart = "92">
-               </Location>
-               <Location
-                  uuid = "DB926723-14B1-4358-AF9B-3BC932A40699 - 804018a15d171c1b"
-                  shouldBeEnabled = "Yes"
-                  ignoreCount = "0"
-                  continueAfterRunningActions = "No"
-                  symbolName = "PDF_Reader_Pro.KMBrowserWindowController._themeChanged(Foundation.Notification) -&gt; ()"
-                  moduleName = "PDF Reader Pro"
-                  usesParentBreakpointCondition = "Yes"
-                  urlString = "file:///Users/kdanmobile/Documents/Git/PDF_Office/PDF%20Office/PDF%20Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
-                  startingColumnNumber = "9223372036854775807"
-                  endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "150"
-                  endingLineNumber = "150"
-                  offsetFromSymbolStart = "416">
-               </Location>
-            </Locations>
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent
@@ -793,10 +715,57 @@
             filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "2541"
-            endingLineNumber = "2541"
+            startingLineNumber = "2632"
+            endingLineNumber = "2632"
             landmarkName = "tableMenu(_:withTable:point:)"
             landmarkType = "7">
+            <Locations>
+               <Location
+                  uuid = "CA4FC0A7-ECA3-4141-AE22-84D66385B822 - e67b12dd034d39f"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "PDF_Reader_Pro.KMMainViewController.tableMenu(_: __C.NSMenu, withTable: PDF_Reader_Pro.KMTableAnnotation, point: __C.CGPoint) -&gt; __C.NSMenu"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/Documents/Git/PDF_Office/PDF%20Office/PDF%20Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "2631"
+                  endingLineNumber = "2631"
+                  offsetFromSymbolStart = "268">
+               </Location>
+               <Location
+                  uuid = "CA4FC0A7-ECA3-4141-AE22-84D66385B822 - e67b12dd034d39f"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "PDF_Reader_Pro.KMMainViewController.tableMenu(_: __C.NSMenu, withTable: PDF_Reader_Pro.KMTableAnnotation, point: __C.CGPoint) -&gt; __C.NSMenu"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/Documents/Git/PDF_Office/PDF%20Office/PDF%20Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "2631"
+                  endingLineNumber = "2631"
+                  offsetFromSymbolStart = "456">
+               </Location>
+               <Location
+                  uuid = "CA4FC0A7-ECA3-4141-AE22-84D66385B822 - e67b12dd034d3be"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "PDF_Reader_Pro.KMMainViewController.tableMenu(_: __C.NSMenu, withTable: PDF_Reader_Pro.KMTableAnnotation, point: __C.CGPoint) -&gt; __C.NSMenu"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/Documents/Git/PDF_Office/PDF%20Office/PDF%20Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "2632"
+                  endingLineNumber = "2632"
+                  offsetFromSymbolStart = "456">
+               </Location>
+            </Locations>
          </BreakpointContent>
       </BreakpointProxy>
       <BreakpointProxy