Browse Source

【Home】打开文档,支持多选打开文档,要显示:按键盘选择多个文件的提示(已修复)

tangchao 1 year ago
parent
commit
80323db4a1

+ 8 - 0
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -2912,6 +2912,9 @@
 		BBBF68802A3BF17F0058E14E /* KMFilePromiseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBF687F2A3BF17F0058E14E /* KMFilePromiseProvider.swift */; };
 		BBBF68812A3BF17F0058E14E /* KMFilePromiseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBF687F2A3BF17F0058E14E /* KMFilePromiseProvider.swift */; };
 		BBBF68822A3BF17F0058E14E /* KMFilePromiseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBF687F2A3BF17F0058E14E /* KMFilePromiseProvider.swift */; };
+		BBBF68842A3C3AF10058E14E /* NSDocumentController+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBF68832A3C3AF10058E14E /* NSDocumentController+KMExtension.swift */; };
+		BBBF68852A3C3AF10058E14E /* NSDocumentController+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBF68832A3C3AF10058E14E /* NSDocumentController+KMExtension.swift */; };
+		BBBF68862A3C3AF10058E14E /* NSDocumentController+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBF68832A3C3AF10058E14E /* NSDocumentController+KMExtension.swift */; };
 		BBC2BCC6295DA8F30036B983 /* KMCropPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC2BCC4295DA8F30036B983 /* KMCropPreviewController.swift */; };
 		BBC2BCC7295DA8F30036B983 /* KMCropPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC2BCC4295DA8F30036B983 /* KMCropPreviewController.swift */; };
 		BBC2BCC8295DA8F30036B983 /* KMCropPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC2BCC4295DA8F30036B983 /* KMCropPreviewController.swift */; };
@@ -4717,6 +4720,7 @@
 		BBB9B306299A5D6C004F3235 /* GTMAppAuthFetcherAuthorization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMAppAuthFetcherAuthorization.m; sourceTree = "<group>"; };
 		BBB9B335299A5F35004F3235 /* ObjectiveDropboxOfficial.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ObjectiveDropboxOfficial.framework; sourceTree = "<group>"; };
 		BBBF687F2A3BF17F0058E14E /* KMFilePromiseProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMFilePromiseProvider.swift; sourceTree = "<group>"; };
+		BBBF68832A3C3AF10058E14E /* NSDocumentController+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSDocumentController+KMExtension.swift"; sourceTree = "<group>"; };
 		BBC2BCC4295DA8F30036B983 /* KMCropPreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCropPreviewController.swift; sourceTree = "<group>"; };
 		BBC2BCC5295DA8F30036B983 /* KMCropPreviewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMCropPreviewController.xib; sourceTree = "<group>"; };
 		BBC347FC295448DE008D2CD1 /* KMWatermarkTemplateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMWatermarkTemplateModel.swift; sourceTree = "<group>"; };
@@ -7527,6 +7531,7 @@
 				BBB1A3A529F6B66400E54E47 /* NSPanel+KMExtension.swift */,
 				BBB7B48C2A0384E100B58A5A /* NSCollectionViewItem+KMExtension.swift */,
 				BBD54ED32A1CBD720012A230 /* NSView+KMExtension.swift */,
+				BBBF68832A3C3AF10058E14E /* NSDocumentController+KMExtension.swift */,
 			);
 			path = Category;
 			sourceTree = "<group>";
@@ -10783,6 +10788,7 @@
 				9FDD0F802952FC36000C4DAD /* KMDesignToken.swift in Sources */,
 				896DD46729893B9900ADE514 /* KMSplitView.m in Sources */,
 				BBFE6E582930724B00142C01 /* KMMergePageModel.swift in Sources */,
+				BBBF68842A3C3AF10058E14E /* NSDocumentController+KMExtension.swift in Sources */,
 				ADA9102A2A272CE2003352F0 /* KMEditPDFTextManager.swift in Sources */,
 				BB897229294B08720045787C /* KMWatermarkAdjectiveTopBarItemModel.swift in Sources */,
 				BB00301D298CB799002DD1A0 /* KMPreferenceManager.swift in Sources */,
@@ -11952,6 +11958,7 @@
 				9F8539D32943121100DF644E /* KMSegmentedBox.swift in Sources */,
 				AD9527C3295294EF0039D2BC /* KMPrintPaperModel.swift in Sources */,
 				ADBC2D4529A0D09A006280C8 /* ImageToPDFTools.swift in Sources */,
+				BBBF68852A3C3AF10058E14E /* NSDocumentController+KMExtension.swift in Sources */,
 				AD8810A129A8459000178CA1 /* KMComparativeTableViewController.swift in Sources */,
 				9F1FE4DC29406E4700E952CA /* NSURL+Utils.m in Sources */,
 				F35B484C29A4903300756255 /* NSPointerArray+PDFListView.m in Sources */,
