Browse Source

【综合】首页打开文件新增提示多选文案

tangchao 1 year ago
parent
commit
90865e4a00

+ 42 - 51
PDF Office/PDF Master/Class/Home/ViewController/KMAIOpenPDFFilesVC.swift

@@ -401,62 +401,53 @@ class KMAIOpenPDFFilesVC: NSViewController {
     }
     
     func openSupportPDFButtonAction() {
-        let openPanel = NSOpenPanel()
-        openPanel.allowedFileTypes = ["pdf", "PDF", "jpg", "cur", "bmp", "jpeg", "gif", "png", "tiff", "tif", "ico", "icns", "tga", "psd", "eps", "hdr", "jp2", "jpc", "pict", "sgi", "heic", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "pptx"]
-        openPanel.allowsMultipleSelection = true
-        
         var window = self.view.window
         if (window == nil) {
             window = NSApp.mainWindow
         }
-        openPanel.beginSheetModal(for: window!) { [self] result in
-            if result == .OK {
-                var imageUrl: [URL] = []
-                for url in openPanel.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
-                                }
-                            }
-                        }
-                    } else if (type == "jpg") ||
-                                (type == "cur") ||
-                                (type == "bmp") ||
-                                (type == "jpeg") ||
-                                (type == "gif") ||
-                                (type == "png") ||
-                                (type == "tiff") ||
-                                (type == "tif") ||
-                                (type == "ico") ||
-                                (type == "icns") ||
-                                (type == "tga") ||
-                                (type == "psd") ||
-                                (type == "eps") ||
-                                (type == "hdr") ||
-                                (type == "jp2") ||
-                                (type == "jpc") ||
-                                (type == "pict") ||
-                                (type == "sgi") ||
-                                (type == "heic") {
-                        openImageFile(url: url)
-                    } else if (type == "doc") ||
-                                (type == "docx") ||
-                                (type == "xls") ||
-                                (type == "xlsx") ||
-                                (type == "ppt") ||
-                                (type == "pptx") ||
-                                (type == "pptx") {
-                        self.openOfficeFile(url: url)
+        NSPanel.km_open_multi_success(window!) { panel in
+            var array: [String] = []
+            for fileType in KMConvertPDFManagerOC.supportFileType() {
+                if let string = fileType as? String {
+                    array.append(string)
+                }
+            }
+            panel.allowedFileTypes = KMTools.pdfExtensions + array
+        } completion: { urls in
+            for url in urls {
+                let type = url.pathExtension.lowercased()
+                if (type == "pdf" || type == "PDF") {
+                    NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
+                        
                     }
+                } else if (type == "jpg") ||
+                            (type == "cur") ||
+                            (type == "bmp") ||
+                            (type == "jpeg") ||
+                            (type == "gif") ||
+                            (type == "png") ||
+                            (type == "tiff") ||
+                            (type == "tif") ||
+                            (type == "ico") ||
+                            (type == "icns") ||
+                            (type == "tga") ||
+                            (type == "psd") ||
+                            (type == "eps") ||
+                            (type == "hdr") ||
+                            (type == "jp2") ||
+                            (type == "jpc") ||
+                            (type == "pict") ||
+                            (type == "sgi") ||
+                            (type == "heic") {
+                    self.openImageFile(url: url)
+                } else if (type == "doc") ||
+                            (type == "docx") ||
+                            (type == "xls") ||
+                            (type == "xlsx") ||
+                            (type == "ppt") ||
+                            (type == "pptx") ||
+                            (type == "pptx") {
+                    self.openOfficeFile(url: url)
                 }
             }
         }