|
@@ -20,9 +20,92 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
self.backViewBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-pdfView")
|
|
|
+
|
|
|
+ collectionView.menuClickedAction = { point in
|
|
|
+ return self.clickMenu(point: point)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public func insertFromPDFAction() {
|
|
|
+ private func clickMenu(point:NSPoint)->NSMenu {
|
|
|
+ let copyPages: [CPDFPage] = KMNThumbnailManager.manager.copyPages
|
|
|
+
|
|
|
+ let menu = NSMenu()
|
|
|
+ // 根据 clickPoint 创建菜单项
|
|
|
+ let copyMenuItem = NSMenuItem(title: KMLocalizedString("Copy"), action: #selector(copyMenuItemAciton), target: self)
|
|
|
+ copyMenuItem.keyEquivalent = "c"
|
|
|
+
|
|
|
+ let pastMenuItem = NSMenuItem(title: KMLocalizedString("Paste"), action: #selector(pastMenuItemAciton), target: self)
|
|
|
+ pastMenuItem.keyEquivalent = "v"
|
|
|
+
|
|
|
+ let pastNullMenuItem = NSMenuItem(title: KMLocalizedString("Paste"), action: nil, target: self)
|
|
|
+ pastNullMenuItem.keyEquivalent = "v"
|
|
|
+
|
|
|
+ let cutMenuItem = NSMenuItem(title: KMLocalizedString("Cut"), action: #selector(cutMenuItemAciton), target: self)
|
|
|
+ cutMenuItem.keyEquivalent = "x"
|
|
|
+
|
|
|
+ let deleteMenuItem = NSMenuItem(title: KMLocalizedString("Delete"), action: #selector(deleteMenuItemAciton), target: self)
|
|
|
+ deleteMenuItem.keyEquivalent = String(Unicode.Scalar(NSBackspaceCharacter)!)
|
|
|
+
|
|
|
+ let rotateLeftMenuItem = NSMenuItem(title: KMLocalizedString("90° CCW"), action: #selector(rotatePageLeftAction), target: self)
|
|
|
+ rotateLeftMenuItem.keyEquivalent = "l" // 设置为字母 l
|
|
|
+ rotateLeftMenuItem.keyEquivalentModifierMask = [.option, .command] // 设置为 Option + Command
|
|
|
+
|
|
|
+ let rotateRightMenuItem = NSMenuItem(title: KMLocalizedString("90° CW"), action: #selector(rotatePageRightAction), target: self)
|
|
|
+ rotateRightMenuItem.keyEquivalent = "r" // 设置为字母 r
|
|
|
+ rotateRightMenuItem.keyEquivalentModifierMask = [.option, .command] // 设置为 Option + Command
|
|
|
+
|
|
|
+ let insertFileMenuItem = NSMenuItem(title: KMLocalizedString("Insert File"), action: #selector(insertFromPDFAction), target: self)
|
|
|
+
|
|
|
+ let insertBlankMenuItem = NSMenuItem(title: KMLocalizedString("Insert a Blank Page"), action: #selector(insertFromBlankAction), target: self)
|
|
|
+
|
|
|
+ let replaceMenuItem = NSMenuItem(title: KMLocalizedString("Replace"), action: #selector(replacePDFAction), target: self)
|
|
|
+
|
|
|
+ let extractMenuItem = NSMenuItem(title: KMLocalizedString("Export"), action: #selector(extractPDFAction), target: self)
|
|
|
+
|
|
|
+ let shareMenuItem = NSMenuItem(title: KMLocalizedString("Share"), action: nil, target: self)
|
|
|
+
|
|
|
+ shareMenuItem.submenu = NSSharingServicePicker.menu(forSharingItems: [showDocument?.documentURL ?? ""], subjectContext: "", withTarget: self, selector: NSSelectorFromString("sharePageItemAction:"), serviceDelegate: nil)
|
|
|
+
|
|
|
+ let showFileSizeMenuItem = NSMenuItem(title: KMLocalizedString("Display Page Size"), action: #selector(displayPageSizeAction), target: self)
|
|
|
+ showFileSizeMenuItem.state = isShowPageSize ? .on : .off
|
|
|
+
|
|
|
+ let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
+
|
|
|
+ if(selectedIndexPaths.count > 0) {
|
|
|
+ menu.addItem(copyMenuItem)
|
|
|
+ menu.addItem(cutMenuItem)
|
|
|
+ if(copyPages.count > 0) {
|
|
|
+ menu.addItem(pastMenuItem)
|
|
|
+ }
|
|
|
+ menu.addItem(deleteMenuItem)
|
|
|
+ menu.addItem(NSMenuItem.separator())
|
|
|
+ menu.addItem(rotateRightMenuItem)
|
|
|
+ menu.addItem(rotateLeftMenuItem)
|
|
|
+ menu.addItem(NSMenuItem.separator())
|
|
|
+ if(selectedIndexPaths.count == 1) {
|
|
|
+ menu.addItem(insertFileMenuItem)
|
|
|
+ menu.addItem(insertBlankMenuItem)
|
|
|
+ menu.addItem(replaceMenuItem)
|
|
|
+ }
|
|
|
+ menu.addItem(extractMenuItem)
|
|
|
+ menu.addItem(shareMenuItem)
|
|
|
+ menu.addItem(NSMenuItem.separator())
|
|
|
+ menu.addItem(showFileSizeMenuItem)
|
|
|
+ } else {
|
|
|
+ if(copyPages.count > 0) {
|
|
|
+ menu.addItem(pastMenuItem)
|
|
|
+ menu.addItem(NSMenuItem.separator())
|
|
|
+ } else {
|
|
|
+ menu.addItem(pastNullMenuItem)
|
|
|
+ menu.addItem(NSMenuItem.separator())
|
|
|
+ }
|
|
|
+ menu.addItem(showFileSizeMenuItem)
|
|
|
+ }
|
|
|
+
|
|
|
+ return menu
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc public func insertFromPDFAction() {
|
|
|
if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
return
|
|
@@ -30,6 +113,7 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
|
|
|
let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
let minimumIndexPath = selectedIndexPaths.min(by: { $0 < $1 })
|
|
|
+ let open = NSOpenPanel()
|
|
|
|
|
|
let insertPDF = KMNPDFInsertPDFWindowController(self.showDocument, currentPageIndex: minimumIndexPath?.item ?? 0)
|
|
|
insertPDF.callback = { [weak self] fileAttribute, insertIdx in
|
|
@@ -53,16 +137,16 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
insertPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
|
|
|
}
|
|
|
|
|
|
- public func insertFromBlankAction() {
|
|
|
+ @objc public func insertFromBlankAction() {
|
|
|
if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
- let minimumIndexPath = selectedIndexPaths.min(by: { $0 < $1 })
|
|
|
+ let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
|
|
|
|
|
|
- let insertPDF = KMNPDFInsertBlankWindowController(self.showDocument, currentPageIndex: minimumIndexPath?.item ?? 0)
|
|
|
+ let insertPDF = KMNPDFInsertBlankWindowController(self.showDocument, currentPageIndex: maxmumIndexPath?.item ?? 0)
|
|
|
insertPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
|
|
|
}
|
|
|
|
|
@@ -72,9 +156,9 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
return
|
|
|
}
|
|
|
let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
- let minimumIndexPath = selectedIndexPaths.min(by: { $0 < $1 })
|
|
|
+ let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
|
|
|
|
|
|
- let insertPDF = KMNPDFInsertClipboardWindowController(self.showDocument, currentPageIndex: minimumIndexPath?.item ?? 0)
|
|
|
+ let insertPDF = KMNPDFInsertClipboardWindowController(self.showDocument, currentPageIndex: maxmumIndexPath?.item ?? 0)
|
|
|
insertPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
|
|
|
}
|
|
|
|
|
@@ -83,18 +167,36 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
- let minimumIndexPath = selectedIndexPaths.min(by: { $0 < $1 })
|
|
|
+ let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
|
|
|
|
|
|
- let insertPDF = KMNPDFInsertClipboardWindowController(self.showDocument, currentPageIndex: minimumIndexPath?.item ?? 0)
|
|
|
- insertPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
|
|
|
+ let vc = KMDeviceBrowserWindowController.shared
|
|
|
+ vc.type = .scanner
|
|
|
+ vc.importScannerFileCallback = { [weak self] (url: NSURL) -> Void in
|
|
|
+ if let imag = NSImage(contentsOfFile: url.path! ) {
|
|
|
+ let index = (maxmumIndexPath?.item ?? 0) + 1
|
|
|
+ let document = CPDFDocument()
|
|
|
+ _ = document?.km_insertPage(imag.size, withImage: url.path! , at:UInt(index))
|
|
|
+ self?.refreshDatas()
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vc.showWindow(nil)
|
|
|
+ vc.window?.center()
|
|
|
}
|
|
|
|
|
|
public func canZoomInPageSize()->Bool {
|
|
|
+ if pageThumbnailSize.width > defaultItemSize.width {
|
|
|
+ return false
|
|
|
+ }
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
public func canZoomOutPageSize()->Bool {
|
|
|
+ if pageThumbnailSize.width < defaultItemSize.width {
|
|
|
+ return false
|
|
|
+ }
|
|
|
return true
|
|
|
}
|
|
|
|
|
@@ -114,32 +216,67 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
- public func extractPDFAction() {
|
|
|
+ @objc public func extractPDFAction() {
|
|
|
if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if collectionView.selectionIndexPaths.count < 1 {
|
|
|
+ let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
+
|
|
|
+ if selectedIndexPaths.count < 1 {
|
|
|
_ = KMNCustomAlertView.alertView(message: KMLocalizedString("Please select one or more pages first to organize."), type: .info, fromView: self.view, point:CGPointMake(self.view.frame.origin.x + self.view.frame.size.width/2, self.view.bounds.size.height - 30))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
let extractPDF = KMNExtractPDFWindowController(self.showDocument, selectionIndexPaths: collectionView.selectionIndexPaths)
|
|
|
+ extractPDF.callback = { [weak self] oneDocumentPerPage, isDeletePage in
|
|
|
+ extractPDF.own_closeEndSheet()
|
|
|
+ if let _ = self?.showDocument {
|
|
|
+ self?.extractPages(indexpaths: selectedIndexPaths, oneDocumentPerPage: oneDocumentPerPage, callback: { [weak self] result, params in
|
|
|
+ if (result == .failure || result == .cancel) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (isDeletePage) {
|
|
|
+ self?.deletePages(indexpaths: selectedIndexPaths)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
extractPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- public func replacePDFAction() {
|
|
|
+ @objc public func replacePDFAction() {
|
|
|
if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
return
|
|
|
}
|
|
|
- if collectionView.selectionIndexPaths.count < 1 {
|
|
|
+
|
|
|
+ let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
+
|
|
|
+ if selectedIndexPaths.count < 1 {
|
|
|
_ = KMNCustomAlertView.alertView(message: KMLocalizedString("Please select one or more pages first to organize."), type: .info, fromView: self.view, point:CGPointMake(self.view.frame.origin.x + self.view.frame.size.width/2, self.view.bounds.size.height - 30))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ self.km_open_file_multi { [unowned self] index, params in
|
|
|
+ if (self.fetchProgressBlockParamsIsPasswordFile(params: params)) { // 加密文档进度回调
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let tFileUrl = self.fetchProgressBlockParamsForFileUrl(params: params)
|
|
|
+ let pdfExtensions = KMNConvertTool.supportPDFFileType()
|
|
|
+ if let exn = tFileUrl?.pathExtension, pdfExtensions.contains(exn) {
|
|
|
+ if (tFileUrl!.path.isPDFValid() == false) {
|
|
|
+ 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()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } completionBlock: { [unowned self] documents in
|
|
|
+ self.replacePages(of: selectedIndexPaths, with: documents)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public func splitPDFAction() {
|
|
@@ -149,8 +286,7 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
}
|
|
|
|
|
|
let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
- let minimumIndexPath = selectedIndexPaths.min(by: { $0 < $1 })
|
|
|
-
|
|
|
+
|
|
|
if collectionView.selectionIndexPaths.count < 1 {
|
|
|
_ = KMNCustomAlertView.alertView(message: KMLocalizedString("Please select one or more pages first to organize."), type: .info, fromView: self.view, point:CGPointMake(self.view.bounds.origin.x + self.view.bounds.size.width/2, self.view.bounds.size.height - 30))
|
|
|
return
|
|
@@ -166,14 +302,16 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
return
|
|
|
}
|
|
|
- if collectionView.selectionIndexPaths.count < 1 {
|
|
|
- _ = KMNCustomAlertView.alertView(message: KMLocalizedString("Please select one or more pages first to organize."), type: .info, fromView: self.view, point:CGPointMake(self.view.frame.origin.x + self.view.frame.size.width/2, self.view.bounds.size.height - 30))
|
|
|
+ let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
+
|
|
|
+ if selectedIndexPaths.count < 2 {
|
|
|
+ _ = KMNCustomAlertView.alertView(message: KMLocalizedString("No page selected. Please select at least two pages to organize."), type: .info, fromView: self.view, point:CGPointMake(self.view.frame.origin.x + self.view.frame.size.width/2, self.view.bounds.size.height - 30))
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ reversePages(indexs: self.indexpathsToIndexs(indexpaths: selectedIndexPaths))
|
|
|
}
|
|
|
|
|
|
- public func rotatePageLeftAction() {
|
|
|
+ @objc public func rotatePageLeftAction() {
|
|
|
if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
return
|
|
@@ -183,10 +321,10 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
_ = KMNCustomAlertView.alertView(message: KMLocalizedString("Please select one or more pages first to organize."), type: .info, fromView: self.view, point:CGPointMake(self.view.frame.origin.x + self.view.frame.size.width/2, self.view.bounds.size.height - 30))
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ rotatePages(indexPaths: collectionView.selectionIndexPaths, rotateAngle: -90)
|
|
|
}
|
|
|
|
|
|
- public func rotatePageRightAction() {
|
|
|
+ @objc public func rotatePageRightAction() {
|
|
|
if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
return
|
|
@@ -196,7 +334,7 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
_ = KMNCustomAlertView.alertView(message: KMLocalizedString("Please select one or more pages first to organize."), type: .info, fromView: self.view, point:CGPointMake(self.view.frame.origin.x + self.view.frame.size.width/2, self.view.bounds.size.height - 30))
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ rotatePages(indexPaths: collectionView.selectionIndexPaths, rotateAngle: 90)
|
|
|
}
|
|
|
|
|
|
public func deletePageAction() {
|
|
@@ -205,23 +343,177 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if collectionView.selectionIndexPaths.count < 1 {
|
|
|
+ let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
+
|
|
|
+ if selectedIndexPaths.count < 1 {
|
|
|
_ = KMNCustomAlertView.alertView(message: KMLocalizedString("Please select one or more pages first to organize."), type: .info, fromView: self.view, point:CGPointMake(self.view.frame.origin.x + self.view.frame.size.width/2, self.view.bounds.size.height - 30))
|
|
|
return
|
|
|
- } else if collectionView.selectionIndexPaths.count == (showDocument?.pageCount ?? 0) {
|
|
|
+ } else if selectedIndexPaths.count == (showDocument?.pageCount ?? 0) {
|
|
|
_ = KMNCustomAlertView.alertView(message: KMLocalizedString("Can not delete all pages."), type: .info, fromView: self.view, point:CGPointMake(self.view.frame.origin.x + self.view.frame.size.width/2, self.view.bounds.size.height - 30))
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
+ deletePages(indexpaths: selectedIndexPaths)
|
|
|
}
|
|
|
|
|
|
public func zoomInPageAction() { //放大
|
|
|
+ if (canZoomInPageSize() == false) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let indexpaths = collectionView.selectionIndexPaths
|
|
|
+
|
|
|
+ if (pageThumbnailSize.width < defaultItemSize.width) {
|
|
|
+ pageThumbnailSize = defaultItemSize
|
|
|
+ } else if (pageThumbnailSize.width == defaultItemSize.width) {
|
|
|
+ pageThumbnailSize = NSSize(width: defaultItemSize.width*1.5, height: defaultItemSize.height*1.5)
|
|
|
+ }
|
|
|
|
|
|
+ collectionView.reloadData()
|
|
|
+ collectionView.selectionIndexPaths = indexpaths
|
|
|
}
|
|
|
|
|
|
public func zoomOutPageAction() { //缩小
|
|
|
+ if (canZoomOutPageSize() == false) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let indexpaths = collectionView.selectionIndexPaths
|
|
|
+
|
|
|
+ if (pageThumbnailSize.width > defaultItemSize.width) {
|
|
|
+ pageThumbnailSize = defaultItemSize
|
|
|
+ } else if (pageThumbnailSize.width == defaultItemSize.width) {
|
|
|
+ pageThumbnailSize = NSSize(width: defaultItemSize.width*0.5, height: defaultItemSize.height*0.5)
|
|
|
+ }
|
|
|
+
|
|
|
+ collectionView.reloadData()
|
|
|
+ collectionView.selectionIndexPaths = indexpaths
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc public func copyMenuItemAciton() {
|
|
|
+ if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
+ let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
|
+ winC?.showWindow(nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ KMNThumbnailManager.manager.copyPages = []
|
|
|
+
|
|
|
+ let indexpaths = collectionView.selectionIndexPaths
|
|
|
+ for indexpath in indexpaths.sorted() {
|
|
|
+ guard let page = showDocument?.page(at: UInt(indexpath.item)).copy() as? CPDFPage else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ KMNThumbnailManager.manager.copyDocument.append(showDocument ?? CPDFDocument())
|
|
|
+ KMNThumbnailManager.manager.copyPages.append(page)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc public func pastMenuItemAciton() {
|
|
|
+ if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
+ let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
|
+ winC?.showWindow(nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
+
|
|
|
+ var pastIndex = 1
|
|
|
+ if(selectedIndexPaths.count > 0) {
|
|
|
+ let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
|
|
|
+ pastIndex = maxmumIndexPath?.item ?? 1
|
|
|
+ }
|
|
|
+
|
|
|
+ var indexpaths: Set<IndexPath> = []
|
|
|
+ let copyPages = KMNThumbnailManager.manager.copyPages
|
|
|
+ let page = copyPages.first
|
|
|
+ if page?.document == showDocument {
|
|
|
+ for (i, page) in copyPages.enumerated() {
|
|
|
+ let zCopyPage = page.copy() as? CPDFPage
|
|
|
+ if(zCopyPage != nil) {
|
|
|
+ showDocument?.insertPageObject(zCopyPage, at: UInt(pastIndex+i))
|
|
|
+ indexpaths.insert(IndexPath(item: pastIndex+i, section: 0))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if let pasteDocument = page?.document {
|
|
|
+ var indexs: IndexSet = IndexSet()
|
|
|
+ for (i, _) in copyPages.enumerated() {
|
|
|
+ indexs.insert(i)
|
|
|
+ indexpaths.insert(IndexPath(item: pastIndex+i, section: 0))
|
|
|
+ }
|
|
|
+ showDocument?.importPages(indexs, from: pasteDocument, at: UInt(pastIndex))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ refreshDatas()
|
|
|
+ collectionView.reloadData()
|
|
|
+ collectionView.selectionIndexPaths = indexpaths
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc public func cutMenuItemAciton() {
|
|
|
+ if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
+ let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
|
+ winC?.showWindow(nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let indexpaths = collectionView.selectionIndexPaths
|
|
|
+ for indexpath in indexpaths.sorted() {
|
|
|
+ guard let page = showDocument?.page(at: UInt(indexpath.item)).copy() as? CPDFPage else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ KMNThumbnailManager.manager.copyDocument.append(showDocument ?? CPDFDocument())
|
|
|
+ KMNThumbnailManager.manager.copyPages.append(page)
|
|
|
+
|
|
|
+ showDocument?.removePage(at: UInt(indexpath.item))
|
|
|
+ refreshDatas()
|
|
|
+ collectionView.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc public func deleteMenuItemAciton() {
|
|
|
+ if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
+ let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
|
+ winC?.showWindow(nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let indexpaths = collectionView.selectionIndexPaths
|
|
|
+ for indexpath in indexpaths.sorted() {
|
|
|
+
|
|
|
+ showDocument?.removePage(at: UInt(indexpath.item))
|
|
|
+ refreshDatas()
|
|
|
+ collectionView.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func sharePageItemAction(menuItem:NSMenuItem) {
|
|
|
+ if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
+ let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
|
+ winC?.showWindow(nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let indexpaths = collectionView.selectionIndexPaths
|
|
|
+
|
|
|
+ let doucument = self.showDocument
|
|
|
+ let filename : String = doucument?.documentURL.lastPathComponent ?? ""
|
|
|
+ let folderPath = (NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(filename)) ?? ""
|
|
|
+
|
|
|
+ try? FileManager.default.removeItem(atPath: folderPath)
|
|
|
|
|
|
+ let pdfdocument = CPDFDocument()
|
|
|
+ let ret = pdfdocument?.importPages(indexpathsToIndexs(indexpaths: indexpaths), from: doucument, at: 0) ?? false
|
|
|
+ let url = URL(fileURLWithPath: folderPath)
|
|
|
+ if ret {
|
|
|
+ let success = pdfdocument?.write(toFile: folderPath)
|
|
|
+ let represent = menuItem.representedObject as? NSSharingService
|
|
|
+ represent?.perform(withItems: [url])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc public func displayPageSizeAction() {
|
|
|
+ let indexpaths = collectionView.selectionIndexPaths
|
|
|
+ isShowPageSize = !isShowPageSize
|
|
|
+ collectionView.selectionIndexPaths = indexpaths
|
|
|
}
|
|
|
|
|
|
}
|