@@ -12514,6 +12521,7 @@
 				BB86C21B28F561C7005AD968 /* NSColor_SKExtensions.m in Sources */,
 				BBA19F4129ADE40A001A285A /* KMCellEmptyView.m in Sources */,
 				ADC07626298CB805006C752F /* KMBatchSettingItemViewModel.swift in Sources */,
+				BBBF68862A3C3AF10058E14E /* NSDocumentController+KMExtension.swift in Sources */,
 				BBEC00AA295BDECF00A26C98 /* KMHeaderFooterContentInfoView.swift in Sources */,
 				F37322FE292DF9410013862C /* CPDFWidgetAnnotation+PDFListView.m in Sources */,
 				ADCB9970292C65EE00B51A03 /* KMOCROperation.m in Sources */,

+ 4 - 20
PDF Office/PDF Master.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -174,8 +174,8 @@
             filePath = "PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1250"
-            endingLineNumber = "1250"
+            startingLineNumber = "1264"
+            endingLineNumber = "1264"
             landmarkName = "menuItemAction_showNextTagPage(_:)"
             landmarkType = "7">
          </BreakpointContent>
@@ -190,8 +190,8 @@
             filePath = "PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1237"
-            endingLineNumber = "1237"
+            startingLineNumber = "1251"
+            endingLineNumber = "1251"
             landmarkName = "menuItemAction_showForwardTagPage(_:)"
             landmarkType = "7">
          </BreakpointContent>
@@ -260,21 +260,5 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "8BD43F6C-FA9C-4FDB-9F66-5F1FFE283352"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "548"
-            endingLineNumber = "548"
-            landmarkName = "openImageFile(url:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 14 - 0
PDF Office/PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift

@@ -350,6 +350,20 @@ import Cocoa
         
         self.rightStripView.autoresizingMask = [.minXMargin, .minYMargin]
     }
+    
+    override func openDocument(_ sender: Any!) {
+        guard let _window = self.window else {
+            return
+        }
+        
+        NSOpenPanel.km_open_pdf_multi_success(_window, panel: nil) { urls in
+            for url in urls {
+                NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
+                    
+                }
+            }
+        }
+    }
 }
 
 // MARK: - KMToolbarRightViewDelegate

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

@@ -0,0 +1,32 @@
+//
+//  NSDocumentController+KMExtension.swift
+//  PDF Master
+//
+//  Created by tangchao on 2023/6/16.
+//
+
+import Foundation
+
+extension NSDocumentController {
+    public func km_safe_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
+        }
+        
+        self.openDocument(withContentsOf: url, display: displayDocument) { document, isOpened, error in
+            if let _error = error {
+                if (needAlert) {
+                    NSApp.presentError(_error)
+                }
+            }
+            completionHandler(document, isOpened, error)
+        }
+    }
+}

+ 13 - 18
PDF Office/PDF Master/Class/Home/ViewController/KMAIOpenPDFFilesVC.swift

@@ -343,24 +343,19 @@ class KMAIOpenPDFFilesVC: NSViewController {
     }
     
     func openPDFButtonAction() {
-        let openPanel = NSOpenPanel()
-        openPanel.allowedFileTypes = ["pdf", "PDF"]
-        openPanel.allowsMultipleSelection = true
-        openPanel.beginSheetModal(for: self.view.window!) { result in
-            if result == .OK {
-                for url in openPanel.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 {
-                                
-                            }
+        NSOpenPanel.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 {
+                            
                         }
                     }
                 }

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

@@ -180,18 +180,20 @@ extension KMHomeViewController {
     }
     
     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
+        NSOpenPanel.km_open_multi(window!) { panel in
+            if let data = KMConvertPDFManagerOC.supportFileType() as? [String], !data.isEmpty {
+                panel.allowedFileTypes = KMTools.pdfExtensions + data
+            } else {
+                panel.allowedFileTypes = KMTools.pdfExtensions + KMTools.imageExtensions
+            }
+        } completion: { [weak self] result , urls in
             if result == .OK {
                 var imageUrl: [URL] = []
-                for url in openPanel.urls {
+                for url in urls! {
                     let type = url.pathExtension.lowercased()
                     if (type == "pdf" || type == "PDF") {
                         if !url.path.isPDFValid() {
@@ -226,7 +228,7 @@ extension KMHomeViewController {
                                 (type == "pict") ||
                                 (type == "sgi") ||
                                 (type == "heic") {
-                        openImageFile(url: url)
+                        self?.openImageFile(url: url)
                     } else if (type == "doc") ||
                                 (type == "docx") ||
                                 (type == "xls") ||
@@ -234,7 +236,7 @@ extension KMHomeViewController {
                                 (type == "ppt") ||
                                 (type == "pptx") ||
                                 (type == "pptx") {
-                        self.openOfficeFile(url: url)
+                        self?.openOfficeFile(url: url)
                     }
                 }
             }