Sfoglia il codice sorgente

【综合】打开文档方式优化

tangchao 1 anno fa
parent
commit
12d17bdfab

File diff suppressed because it is too large
+ 2 - 18
PDF Office/PDF Master/AppDelegate.swift


+ 5 - 26
PDF Office/PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift

@@ -281,21 +281,10 @@ import Cocoa
                             selectDocument?.browser.window.orderFront(nil)
                         }
                     } else {
-                        if !(activeTab?.fileURL)!.path.isPDFValid() {
-                            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()
-                            return
-                        }
-
-                        NSDocumentController.shared.openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, documentWasAlreadyOpen, error in
-                            if error != nil {
-                                NSApp.presentError(error!)
-                                return
+                        NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, _, error in
+                            if (error == nil) {
+                                (document as! KMMainDocument).mainViewController?.password = password
                             }
-
-                            (document as! KMMainDocument).mainViewController?.password = password
                         }
                     }
                 }
@@ -313,18 +302,8 @@ import Cocoa
                         selectDocument?.browser.window.orderFront(nil)
                     }
                 } else {
-                    if !(activeTab?.fileURL)!.path.isPDFValid() {
-                        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()
-                        return
-                    }
-                    NSDocumentController.shared.openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, documentWasAlreadyOpen, error in
-                        if error != nil {
-                            NSApp.presentError(error!)
-                            return
-                        }
+                    NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { _, _, _ in
+                        
                     }
                 }
             }

+ 2 - 11
PDF Office/PDF Master/Class/Common/Tools/KMTools.swift

@@ -282,17 +282,8 @@ extension KMTools {
         }
         try?FileManager.default.copyItem(atPath: path!, toPath: toPath)
         
-        if !toPath.isPDFValid() {
-            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()
-            return
-        }
-        NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: toPath), display: true) { document, result, error in
-            if (error != nil) {
-                NSApp.presentError(error!)
-            }
+        NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: toPath), display: true) { _, _, _ in
+            
         }
     }
     

+ 12 - 73
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -165,19 +165,8 @@ extension KMHomeViewController {
     func openPDFButtonAction() {
         NSPanel.km_open_pdf_multi_success(self.view.window!, panel: nil) { urls in
             for url in urls {
-                if !url.path.isPDFValid() {
-                    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()
-                } else {
-                    NSDocumentController.shared.openDocument(withContentsOf: url, display: true) { document, documentWasAlreadyOpen, error in
-                        if error != nil {
-                            NSApp.presentError(error!)
-                        } else {
-                            
-                        }
-                    }
+                NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
+                    
                 }
             }
         }
@@ -200,18 +189,8 @@ extension KMHomeViewController {
                 for url in urls! {
                     let type = url.pathExtension.lowercased()
                     if (type == "pdf" || type == "PDF") {
-                        if !url.path.isPDFValid() {
-                            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()
-                        } else {
-                            NSDocumentController.shared.openDocument(withContentsOf: url, display: true) { document, documentWasAlreadyOpen, error in
-                                if error != nil {
-                                    NSApp.presentError(error!)
-                                    return
-                                }
-                            }
+                        NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
+                            
                         }
                     } else if (type == "jpg") ||
                                 (type == "cur") ||
@@ -394,18 +373,8 @@ extension KMHomeViewController {
                             selectDocument?.browser.window.orderFront(nil)
                         }
                     } else {
-                        if !url.path.isPDFValid() {
-                            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()
-                        } else {
-                            NSDocumentController.shared.openDocument(withContentsOf: url, display: true) { document, documentWasAlreadyOpen, error in
-                                if error != nil {
-                                    NSApp.presentError(error!)
-                                    return
-                                }
-                            }
+                        NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
+                            
                         }
                     }
                 } else {
@@ -424,18 +393,8 @@ extension KMHomeViewController {
                             }
                         }
                     } else {
-                        if !url.path.isPDFValid() {
-                            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()
-                        } else {
-                            NSDocumentController.shared.openDocument(withContentsOf: url, display: true) { document, documentWasAlreadyOpen, error in
-                                if error != nil {
-                                    NSApp.presentError(error!)
-                                    return
-                                }
-                            }
+                        NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
+                            
                         }
                     }
                 }
@@ -571,18 +530,8 @@ extension KMHomeViewController {
         } else {
         }
         if success {
-            if !path.isPDFValid() {
-                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()
-                return
-            }
-            NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: path), display: true) { document, documentWasAlreadyOpen, error in
-                if error != nil {
-                    NSApp.presentError(error!)
-                    return
-                }
+            NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: path), display: true) { _, _, _ in
+                
             }
         }
     }
@@ -623,18 +572,8 @@ extension KMHomeViewController {
                 return
             }
             
-            if !savePath!.isPDFValid() {
-                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()
-                return
-            }
-            NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath!), display: true) { document, documentWasAlreadyOpen, error in
-                if error != nil {
-                    NSApp.presentError(error!)
-                    return
-                }
+            NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: savePath!), display: true) { _, _, _ in
+                
             }
         }
     }

+ 0 - 6
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController_dmg.swift

@@ -12,12 +12,6 @@ import Cocoa
  登录策略 与 free 不同
  */
 class KMPDFEditViewController_dmg: KMPDFEditViewController {
-
-    override func viewDidLoad() {
-        super.viewDidLoad()
-        // Do view setup here.
-    }
-    
     // MARK: menu 菜单事件
     
     @objc override func item_insertCustomPage(sender: NSMenuItem?) {

+ 1 - 9
PDF Office/PDF Master/Class/PDFTools/PageEdit/Tools/KMPageEditTools.swift

@@ -61,15 +61,7 @@ class KMPageEditTools: NSObject {
                                 let url = URL(fileURLWithPath: saveFilePath)
                                 NSWorkspace.shared.activateFileViewerSelecting([url])
                             } else {
-                                if !saveFilePath.isPDFValid() {
-                                    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()
-                                    return
-                                }
-
-                                NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: saveFilePath), display: true) { document, result, error in
+                                NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: saveFilePath), display: true) { _, _, _ in
                                     
                                 }
                             }