浏览代码

【页面编辑】拖拽插入补充图片和office文档格式

tangchao 1 年之前
父节点
当前提交
a106e16143

+ 0 - 48
PDF Office/PDF Master.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -324,54 +324,6 @@
             </Locations>
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "22568723-DB3D-497E-8BC0-B72CE9C65270"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "844"
-            endingLineNumber = "844"
-            landmarkName = "thumbnailView(thumbanView:didDragAddFiles:indexpath:)"
-            landmarkType = "7">
-            <Locations>
-               <Location
-                  uuid = "22568723-DB3D-497E-8BC0-B72CE9C65270 - bcad3bddbdf19529"
-                  shouldBeEnabled = "Yes"
-                  ignoreCount = "0"
-                  continueAfterRunningActions = "No"
-                  symbolName = "PDF_Master.KMPDFEditViewController.thumbnailView(thumbanView: PDF_Master.KMThumbnailView, didDragAddFiles: Swift.Array&lt;Foundation.URL&gt;, indexpath: Foundation.IndexPath) -&gt; ()"
-                  moduleName = "PDF Master"
-                  usesParentBreakpointCondition = "Yes"
-                  urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift"
-                  startingColumnNumber = "9223372036854775807"
-                  endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "844"
-                  endingLineNumber = "844"
-                  offsetFromSymbolStart = "179">
-               </Location>
-               <Location
-                  uuid = "22568723-DB3D-497E-8BC0-B72CE9C65270 - e7db40416cd73693"
-                  shouldBeEnabled = "Yes"
-                  ignoreCount = "0"
-                  continueAfterRunningActions = "No"
-                  symbolName = "closure #1 (Swift.Array&lt;__C.CPDFDocument&gt;) -&gt; () in PDF_Master.KMPDFEditViewController.thumbnailView(thumbanView: PDF_Master.KMThumbnailView, didDragAddFiles: Swift.Array&lt;Foundation.URL&gt;, indexpath: Foundation.IndexPath) -&gt; ()"
-                  moduleName = "PDF Master"
-                  usesParentBreakpointCondition = "Yes"
-                  urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift"
-                  startingColumnNumber = "9223372036854775807"
-                  endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "844"
-                  endingLineNumber = "844"
-                  offsetFromSymbolStart = "353">
-               </Location>
-            </Locations>
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent

+ 85 - 0
PDF Office/PDF Master/Class/Common/Base/KMBaseViewController.swift

@@ -95,6 +95,20 @@ class KMBaseViewController: NSViewController {
         }
     }
     
