Forráskód Böngészése

【设置】有选择“文档打开于新窗口”,实际打开文档不是以新窗口的形式

liujiajie 6 hónapja
szülő
commit
eeff9815d4

+ 41 - 28
PDF Office/PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift

@@ -538,21 +538,27 @@ import Cocoa
             KMPrint("openDocument error: window is nil.", beep: true)
             return
         }
-        if let cnt = self.browser?.tabCount(), cnt > 1 && !IAPProductsManager.default().isAvailableAllFunction() {
-            if !KMDataManager.default.isTabbingWin{
-                KMDataManager.default.isTabbingWin = true
-                let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
-                tabbingWin.selectCallBack = { [weak self] continueOrNot in
-                    KMDataManager.default.isTabbingWin = false
-                    if continueOrNot {
-                        self?.reopenDocument(forPaths: nil)
-                    } else {
-                        
+        if let cnt = self.browser?.tabCount(), cnt > 1{
+            if !IAPProductsManager.default().isAvailableAllFunction() {
+                if !KMDataManager.default.isTabbingWin{
+                    KMDataManager.default.isTabbingWin = true
+                    let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
+                    tabbingWin.selectCallBack = { [weak self] continueOrNot in
+                        KMDataManager.default.isTabbingWin = false
+                        if continueOrNot {
+                            self?.reopenDocument(forPaths: nil)
+                        } else {
+                            
+                        }
                     }
+                    self.km_beginSheet(windowC: tabbingWin)
                 }
-                self.km_beginSheet(windowC: tabbingWin)
+                return
+            }
+            if KMPreference.shared.openDocumentType == .newWindow {
+                self.reopenDocument(forPaths: nil)
+                return
             }
-            return
         }
 
         NSOpenPanel.km_open_multi_success(_window) { panel in
@@ -1509,26 +1515,33 @@ extension KMBrowserWindowController: KMSystemFileMenuProtocol {
     }
     func checkOpenNewDocument(path: String) -> Bool {
         let tabCount = self.km_browser?.tabCount() ?? 0
-        if !IAPProductsManager.default().isAvailableAllFunction() && tabCount > 1 {
-            let preferenceNoteShow = UserDefaults.standard.bool(forKey: KMTabbingHintShowFlag)
-            if preferenceNoteShow {
-                menuItemAction_newTagPageToNewWindow("")
-            } else {
-                if !KMDataManager.default.isTabbingWin{
-                    KMDataManager.default.isTabbingWin = true
-                    let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
-                    tabbingWin.selectCallBack = {[weak self] continueOrNot in
-                        KMDataManager.default.isTabbingWin = false
-                        if continueOrNot {
-                            self?.reopenDocumentForNewWindow(savePath: path)
-                        } else {
-                            
+        if tabCount > 1{
+            if !IAPProductsManager.default().isAvailableAllFunction() {
+                let preferenceNoteShow = UserDefaults.standard.bool(forKey: KMTabbingHintShowFlag)
+                if preferenceNoteShow {
+                    menuItemAction_newTagPageToNewWindow("")
+                } else {
+                    if !KMDataManager.default.isTabbingWin{
+                        KMDataManager.default.isTabbingWin = true
+                        let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
+                        tabbingWin.selectCallBack = {[weak self] continueOrNot in
+                            KMDataManager.default.isTabbingWin = false
+                            if continueOrNot {
+                                self?.reopenDocumentForNewWindow(savePath: path)
+                            } else {
+                                
+                            }
                         }
+                        self.km_beginSheet(windowC: tabbingWin)
                     }
-                    self.km_beginSheet(windowC: tabbingWin)
+                }
+                return false
+            }else {
+                if KMPreference.shared.openDocumentType == .newWindow {
+                    self.reopenDocumentForNewWindow(savePath: path)
+                    return false
                 }
             }
-            return false
         }
         return true
     }

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

@@ -230,15 +230,15 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
                     }
                 }
             } else {
-                if currentWindowController?.browser.tabCount() ?? 0 > 1 && !IAPProductsManager.default().isAvailableAllFunction() {
-                    // 开启新窗口
-                    let browser = KMBrowser.init() as KMBrowser
-                    browser.windowController = KMBrowserWindowController.init(browser: browser)
-                    browser.addHomeTabContents()
-                    browser.windowController.showWindow(self)
-                    browser.add(self, at: Int32()-1, inForeground: true)
-                    self.addWindowController(browser.windowController)
-                    self.mainViewController?.browserWindowController = browser.windowController as? KMBrowserWindowController
+                if currentWindowController?.browser.tabCount() ?? 0 > 1 && (!IAPProductsManager.default().isAvailableAllFunction() || KMPreference.shared.openDocumentType == .newWindow){
+                        // 开启新窗口
+                        let browser = KMBrowser.init() as KMBrowser
+                        browser.windowController = KMBrowserWindowController.init(browser: browser)
+                        browser.addHomeTabContents()
+                        browser.windowController.showWindow(self)
+                        browser.add(self, at: Int32()-1, inForeground: true)
+                        self.addWindowController(browser.windowController)
+                        self.mainViewController?.browserWindowController = browser.windowController as? KMBrowserWindowController
                 }else { // 正常拼接到后面
                     self.addWindowController(currentWindowController!)
                     self.mainViewController?.browserWindowController = currentWindowController

+ 13 - 3
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -379,6 +379,10 @@ extension KMHomeViewController {
             browser.addHomeTabContents()
             browser.windowController.showWindow(self)
         }else {
+            let browser = KMBrowser.init() as KMBrowser
+            browser.windowController = KMBrowserWindowController.init(browser: browser)
+            browser.addHomeTabContents()
+            browser.windowController.showWindow(self)
             NSDocumentController.shared.km_safe_openDocument(withContentsOf: path!, display: true) { doc, open, err in
                 
             }
@@ -425,9 +429,15 @@ extension KMHomeViewController {
                 }
                 if !alreadyOpen {
                     let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
-                    if controll?.browser?.tabCount() ?? 0 > 1 && !IAPProductsManager.default().isAvailableAllFunction() {
-                        showLimitWindowAlert(url: url)
-                        return
+                    if controll?.browser?.tabCount() ?? 0 > 1{
+                        if !IAPProductsManager.default().isAvailableAllFunction() {
+                            showLimitWindowAlert(url: url)
+                            return
+                        }else {
+                            if KMPreference.shared.openDocumentType == .newWindow {
+                                self.reopenDocument(forPaths: url)
+                            }
+                        }
                     }
                 }
                 

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

@@ -686,10 +686,15 @@ extension KMHomeViewController {
         let openPanel = NSOpenPanel()
         openPanel.allowedFileTypes = ["pdf", "PDF"]
         openPanel.allowsMultipleSelection = false
-        openPanel.beginSheetModal(for: self.view.window!) { (result) in
+        openPanel.beginSheetModal(for: self.view.window!) {   (result) in
             if result == NSApplication.ModalResponse.OK {
-                NSDocumentController.shared.km_safe_limit_openDocument(withContentsOf: openPanel.url!, display: true) { (document, documentWasAlreadyOpen, error) in
-                    
+                let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
+                if controll?.browser?.tabCount() ?? 0 > 1 && KMPreference.shared.openDocumentType == .newWindow{
+                    self.reopenDocument(forPaths: openPanel.url!)
+                }else {
+                    NSDocumentController.shared.km_safe_limit_openDocument(withContentsOf: openPanel.url!, display: true) { (document, documentWasAlreadyOpen, error) in
+                        
+                    }
                 }
             }
         }
@@ -764,16 +769,21 @@ extension KMHomeViewController {
         let pdfDocument = CPDFDocument()
         pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
         pdfDocument?.write(to: URL(fileURLWithPath: savePath))
-        NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
-            if error != nil {
-                NSApp.presentError(error!)
-            } else {
-                if document is KMMainDocument {
-                    let newDocument = document
-                    (newDocument as! KMMainDocument).isNewCreated = true
+        let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
+        if controll?.browser?.tabCount() ?? 0 > 1 && KMPreference.shared.openDocumentType == .newWindow{
+            self.reopenDocument(forPaths: URL(fileURLWithPath: savePath))
+        }else {
+            NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
+                if error != nil {
+                    NSApp.presentError(error!)
+                } else {
+                    if document is KMMainDocument {
+                        let newDocument = document
+                        (newDocument as! KMMainDocument).isNewCreated = true
+                    }
                 }
+    //            self.homeContentView?.reloadData()
             }
-//            self.homeContentView?.reloadData()
         }
     }