|
@@ -1760,15 +1760,16 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
var fileURLArray: [String] = []
|
|
|
if indexSet.count > 1 {
|
|
|
var docmentName = ""
|
|
|
- var tFileName = String(format: "%@", self.fileNameWithSelectedPages(indexSet))
|
|
|
- var pdf = CPDFDocument()
|
|
|
+ let tFileName = String(format: "%@", self.fileNameWithSelectedPages(indexSet))
|
|
|
+ let pdf = CPDFDocument()
|
|
|
for idx in indexSet {
|
|
|
if idx != NSNotFound && self.listView.document.isLocked == false {
|
|
|
- let copyPage = self.listView.document.page(at: UInt(idx)).copy() as? CPDFPage
|
|
|
+// let copyPage = self.listView.document.page(at: UInt(idx)).copy() as? CPDFPage
|
|
|
+ let copyPage = self.listView.document.page(at: UInt(idx))
|
|
|
pdf?.insertPageObject(copyPage, at: pdf?.pageCount ?? 0)
|
|
|
}
|
|
|
}
|
|
|
- var fileURL = dropDestination.appendingPathComponent(tFileName).appendingPathExtension("pdf").uniqueFileURL()
|
|
|
+ let fileURL = dropDestination.appendingPathComponent(tFileName).appendingPathExtension("pdf").uniqueFileURL()
|
|
|
docmentName = fileURL.path
|
|
|
let success = pdf?.write(toFile: docmentName) ?? false
|
|
|
if(success) {
|
|
@@ -1777,21 +1778,23 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
} else {
|
|
|
if let page = self.listView.document.page(at: UInt(indexSet.first ?? 0)) {
|
|
|
var fileURL = dropDestination.appendingPathComponent(self.draggedFileName(for: page))
|
|
|
- var pathExt = ""
|
|
|
- var fileData: Data?
|
|
|
-
|
|
|
if let data = self.listView?.document?.allowsPrinting, data {
|
|
|
- pathExt = "pdf"
|
|
|
- // data = [page dataRepresentation];
|
|
|
+ fileURL = fileURL.appendingPathExtension("pdf").uniqueFileURL()
|
|
|
+ let pdf = CPDFDocument()
|
|
|
+// let copyPage = page.copy() as? CPDFPage
|
|
|
+ let copyPage = page
|
|
|
+ pdf?.insertPageObject(copyPage, at: pdf?.pageCount ?? 0)
|
|
|
+ let success = pdf?.write(toFile: fileURL.path) ?? false
|
|
|
+ if success {
|
|
|
+ fileURLArray.append(fileURL.lastPathComponent)
|
|
|
+ }
|
|
|
} else {
|
|
|
- pathExt = "tiff"
|
|
|
- fileData = page.PDFListViewTIFFData(for: page.bounds(for: self.listView?.displayBox ?? .cropBox))
|
|
|
- }
|
|
|
-
|
|
|
- fileURL = fileURL.appendingPathExtension(pathExt).uniqueFileURL()
|
|
|
- let success = (try?fileData?.write(to: fileURL)) != nil
|
|
|
- if success {
|
|
|
- fileURLArray.append(fileURL.lastPathComponent)
|
|
|
+ fileURL = fileURL.appendingPathExtension("tiff").uniqueFileURL()
|
|
|
+ let fileData = page.PDFListViewTIFFData(for: page.bounds(for: self.listView?.displayBox ?? .cropBox))
|
|
|
+ let success = (try?fileData?.write(to: fileURL)) != nil
|
|
|
+ if success {
|
|
|
+ fileURLArray.append(fileURL.lastPathComponent)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1810,7 +1813,7 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return[]
|
|
|
+ return []
|
|
|
}
|
|
|
|
|
|
func tableViewColumnDidResize(_ notification: Notification) {
|
|
@@ -3243,70 +3246,20 @@ extension KMLeftSideViewController {
|
|
|
if (itemIndexes.count > 1) {
|
|
|
pagesName.append(" pages")
|
|
|
} else {
|
|
|
- pagesName.append("page")
|
|
|
+ pagesName.append(" page")
|
|
|
}
|
|
|
|
|
|
let docmentName = self.listView.document?.documentURL.deletingPathExtension().lastPathComponent ?? ""
|
|
|
-
|
|
|
- var fileName = ""
|
|
|
- if (itemIndexes.count > 0) {
|
|
|
- if (itemIndexes.count == 1) {
|
|
|
- let idx = itemIndexes.first! + 1
|
|
|
- let tFileName = String(format: "%@ %@", pagesName, "\(idx)")
|
|
|
- return String(format: "%@%@", docmentName, tFileName)
|
|
|
- }
|
|
|
-
|
|
|
- var sortIndex = IndexSet()
|
|
|
- for idx in itemIndexes {
|
|
|
- let _idx = idx + 1
|
|
|
- sortIndex.insert(_idx)
|
|
|
- }
|
|
|
-// NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];
|
|
|
-// NSArray *sortDesc = @[sort];
|
|
|
-// NSArray *sortArray = [sortIndex sortedArrayUsingDescriptors:sortDesc];
|
|
|
- let sortArray = sortIndex.sorted()
|
|
|
-
|
|
|
- var a = 0
|
|
|
- var b = 0
|
|
|
-
|
|
|
- for num in sortArray {
|
|
|
-// for (NSNumber *num in sortArray) {
|
|
|
- if (fileName.isEmpty == false) {
|
|
|
- if (num == b+1) {
|
|
|
- b = num
|
|
|
- if (num == sortArray.last) {
|
|
|
- fileName = "\(fileName)\(a)-\(b)"
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (a == b) {
|
|
|
- fileName = "\(fileName)\(a),"
|
|
|
- } else {
|
|
|
- fileName = "\(fileName)\(a)-\(b),"
|
|
|
- }
|
|
|
- b = num
|
|
|
- a = b
|
|
|
- if (num == sortArray.last) {
|
|
|
- fileName = "\(fileName)\(a)"
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- fileName = ""
|
|
|
- b = num
|
|
|
- a = b
|
|
|
- }
|
|
|
- }
|
|
|
- let tFileName = String(format: "%@ %@", pagesName,fileName)
|
|
|
-
|
|
|
- return String(format: "%@%@", docmentName,tFileName)
|
|
|
- }
|
|
|
- return ""
|
|
|
+ let tFileName = String(format: "%@ %@", pagesName,KMTools.parseIndexSet(indexSet: itemIndexes))
|
|
|
+ return String(format: "%@%@", docmentName,tFileName)
|
|
|
}
|
|
|
|
|
|
func draggedFileName(for page: CPDFPage) -> String {
|
|
|
let pageIndex = "\(page.pageIndex() + 1)"
|
|
|
var fileName = ""
|
|
|
if let doc = self.view.window?.windowController?.document as? NSDocument {
|
|
|
- fileName = doc.displayName.deletingPathExtension
|
|
|
+// fileName = doc.displayName.deletingPathExtension
|
|
|
+ fileName = doc.fileURL?.deletingPathExtension().lastPathComponent ?? (MainBundle.nameSpaceName ?? "")
|
|
|
}
|
|
|
return "\(fileName)-Page \(pageIndex)"
|
|
|
}
|