+    func km_open_file_multi(type: KMPasswordInputWindowType = .open, progressBlock: ((_ index: Int, _ params: Any...)->Void)? = nil, completionBlock:@escaping ([CPDFDocument])->Void) {
+        NSPanel.km_open_multi_success(self.view.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
+            self.km_add_file_multi(fileUrls: urls, type: type, progressBlock: progressBlock, completionBlock: completionBlock)
+        }
+    }
+    
     func km_add_pdf_multi(fileUrlStrings: [String] ,type: KMPasswordInputWindowType = .open, progressBlock: ((_ index: Int, _ params: Any...)->Void)? = nil, completionBlock:@escaping ([CPDFDocument])->Void) {
         var urls: [URL] = []
         for string in fileUrlStrings {
@@ -163,6 +177,77 @@ class KMBaseViewController: NSViewController {
         }
     }
     
+    func km_add_file_multi(fileUrls: [URL] ,type: KMPasswordInputWindowType = .open, progressBlock: ((_ index: Int, _ params: Any...)->Void)? = nil, completionBlock:@escaping ([CPDFDocument])->Void) {
+            var pdfUrls: [URL] = []
+            var imageUrls: [URL] = []
+            var officeUrls: [URL] = []
+            for url in fileUrls {
+                let type = url.pathExtension.lowercased()
+                if (KMTools.isPDFType(type)) {
+                    pdfUrls.append(url)
+                }
+                if (KMTools.isImageType(type)) {
+                    imageUrls.append(url)
+                }
+                if (KMTools.isOfficeType(type)) {
+                    officeUrls.append(url)
+                }
+            }
+            
+            if (officeUrls.count == 0) {
+                self.km_add_pdf_multi(fileUrls: pdfUrls, type: type, progressBlock: progressBlock) { documents in
+                    var index = documents.count
+                    var _documents: [CPDFDocument] = []
+                    for imageUrl in imageUrls {
+                        index += 1
+                        let document = CPDFDocument()
+                        let image = NSImage(contentsOfFile: imageUrl.path)
+                        document?.insertPage(image!.size, withImage: imageUrl.path, at: 0)
+                        _documents.append(document!)
+                        
+                        if let _callback = progressBlock { // 回调进度
+                            _callback(index, document as Any, imageUrl)
+                        }
+                    }
+                    
+                    completionBlock(documents + _documents)
+                }
+                return
+            }
+            
+            self.km_add_office_multi(fileUrls: officeUrls) { [unowned self] fileUrlStrings in
+                var officeDocuments: [CPDFDocument] = []
+                var index = 0
+                for fileUrlString in fileUrlStrings {
+                    index += 1
+                    let document = CPDFDocument(url: URL(fileURLWithPath: fileUrlString))
+                    officeDocuments.append(document!)
+                    
+                    if let _callback = progressBlock { // 回调进度
+                        _callback(index, document as Any, URL(fileURLWithPath: fileUrlString))
+                    }
+                }
+                
+                self.km_add_pdf_multi(fileUrls: pdfUrls) { documents in
+                    var index = documents.count + officeDocuments.count
+                    var _documents: [CPDFDocument] = []
+                    for imageUrl in imageUrls {
+                        index += 1
+                        let document = CPDFDocument()
+                        let image = NSImage(contentsOfFile: imageUrl.path)
+                        document?.insertPage(image!.size, withImage: imageUrl.path, at: 0)
+                        _documents.append(document!)
+                        
+                        if let _callback = progressBlock { // 回调进度
+                            _callback(index, document as Any, imageUrl)
+                        }
+                    }
+
+                    completionBlock(officeDocuments + documents + _documents)
+                }
+            }
+    }
+    
     // MARK: - Open Password Window
     // 留意:
     // -会直接弹密码弹窗,不会判断文档是否加密

+ 1 - 5
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -43,8 +43,6 @@ class KMPDFEditViewController: KMPDFThumbViewBaseController {
     var windowController: NSWindowController?
     
     var pageIsUpdate: Bool = true
-    /// 临时存储 document
-    private var documentCaches: [CPDFDocument] = []
     var selectedPages: [Int] = []
     
     private let defaultItemSize = NSMakeSize(218 + 12 * 2, 292 + 24)
@@ -841,13 +839,11 @@ extension KMPDFEditViewController {
 
 extension KMPDFEditViewController: KMThumbnailViewDelegate {
     func thumbnailView(thumbanView: KMThumbnailView, didDragAddFiles files: [URL], indexpath: IndexPath) {
-        self.km_add_pdf_multi(fileUrls: files) { [unowned self] documents in
+        self.km_add_file_multi(fileUrls: files) { [unowned self] documents in
             var insertIndex: Int = indexpath.item
             var pages: Array<CPDFPage> = []
-            self.documentCaches.removeAll()
             var indexs = IndexSet()
             for document in documents {
-                self.documentCaches.append(document)
                 for i in 0 ..< document.pageCount {
                     let page = document.page(at: i)
                     pages.append(page!)

+ 2 - 63
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/Base/KMPDFThumbViewBaseController.swift

@@ -307,70 +307,9 @@ class KMPDFThumbViewBaseController: KMBaseViewController {
                 return
             }
             
-            NSPanel.km_open_multi_success(self.view.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
-                var pdfUrls: [URL] = []
-                var imageUrls: [URL] = []
-                var officeUrls: [URL] = []
-                for url in urls {
-                    let type = url.pathExtension.lowercased()
-                    if (KMTools.isPDFType(type)) {
-                        pdfUrls.append(url)
-                    }
-                    if (KMTools.isImageType(type)) {
-                        imageUrls.append(url)
-                    }
-                    if (KMTools.isOfficeType(type)) {
-                        officeUrls.append(url)
-                    }
-                }
-                
-                if (officeUrls.count == 0) {
-                    self.km_add_pdf_multi(fileUrls: pdfUrls) { [unowned self] documents in
-                        var _documents: [CPDFDocument] = []
-                        for imageUrl in imageUrls {
-                            let document = CPDFDocument()
-                            let image = NSImage(contentsOfFile: imageUrl.path)
-                            document?.insertPage(image!.size, withImage: imageUrl.path, at: 0)
-                            _documents.append(document!)
-                        }
-
-                        self.replacePages(of: self.thumbnailView.selectionIndexPaths, with: documents + _documents)
-                    }
-                    return
-                }
-                
-                self.km_add_office_multi(fileUrls: officeUrls) { [unowned self] fileUrlStrings in
-                    var officeDocuments: [CPDFDocument] = []
-                    for fileUrlString in fileUrlStrings {
-                        let document = CPDFDocument(url: URL(fileURLWithPath: fileUrlString))
-                        officeDocuments.append(document!)
-                    }
-                    
-                    self.km_add_pdf_multi(fileUrls: pdfUrls) { [unowned self] documents in
-                        var _documents: [CPDFDocument] = []
-                        for imageUrl in imageUrls {
-                            let document = CPDFDocument()
-                            let image = NSImage(contentsOfFile: imageUrl.path)
-                            document?.insertPage(image!.size, withImage: imageUrl.path, at: 0)
-                            _documents.append(document!)
-                        }
-
-                        self.replacePages(of: self.thumbnailView.selectionIndexPaths, with: documents + _documents + officeDocuments)
-                    }
-                }
+            self.km_open_file_multi { [unowned self] documents in
+                self.replacePages(of: self.thumbnailView.selectionIndexPaths, with: documents)
             }
-
-//            self.km_open_pdf_multi { [unowned self] documents in
-//                self.replacePages(of: self.thumbnailView.selectionIndexPaths, with: documents)
-//            }
         }
     }