KMNThumbnailBaseViewController.swift 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. //
  2. // KMNThumbnailBaseViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by 丁林圭 on 2024/10/21.
  6. //
  7. import Cocoa
  8. @objc protocol KMNThumbnailBaseViewDelegate: AnyObject {
  9. @objc optional func clickThumbnailViewControlle(pageEditVC:KMNThumbnailBaseViewController?,currentIndex:Int)
  10. @objc optional func insertPDFThumbnailViewControlle(pageEditVC:KMNThumbnailBaseViewController?,pdfDocment:CPDFDocument?)
  11. @objc optional func changeIndexPathsThumbnailViewControlle(pageEditVC:KMNThumbnailBaseViewController?,selectionIndexPaths: Set<IndexPath>,selectionStrings:String )
  12. }
  13. enum KMNThumbnailChoosePageStyle: Int {
  14. case odd
  15. case even
  16. case horizontal
  17. case vertical
  18. case allPage
  19. case custom
  20. }
  21. internal let kmnThumLocalForDraggedTypes = NSPasteboard.PasteboardType(rawValue: "kmnThumLocalForDraggedTypes")
  22. let topThumOffset: CGFloat = 12.0 // 缩图顶部高度
  23. let infoThumTitleHeight: CGFloat = 16.0 //文字高度
  24. let infoThumTitleBottom: CGFloat = 16.0 // 底部高度
  25. class KMNThumbnailBaseViewController: KMNBaseViewController,NSCollectionViewDelegate, NSCollectionViewDataSource,NSCollectionViewDelegateFlowLayout {
  26. let maxCellHeight: CGFloat = 320.0 - infoThumTitleBottom - infoThumTitleHeight - topThumOffset * 2
  27. let minCellHeight: CGFloat = 80.0 - infoThumTitleBottom - infoThumTitleHeight - topThumOffset - topThumOffset * 2
  28. weak open var thumbnailBaseViewDelegate: KMNThumbnailBaseViewDelegate?
  29. @IBOutlet var backViewBox: NSBox!
  30. @IBOutlet var scrollView: NSScrollView!
  31. @IBOutlet var collectionView: KMNThumbnailCollectionView!
  32. private var currentDocument:CPDFDocument?
  33. private var isChangeIndexPaths = false
  34. var lockedFiles: [URL] = []
  35. internal var dragedIndexPaths: [IndexPath] = []
  36. public var thumbnails:[KMNThumbnail] = []
  37. public var dragLocalityPages: [CPDFPage] = []
  38. public var currentUndoManager:UndoManager?
  39. public var showDocument: CPDFDocument? {
  40. return currentDocument
  41. }
  42. public var changeDocument:CPDFDocument? {
  43. didSet {
  44. if(changeDocument != nil && changeDocument != currentDocument) {
  45. currentDocument = changeDocument
  46. refreshDatas()
  47. collectionView.reloadData()
  48. }
  49. }
  50. }
  51. public var thumbnailChoosePageStyle:KMNThumbnailChoosePageStyle = .custom {
  52. didSet {
  53. var tSelectionIndexPaths: Set<IndexPath> = []
  54. let pageCount = currentDocument?.pageCount ?? 0
  55. switch thumbnailChoosePageStyle {
  56. case .even:
  57. for i in 0 ..< pageCount {
  58. if(i % 2 == 0) {
  59. tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
  60. }
  61. }
  62. case .odd:
  63. for i in 0 ..< pageCount {
  64. if(i % 2 != 0) {
  65. tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
  66. }
  67. }
  68. case .allPage:
  69. for i in 0 ..< pageCount {
  70. tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
  71. }
  72. case .vertical:
  73. for i in 0 ..< pageCount {
  74. let page = showDocument?.page(at: i)
  75. if(page != nil) {
  76. if(page!.rotation % 180 != 0) {
  77. tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
  78. }
  79. }
  80. }
  81. case .horizontal:
  82. for i in 0 ..< pageCount {
  83. let page = showDocument?.page(at: i)
  84. if(page != nil) {
  85. if(page!.rotation % 180 == 0) {
  86. tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
  87. }
  88. }
  89. }
  90. default: break
  91. }
  92. isChangeIndexPaths = true
  93. collectionView.selectionIndexPaths = tSelectionIndexPaths
  94. isChangeIndexPaths = false
  95. }
  96. }
  97. var selectionIndexPaths: Set<IndexPath> = [] {
  98. didSet {
  99. var indexpaths: Set<IndexPath> = []
  100. for indexpath in selectionIndexPaths {
  101. if (indexpath.section >= collectionView.numberOfSections) {
  102. continue
  103. }
  104. if indexpath.section < 0 {
  105. continue
  106. }
  107. if (indexpath.item >= collectionView.numberOfItems(inSection: indexpath.section)) {
  108. continue
  109. }
  110. if indexpath.item < 0 {
  111. continue
  112. }
  113. indexpaths.insert(indexpath)
  114. }
  115. collectionView.selectionIndexPaths = indexpaths
  116. if(indexpaths.count > 0) {
  117. let firstIndexPath = indexpaths.first
  118. let itemFrame = collectionView.frameForItem(at: firstIndexPath!.item)
  119. let itemFrameInCollectionView = collectionView.convert(itemFrame, to: self.view)
  120. if collectionView.bounds.contains(itemFrameInCollectionView) {
  121. } else {
  122. collectionView.scrollToItems(at: indexpaths, scrollPosition: .bottom)
  123. }
  124. }
  125. }
  126. }
  127. public var isShowPageSize:Bool = false {
  128. didSet {
  129. if oldValue != isShowPageSize {
  130. var pageSize = pageThumbnailSize
  131. if(isShowPageSize) {
  132. pageSize.height += infoThumTitleHeight
  133. } else {
  134. pageSize.height -= infoThumTitleHeight
  135. }
  136. pageThumbnailSize = pageSize
  137. collectionView.reloadData()
  138. }
  139. }
  140. }
  141. public var pageThumbnailSize:CGSize = CGSizeMake(185.0, 260) {
  142. didSet {
  143. collectionView.reloadData()
  144. }
  145. }
  146. public let defaultItemSize = NSMakeSize(185.0, 260)
  147. deinit {
  148. thumbnailBaseViewDelegate = nil
  149. KMPrint("KMNThumbnailBaseViewController deinit.")
  150. }
  151. init(_ document: CPDFDocument?) {
  152. super.init(nibName: "KMNThumbnailBaseViewController", bundle: nil)
  153. currentDocument = document
  154. }
  155. init(_ filePath: String,password:String?) {
  156. super.init(nibName: "KMNThumbnailBaseViewController", bundle: nil)
  157. let document = CPDFDocument.init(url: URL(fileURLWithPath: filePath))
  158. if password != nil {
  159. document?.unlock(withPassword: password as String?)
  160. }
  161. if document?.allowsCopying == false || document?.allowsPrinting == false {
  162. exitCurrentView()
  163. } else {
  164. currentDocument = document
  165. }
  166. }
  167. required init?(coder: NSCoder) {
  168. fatalError("init(coder:) has not been implemented")
  169. }
  170. override func viewDidLoad() {
  171. super.viewDidLoad()
  172. collectionView.delegate = self
  173. collectionView.dataSource = self
  174. collectionView.isSelectable = true //支持拖拽需设置未True
  175. collectionView.allowsMultipleSelection = true
  176. collectionView.enclosingScrollView?.hasVerticalScroller = false
  177. collectionView.enclosingScrollView?.hasHorizontalScroller = false
  178. scrollView.scrollerStyle = .overlay
  179. collectionView.register(KMNThumbnailCollectionViewItem.self, forItemWithIdentifier: NSUserInterfaceItemIdentifier(rawValue: "thumbnailCollectionViewItem"))
  180. collectionView.registerForDraggedTypes([.fileURL,.string,.pdf])
  181. collectionView.setDraggingSourceOperationMask(.every, forLocal: false)
  182. collectionView.setDraggingSourceOperationMask(.every, forLocal: true)
  183. refreshDatas()
  184. }
  185. public func exitCurrentView() {
  186. let minIndexPath = selectionIndexPaths.max(by: { $0.item < $1.item })
  187. thumbnailBaseViewDelegate?.clickThumbnailViewControlle?(pageEditVC: self, currentIndex: minIndexPath?.item ?? 0)
  188. }
  189. public func supportDragFileTypes()->[String] {
  190. let supportFiles = KMNConvertTool.pdfExtensions + KMConvertPDFManager.supportFileType()
  191. return supportFiles
  192. }
  193. public func refreshDatas() {
  194. thumbnails = []
  195. if currentDocument != nil {
  196. for i in 0 ... currentDocument!.pageCount - 1 {
  197. let thumbnail = KMNThumbnail.init(document: currentDocument!, currentPageIndex: Int(i))
  198. thumbnails.append(thumbnail)
  199. }
  200. }
  201. }
  202. public func reloadDataDatas() {
  203. refreshDatas()
  204. collectionView.reloadData()
  205. }
  206. // MARK: - private
  207. public func clickMenu(point:NSPoint)->NSMenu {
  208. let copyPages: [CPDFPage] = KMNThumbnailManager.manager.copyPages
  209. let menu = NSMenu()
  210. // 根据 clickPoint 创建菜单项
  211. let copyMenuItem = NSMenuItem(title: KMLocalizedString("Copy"), action: #selector(copyMenuItemAciton), target: self)
  212. copyMenuItem.keyEquivalent = "c"
  213. let pastMenuItem = NSMenuItem(title: KMLocalizedString("Paste"), action: #selector(pastMenuItemAciton), target: self)
  214. pastMenuItem.representedObject = point
  215. pastMenuItem.keyEquivalent = "v"
  216. let pastNullMenuItem = NSMenuItem(title: KMLocalizedString("Paste"), action: nil, target: self)
  217. pastNullMenuItem.keyEquivalent = "v"
  218. let cutMenuItem = NSMenuItem(title: KMLocalizedString("Cut"), action: #selector(cutMenuItemAciton), target: self)
  219. cutMenuItem.keyEquivalent = "x"
  220. let deleteMenuItem = NSMenuItem(title: KMLocalizedString("Delete"), action: #selector(deleteMenuItemAciton), target: self)
  221. deleteMenuItem.keyEquivalent = String(Unicode.Scalar(NSBackspaceCharacter)!)
  222. let rotateLeftMenuItem = NSMenuItem(title: KMLocalizedString("90° CCW"), action: #selector(rotatePageLeftAction), target: self)
  223. rotateLeftMenuItem.keyEquivalent = "l" // 设置为字母 l
  224. rotateLeftMenuItem.keyEquivalentModifierMask = [.option, .command] // 设置为 Option + Command
  225. let rotateRightMenuItem = NSMenuItem(title: KMLocalizedString("90° CW"), action: #selector(rotatePageRightAction), target: self)
  226. rotateRightMenuItem.keyEquivalent = "r" // 设置为字母 r
  227. rotateRightMenuItem.keyEquivalentModifierMask = [.option, .command] // 设置为 Option + Command
  228. let insertFileMenuItem = NSMenuItem(title: KMLocalizedString("Insert File"), action: #selector(insertFromPDFAction), target: self)
  229. let insertBlankMenuItem = NSMenuItem(title: KMLocalizedString("Insert a Blank Page"), action: #selector(insertFromBlankAction), target: self)
  230. let replaceMenuItem = NSMenuItem(title: KMLocalizedString("Replace"), action: #selector(replacePDFAction), target: self)
  231. let extractMenuItem = NSMenuItem(title: KMLocalizedString("Export"), action: #selector(extractPDFAction), target: self)
  232. let shareMenuItem = NSMenuItem(title: KMLocalizedString("Share"), action: nil, target: self)
  233. shareMenuItem.submenu = NSSharingServicePicker.menu(forSharingItems: [showDocument?.documentURL ?? ""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  234. let showFileSizeMenuItem = NSMenuItem(title: KMLocalizedString("Display Page Size"), action: #selector(displayPageSizeAction), target: self)
  235. showFileSizeMenuItem.state = isShowPageSize ? .on : .off
  236. let selectedIndexPaths = collectionView.selectionIndexPaths
  237. if(selectedIndexPaths.count > 0) {
  238. menu.addItem(copyMenuItem)
  239. menu.addItem(cutMenuItem)
  240. if(copyPages.count > 0) {
  241. menu.addItem(pastMenuItem)
  242. }
  243. menu.addItem(deleteMenuItem)
  244. menu.addItem(NSMenuItem.separator())
  245. menu.addItem(rotateRightMenuItem)
  246. menu.addItem(rotateLeftMenuItem)
  247. menu.addItem(NSMenuItem.separator())
  248. if(selectedIndexPaths.count == 1) {
  249. menu.addItem(insertFileMenuItem)
  250. menu.addItem(insertBlankMenuItem)
  251. menu.addItem(replaceMenuItem)
  252. }
  253. menu.addItem(extractMenuItem)
  254. menu.addItem(shareMenuItem)
  255. menu.addItem(NSMenuItem.separator())
  256. menu.addItem(showFileSizeMenuItem)
  257. } else {
  258. if(copyPages.count > 0) {
  259. menu.addItem(pastMenuItem)
  260. menu.addItem(NSMenuItem.separator())
  261. } else {
  262. menu.addItem(pastNullMenuItem)
  263. menu.addItem(NSMenuItem.separator())
  264. }
  265. menu.addItem(showFileSizeMenuItem)
  266. }
  267. return menu
  268. }
  269. // MARK: - NSCollectionViewDataSource
  270. func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
  271. return thumbnails.count
  272. }
  273. func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
  274. let item: KMNThumbnailCollectionViewItem = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "thumbnailCollectionViewItem"), for: indexPath) as! KMNThumbnailCollectionViewItem
  275. item.isShowFileSize = isShowPageSize
  276. item.doubleClickBack = { [weak self] in
  277. self?.thumbnailBaseViewDelegate?.clickThumbnailViewControlle?(pageEditVC: self, currentIndex: indexPath.item)
  278. }
  279. item.thumbnailMode = thumbnails[indexPath.item]
  280. return item
  281. }
  282. func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
  283. if isChangeIndexPaths == false {
  284. let indexpathsz = collectionView.selectionIndexPaths
  285. let dex:IndexSet = KMNTools.indexpathsToIndexs(indexpaths: indexpathsz)
  286. let selectedIndexPathsString = KMNTools.parseIndexSet(indexSet: dex)
  287. thumbnailBaseViewDelegate?.changeIndexPathsThumbnailViewControlle?(pageEditVC: self, selectionIndexPaths: indexpathsz, selectionStrings: selectedIndexPathsString)
  288. }
  289. }
  290. func collectionView(_ collectionView: NSCollectionView, didDeselectItemsAt indexPaths: Set<IndexPath>) {
  291. if isChangeIndexPaths == false {
  292. let indexpathsz = self.collectionView.selectionIndexPaths
  293. let dex:IndexSet = KMNTools.indexpathsToIndexs(indexpaths: indexpathsz)
  294. let selectedIndexPathsString = KMNTools.parseIndexSet(indexSet: dex)
  295. thumbnailBaseViewDelegate?.changeIndexPathsThumbnailViewControlle?(pageEditVC: self, selectionIndexPaths: indexpathsz, selectionStrings: selectedIndexPathsString)
  296. }
  297. }
  298. // MARK: - NSCollectionViewDelegateFlowLayout
  299. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
  300. return pageThumbnailSize
  301. }
  302. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  303. return 16.0
  304. }
  305. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  306. return 24.0
  307. }
  308. public func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
  309. return NSEdgeInsetsMake(24.0, 24.0, 24.0, 24.0)
  310. }
  311. //MARK: - NSCollectionViewDelegate
  312. func collectionView(_ collectionView: NSCollectionView,
  313. writeItemsAt indexPaths: Set<IndexPath>,
  314. to pasteboard: NSPasteboard) -> Bool {
  315. if IAPProductsManager.default().isAvailableAllFunction() == false {
  316. return false
  317. }
  318. var docmentName = currentDocument?.documentURL.lastPathComponent.deletingPathExtension ?? ""
  319. let pagesName = indexPaths.count > 1 ? " pages" : " page"
  320. var tFileName = pagesName + KMNTools.parseIndexPathsSet(indexSets: collectionView.selectionIndexPaths)
  321. if tFileName.count > 50 {
  322. tFileName = String(tFileName.prefix(50))
  323. }
  324. pasteboard.declareTypes([.fileURL], owner: self)
  325. let writePDFDocument = CPDFDocument()
  326. for indexPath in indexPaths {
  327. let row = indexPath.item
  328. if let copyPage = currentDocument?.page(at: UInt(row)) as? CPDFPage {
  329. writePDFDocument?.insertPageObject(copyPage, at: writePDFDocument?.pageCount ?? 0)
  330. }
  331. }
  332. var cachesDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
  333. cachesDir = cachesDir.appendingPathComponent("PageEdit_Pasteboard")
  334. let fileManager = FileManager.default
  335. if !fileManager.fileExists(atPath: cachesDir.path) {
  336. try? FileManager.default.createDirectory(atPath: cachesDir.path, withIntermediateDirectories: true, attributes: nil)
  337. }
  338. docmentName = "\(docmentName)\(tFileName)"
  339. if docmentName.count > 50 {
  340. docmentName = String(docmentName.prefix(50))
  341. }
  342. dragedIndexPaths.removeAll()
  343. for indexPath in indexPaths {
  344. dragedIndexPaths.append(indexPath)
  345. }
  346. let filePathURL = cachesDir.appendingPathComponent(docmentName).appendingPathExtension("pdf")
  347. let success = writePDFDocument?.write(to: filePathURL, isSaveFontSubset:false)
  348. if success == true {
  349. pasteboard.setPropertyList([filePathURL.path], forType: .fileURL)
  350. return true
  351. } else {
  352. return false
  353. }
  354. }
  355. func collectionView(_ collectionView: NSCollectionView,
  356. draggingSession session: NSDraggingSession,
  357. willBeginAt screenPoint: NSPoint,
  358. forItemsAt indexPaths: Set<IndexPath>) {
  359. let sortedIndexPaths = indexPaths.sorted { (ip1, ip2) -> Bool in
  360. if ip1.section == ip2.section {
  361. return ip1.item < ip2.item
  362. }
  363. return ip1.section < ip2.section
  364. }
  365. dragLocalityPages = []
  366. for fromIndexPath in sortedIndexPaths {
  367. let page = thumbnails[fromIndexPath.item].thumbnaiPage
  368. if(page != nil) {
  369. dragLocalityPages.append(page!)
  370. }
  371. }
  372. }
  373. func collectionView(_ collectionView: NSCollectionView, validateDrop draggingInfo: NSDraggingInfo, proposedIndexPath proposedDropIndexPath: AutoreleasingUnsafeMutablePointer<NSIndexPath>, dropOperation proposedDropOperation: UnsafeMutablePointer<NSCollectionView.DropOperation>) -> NSDragOperation {
  374. let pboard = draggingInfo.draggingPasteboard
  375. if dragLocalityPages.count != 0 {
  376. if proposedDropOperation.pointee == .on {
  377. proposedDropOperation.pointee = .before
  378. }
  379. return .move
  380. } else if ((pboard.availableType(from: [.fileURL])) != nil) {
  381. guard let pbItems = pboard.pasteboardItems else {
  382. return NSDragOperation(rawValue: 0)
  383. }
  384. var hasValidFile = false
  385. for item in pbItems {
  386. guard let data = item.string(forType: .fileURL), let url = URL(string: data) else {
  387. continue
  388. }
  389. let type = url.pathExtension.lowercased()
  390. if (supportDragFileTypes().contains(type)) {
  391. hasValidFile = true
  392. break
  393. }
  394. }
  395. if (!hasValidFile) {
  396. return NSDragOperation(rawValue: 0)
  397. }
  398. }
  399. return .copy
  400. }
  401. func collectionView(_ collectionView: NSCollectionView,
  402. acceptDrop draggingInfo: NSDraggingInfo,
  403. indexPath: IndexPath,
  404. dropOperation: NSCollectionView.DropOperation) -> Bool {
  405. let pboard = draggingInfo.draggingPasteboard
  406. if dragLocalityPages.count != 0 {
  407. movePages(pages: dragLocalityPages, destinationDex: indexPath.item)
  408. return true
  409. } else if ((pboard.availableType(from: [.fileURL])) != nil) {
  410. let index = indexPath.item
  411. guard let pbItems = pboard.pasteboardItems else {
  412. return false
  413. }
  414. //获取url
  415. var fileNames: [String] = []
  416. for item in pbItems {
  417. guard let data = item.string(forType: .fileURL), let url = URL(string: data) else {
  418. continue
  419. }
  420. let type = url.pathExtension.lowercased()
  421. if (supportDragFileTypes().contains(type)) {
  422. if(FileManager.default.fileExists(atPath: url.path)) {
  423. fileNames.append(url.path)
  424. }
  425. }
  426. }
  427. if(fileNames.count > 0) {
  428. insertFromFilePath(fileNames: fileNames, formDex: 0, indexDex: UInt(index), selectIndexs: []) { newSelectIndexs in
  429. }
  430. return true
  431. }
  432. }
  433. return false
  434. }
  435. func collectionView(_ collectionView: NSCollectionView,
  436. draggingSession session: NSDraggingSession,
  437. endedAt screenPoint: NSPoint,
  438. dragOperation operation: NSDragOperation) {
  439. dragLocalityPages = []
  440. }
  441. }
  442. // MARK: - NSFilePromiseProviderDelegate
  443. //extension KMNThumbnailBaseViewController: NSFilePromiseProviderDelegate {
  444. // func filePromiseProvider(_ filePromiseProvider: NSFilePromiseProvider, writePromiseTo url: URL, completionHandler: @escaping (Error?) -> Void) {
  445. //
  446. // }
  447. //
  448. // func filePromiseProvider(_ filePromiseProvider: NSFilePromiseProvider, writePromiseTo url: URL) async throws {
  449. //
  450. // }
  451. //
  452. // func filePromiseProvider(_ filePromiseProvider: NSFilePromiseProvider, fileNameForType fileType: String) -> String {
  453. // var fileName: String = "Untitle"
  454. // if let _string = showDocument?.documentURL.deletingPathExtension().lastPathComponent {
  455. // fileName = _string
  456. // }
  457. // fileName.append(" pages")
  458. // var indexs = IndexSet()
  459. // for indexpath in self.dragedIndexPaths {
  460. // indexs.insert(indexpath.item)
  461. // }
  462. // fileName.append(" ")
  463. // fileName.append(KMPageRangeTools.newParseSelectedIndexs(selectedIndex: indexs.sorted()))
  464. // fileName.append(".pdf")
  465. //
  466. // return fileName
  467. // }
  468. //
  469. //}