|
@@ -15,6 +15,8 @@ import KMComponentLibrary
|
|
|
}
|
|
|
|
|
|
class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
+
|
|
|
+ weak open var pageEditViewController: KMNPageEditViewViewDelegate?
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
@@ -26,87 +28,6 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // MARK: - private
|
|
|
- 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.representedObject = point
|
|
|
- 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: #selector(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
|
|
|
- }
|
|
|
-
|
|
|
private func insertFilePath(filePath:String,pdfPassword:String?) {
|
|
|
let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
|
|
@@ -134,134 +55,6 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
}
|
|
|
|
|
|
// MARK: - public
|
|
|
- func updateThumnailItem(updateIndexPaths: Set<IndexPath>,isSelect:Bool) {
|
|
|
-
|
|
|
- for targetIndexPath in updateIndexPaths {
|
|
|
- let cellView = collectionView.item(at: targetIndexPath) as? KMNThumbnailCollectionViewItem
|
|
|
- if(cellView != nil) {
|
|
|
- cellView?.thumbnailMode.removeCacheImage()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- collectionView.reloadItems(at: updateIndexPaths)
|
|
|
- if(isSelect) {
|
|
|
- if updateIndexPaths.isEmpty { return }
|
|
|
- let firstIndexPath = updateIndexPaths.first
|
|
|
- collectionView.scrollToItems(at: [firstIndexPath ?? IndexPath(item: 0, section: 0)], scrollPosition: .top)
|
|
|
-
|
|
|
- collectionView.selectionIndexPaths = updateIndexPaths
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func updateAllThumnailItems() {
|
|
|
- KMNThumbnailManager.clearCacheFilePath(filePath: showDocument?.documentURL.path ?? "")
|
|
|
-
|
|
|
- collectionView.reloadData()
|
|
|
- }
|
|
|
-
|
|
|
- @objc public func insertFromPDFAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- let openPanel = NSOpenPanel()
|
|
|
- openPanel.allowedFileTypes = supportDragFileTypes()
|
|
|
- openPanel.allowsMultipleSelection = false
|
|
|
- openPanel.beginSheetModal(for: NSWindow.currentWindow()) {[weak self] result in
|
|
|
- if result == NSApplication.ModalResponse.OK {
|
|
|
- let fileURL = openPanel.url
|
|
|
- if(fileURL?.pathExtension == "pdf") {
|
|
|
- let pdfDoc = CPDFDocument(url: fileURL)
|
|
|
- if let data = pdfDoc?.isLocked, data {
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
|
|
|
- KMNBaseWindowController.checkPassword(url: fileURL ?? NSURL.fileURL(withPath: ""), type: .owner) { result, pwd in
|
|
|
- if (pwd.isEmpty == false) {
|
|
|
- self?.insertFilePath(filePath: fileURL?.path ?? "", pdfPassword: pwd)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- self?.insertFilePath(filePath: fileURL?.path ?? "", pdfPassword: nil)
|
|
|
- }
|
|
|
- } else {
|
|
|
- self?.insertFilePath(filePath: fileURL?.path ?? "", pdfPassword: nil)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @objc public func insertFromBlankAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
-
|
|
|
- let insertPDF = KMNPDFInsertBlankWindowController(self.showDocument, selectionIndexPaths: selectedIndexPaths)
|
|
|
- insertPDF.callback = { [weak self] pageSize, insertIdx in
|
|
|
- self?.insertBlankSize(pageSize: pageSize, pageDex: insertIdx)
|
|
|
- }
|
|
|
- insertPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
|
|
|
- }
|
|
|
-
|
|
|
- public func insertFromClipboardAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
- let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
- var maxmumIndex = 1
|
|
|
- if(selectedIndexPaths.count > 0) {
|
|
|
- let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
|
|
|
- maxmumIndex = (maxmumIndexPath?.item ?? 0) + 1
|
|
|
- }
|
|
|
-
|
|
|
- var error: NSError?
|
|
|
- guard let document: CPDFDocument = KMNConvertTool.openDocumentWithImageFromPasteboard(NSPasteboard.general, error: &error) else {
|
|
|
- return
|
|
|
- }
|
|
|
- if let page: CPDFPage = (document.page(at: 0)) {
|
|
|
- insertFormPages(insertPages: [page], pageDex: maxmumIndex)
|
|
|
- }
|
|
|
-
|
|
|
- self.thumbnailBaseViewDelegate?.insertPDFThumbnailViewControlle?(pageEditVC: self, pdfDocment: document)
|
|
|
- let ips: Set<IndexPath> = [IndexPath(item: maxmumIndex, section: 0)]
|
|
|
-
|
|
|
- refreshDatas()
|
|
|
- collectionView.selectionIndexPaths = ips
|
|
|
- collectionView.scrollToItems(at: ips, scrollPosition: .centeredVertically)
|
|
|
- }
|
|
|
-
|
|
|
- public func insertFromScannerAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
- let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
|
|
|
-
|
|
|
- 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
|
|
|
- _ = self?.showDocument?.km_insertPage(imag.size, withImage: url.path! , at:UInt(index))
|
|
|
-
|
|
|
- self?.refreshDatas()
|
|
|
-
|
|
|
- let ips: Set<IndexPath> = [IndexPath(item: index, section: 0)]
|
|
|
-
|
|
|
- self?.collectionView.selectionIndexPaths = ips
|
|
|
- self?.collectionView.scrollToItems(at: ips, scrollPosition: .centeredVertically)
|
|
|
- }
|
|
|
- }
|
|
|
- vc.showWindow(nil)
|
|
|
- vc.window?.center()
|
|
|
- }
|
|
|
-
|
|
|
public func canZoomInPageSize()->Bool {
|
|
|
if pageThumbnailSize.width > defaultItemSize.width {
|
|
|
return false
|
|
@@ -276,162 +69,6 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
- public func canUndo()->Bool {
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- public func undoPDFAction() {
|
|
|
- currentUndoManager?.undo()
|
|
|
- }
|
|
|
-
|
|
|
- public func canRodo()->Bool {
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- public func redoPDFAction() {
|
|
|
- currentUndoManager?.redo()
|
|
|
- }
|
|
|
-
|
|
|
- @objc public func extractPDFAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- 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)
|
|
|
- }
|
|
|
-
|
|
|
- @objc public func replacePDFAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- 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() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
-
|
|
|
- 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
|
|
|
- }
|
|
|
-
|
|
|
- let splitPDF = KMNSplitPDFWindowController(self.showDocument,selectionIndexPaths: selectedIndexPaths)
|
|
|
- splitPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
|
|
|
- }
|
|
|
-
|
|
|
- public func reversePDFAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
- 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:KMNTools.indexpathsToIndexs(indexpaths: selectedIndexPaths))
|
|
|
- }
|
|
|
-
|
|
|
- @objc public func rotatePageLeftAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- 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))
|
|
|
- return
|
|
|
- }
|
|
|
- rotatePages(indexPaths: collectionView.selectionIndexPaths, rotateAngle: -90)
|
|
|
- }
|
|
|
-
|
|
|
- @objc public func rotatePageRightAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- 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))
|
|
|
- return
|
|
|
- }
|
|
|
- rotatePages(indexPaths: collectionView.selectionIndexPaths, rotateAngle: 90)
|
|
|
- }
|
|
|
-
|
|
|
- public func deletePageAction() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- 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 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
|
|
@@ -463,146 +100,5 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
|
|
|
collectionView.reloadData()
|
|
|
collectionView.selectionIndexPaths = indexpaths
|
|
|
}
|
|
|
-
|
|
|
- // MARK: - MenuItem
|
|
|
- @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(menuItem:NSMenuItem) {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
|
- winC?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- var pastIndex = 1
|
|
|
- let point = menuItem.representedObject as? NSPoint
|
|
|
-
|
|
|
- if(point != nil) {
|
|
|
- let pointInCollectionView = collectionView.convert(point!, from: nil)
|
|
|
-
|
|
|
- let visibleItems = collectionView.visibleItems()
|
|
|
- let mouseX = pointInCollectionView.x
|
|
|
- let mouseY = pointInCollectionView.y
|
|
|
-
|
|
|
- // 获取当前行的所有 cell
|
|
|
- let currentRowItems = visibleItems.filter { item in
|
|
|
- if let indexPath = collectionView.indexPath(for: item),
|
|
|
- let cellAttributes = collectionView.layoutAttributesForItem(at: indexPath) {
|
|
|
- return cellAttributes.frame.minY <= mouseY && cellAttributes.frame.maxY >= mouseY
|
|
|
- }
|
|
|
- return false
|
|
|
- }
|
|
|
- if(mouseX < 24) { //点击区域在最左边
|
|
|
- // 找到最近右边的 cell
|
|
|
- let rightMostCell = currentRowItems.compactMap { collectionView.indexPath(for: $0) }
|
|
|
- .filter { indexPath in
|
|
|
- let cellRect = collectionView.layoutAttributesForItem(at: indexPath)?.frame
|
|
|
- return cellRect?.minX ?? 0 > mouseX // 只选择右侧的 cell
|
|
|
- }
|
|
|
- .sorted { ($0.item < $1.item) } // 按 item 的顺序排列
|
|
|
- .first // 选择第一个,即最右边的 cell
|
|
|
- pastIndex = (rightMostCell?.item ?? (Int(showDocument?.pageCount ?? 1)))
|
|
|
- } else {
|
|
|
- // 找到最近右边的 cell
|
|
|
- let leftMostCell = currentRowItems.compactMap { collectionView.indexPath(for: $0) }
|
|
|
- .filter { indexPath in
|
|
|
- let cellRect = collectionView.layoutAttributesForItem(at: indexPath)?.frame
|
|
|
- return cellRect?.maxX ?? 0 < mouseX // 只选择左侧的 cell
|
|
|
- }
|
|
|
- .sorted { $0.item > $1.item } // 按 item 的逆序排列,以选择最近的左侧 cell
|
|
|
- .first // 选择第一个,即最近的左边的 cell
|
|
|
-
|
|
|
- pastIndex = (leftMostCell?.item ?? (Int(showDocument?.pageCount ?? 1)) - 1) + 1
|
|
|
- }
|
|
|
- } else {
|
|
|
- let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
- if(selectedIndexPaths.count > 0) {
|
|
|
- let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
|
|
|
- pastIndex = ((maxmumIndexPath?.item ?? 0) + 1)
|
|
|
- } else {
|
|
|
- pastIndex = Int(showDocument?.pageCount ?? 0)
|
|
|
- }
|
|
|
- }
|
|
|
- let copyPages = KMNThumbnailManager.manager.copyPages
|
|
|
-
|
|
|
- insertFormPages(insertPages: copyPages, pageDex: pastIndex)
|
|
|
- }
|
|
|
-
|
|
|
- @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)
|
|
|
- }
|
|
|
-
|
|
|
- deletePages(indexpaths: indexpaths)
|
|
|
- }
|
|
|
-
|
|
|
- @objc public func deleteMenuItemAciton() {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
|
- winC?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
- let indexpaths = collectionView.selectionIndexPaths
|
|
|
- deletePages(indexpaths: indexpaths)
|
|
|
- }
|
|
|
-
|
|
|
- @objc func sharePageItemAction(menuItem:NSMenuItem) {
|
|
|
- if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
- let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
|
- winC?.showWindow(nil)
|
|
|
- return
|
|
|
- }
|
|
|
- let indexpaths = collectionView.selectionIndexPaths
|
|
|
-
|
|
|
- let doucument = 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(KMNTools.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
|
|
|
- }
|
|
|
|
|
|
}
|