|
@@ -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
|
|
|
// 留意:
|
|
|
// -会直接弹密码弹窗,不会判断文档是否加密
|