ソースを参照

【多页签】- 多页签优化

liujiajie 1 年間 前
コミット
748ad235f2

+ 4 - 4
PDF Office/PDF Master/Class/ChromiumTabs/src/Tab Strip/CTTabStripModel.m

@@ -290,10 +290,10 @@ const int kNoTab = NSNotFound;
     NSLog(@"切换document:%d",index);
 #endif
 	if ([self containsIndex:index]) {
-        if (![IAPProductsManager defaultManager].isAvailableAllFunction && [self count] > 1 && activeIndex_ != index){
-            [[NSNotificationCenter defaultCenter]postNotificationName:@"KMCTTableChangeShowAlertView" object:nil userInfo:nil];
-            return;
-        }
+//        if (![IAPProductsManager defaultManager].isAvailableAllFunction && [self count] > 1 && activeIndex_ != index){
+//            [[NSNotificationCenter defaultCenter]postNotificationName:@"KMCTTableChangeShowAlertView" object:nil userInfo:nil];
+//            return;
+//        }
 		[self changeSelectedContentsFrom:[self activeTabContents]
 								 toIndex:index
 							 userGesture:userGesture];

+ 25 - 0
PDF Office/PDF Master/Class/Common/Category/NSDocumentController+KMExtension.swift

@@ -29,4 +29,29 @@ extension NSDocumentController {
             completionHandler(document, isOpened, error)
         }
     }
+    
+    public func km_safe_limit_openDocument(withContentsOf url: URL, display displayDocument: Bool, needAlert: Bool = true, completionHandler: @escaping (NSDocument?, Bool, Error?) -> Void) {
+        if (!url.path.isPDFValid()) {
+            if (needAlert) {
+                let alert = NSAlert()
+                alert.alertStyle = .critical
+                alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
+                alert.runModal()
+            }
+            completionHandler(nil, false, nil)
+            return
+        }
+        if KMDataManager.default.isTabbingWin{
+            completionHandler(nil, false, nil)
+            return
+        }
+        self.openDocument(withContentsOf: url, display: displayDocument) { document, isOpened, error in
+            if let _error = error {
+                if (needAlert) {
+                    NSApp.presentError(_error)
+                }
+            }
+            completionHandler(document, isOpened, error)
+        }
+    }
 }

+ 1 - 1
PDF Office/PDF Master/Class/Document/KMMainDocument.swift

@@ -212,7 +212,7 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
                     }
                 }
             } else {
-                if currentWindowController?.browser.tabCount() ?? 0 > 1{
+                if currentWindowController?.browser.tabCount() ?? 0 > 1 && !IAPProductsManager.default().isAvailableAllFunction() {
                     let window = NSWindow.currentWindow()
                     if !KMDataManager.default.isTabbingWin{
                         KMDataManager.default.isTabbingWin = true

+ 24 - 1
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -346,6 +346,24 @@ extension KMHomeViewController {
         browser.windowController.showWindow(self)
     }
     
+    func showLimitWindowAlert() {
+        let window = NSWindow.currentWindow()
+        if !KMDataManager.default.isTabbingWin{
+            KMDataManager.default.isTabbingWin = true
+            let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
+            tabbingWin.selectCallBack = { continueOrNot in
+                window.km_quick_endSheet()
+                KMDataManager.default.isTabbingWin = false
+                if continueOrNot {
+                    self.reopenDocument(forPaths: [])
+                } else {
+                    
+                }
+            }
+            window.km_beginSheet(windowC: tabbingWin)
+        }
+    }
+    
     func openHistoryFilePath(url: URL) -> Void {
         if !url.path.isPDFValid() {
             let alert = NSAlert()
@@ -357,7 +375,7 @@ extension KMHomeViewController {
             }
             return
         }
-
+     
         if url.pathExtension.lowercased() == "pdf" {
             let pdfDoc = CPDFDocument.init(url: url)
             if pdfDoc != nil {
@@ -369,6 +387,11 @@ extension KMHomeViewController {
                     }
                 }
                 if !alreadyOpen {
+                    let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
+                    if controll?.browser.tabCount() ?? 0 > 1 && !IAPProductsManager.default().isAvailableAllFunction() {
+                        showLimitWindowAlert()
+                        return
+                    }
                     KMMainDocument().tryToUnlockDocument(pdfDoc!)
                     var selectDocument: KMMainDocument? = nil
                     if ((document?.isKind(of: KMMainDocument.self)) != nil) {

+ 21 - 6
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -643,17 +643,32 @@ extension KMHomeViewController: NSPopoverDelegate {
 
 extension KMHomeViewController {
     func openPDFAction(_ sender: KMBox) {
+        let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
+        if controll?.browser.tabCount() ?? 0 > 1 && !IAPProductsManager.default().isAvailableAllFunction() {
+            let window = NSWindow.currentWindow()
+            if !KMDataManager.default.isTabbingWin{
+                KMDataManager.default.isTabbingWin = true
+                let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
+                tabbingWin.selectCallBack = { continueOrNot in
+                    window.km_quick_endSheet()
+                    KMDataManager.default.isTabbingWin = false
+                    if continueOrNot {
+                        self.reopenDocument(forPaths: [])
+                    } else {
+                        
+                    }
+                }
+                window.km_beginSheet(windowC: tabbingWin)
+            }
+            return
+        }
         let openPanel = NSOpenPanel()
         openPanel.allowedFileTypes = ["pdf", "PDF"]
         openPanel.allowsMultipleSelection = false
         openPanel.beginSheetModal(for: self.view.window!) { (result) in
             if result == NSApplication.ModalResponse.OK {
-                NSDocumentController.shared.openDocument(withContentsOf: openPanel.url!, display: true) { (document, documentWasAlreadyOpen, error) in
-                    if let error = error {
-                        NSApp.presentError(error)
-                    } else {
-                        self.view.window?.windowController?.close()
-                    }
+                NSDocumentController.shared.km_safe_limit_openDocument(withContentsOf: openPanel.url!, display: true) { (document, documentWasAlreadyOpen, error) in
+                    
                 }
             }
         }