|
@@ -295,17 +295,41 @@ class KMPDFThumbViewBaseController: KMBaseViewController {
|
|
|
|
|
|
// 替换 特定的item
|
|
|
public func replaceAction() {
|
|
|
- self.replacePages(at: self.getPasteIndex())
|
|
|
+ Task { @MainActor in
|
|
|
+ if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
|
|
|
+ let _ = KMComparativeTableViewController.show(window: self.view.window!)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ self.km_open_pdf_multi { [unowned self] documents in
|
|
|
+ self.replacePages(of: self.thumbnailView.selectionIndexPaths, with: documents)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 替换 指定的item
|
|
|
- public func replacePages(at index: Int) {
|
|
|
+ public func replacePages(of targetIndexpaths: Set<IndexPath>, with documents: [CPDFDocument]) {
|
|
|
Task { @MainActor in
|
|
|
if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
|
|
|
let _ = KMComparativeTableViewController.show(window: self.view.window!)
|
|
|
return
|
|
|
}
|
|
|
- self._replacePages(at: index)
|
|
|
+
|
|
|
+ if (targetIndexpaths.count == 0 || documents.count == 0) {
|
|
|
+ KMPrint("replace invalid.")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let index = targetIndexpaths.sorted().first!.item
|
|
|
+
|
|
|
+ var pages: Array<CPDFPage> = []
|
|
|
+ for document in documents {
|
|
|
+ for i in 0 ..< document.pageCount {
|
|
|
+ let page = document.page(at: i)
|
|
|
+ pages.append(page!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self._undo_replace(of: self.indexpathsToIndexs(indexpaths: targetIndexpaths), with: pages, at: index)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -446,26 +470,6 @@ class KMPDFThumbViewBaseController: KMBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private func _replacePages(at index: Int) {
|
|
|
- self.km_open_pdf_multi { [unowned self] documents in
|
|
|
- /// 处理page
|
|
|
- var pages: Array<CPDFPage> = []
|
|
|
- self.thumbnailView.document?.removePage(at: UInt(index))
|
|
|
-
|
|
|
- var insertIndex: Int = index
|
|
|
- for document in documents {
|
|
|
- for i in 0 ..< document.pageCount {
|
|
|
- let page = document.page(at: i)
|
|
|
- pages.append(page!)
|
|
|
- self.thumbnailView.document?.insertPageObject(page, at:UInt(insertIndex))
|
|
|
- insertIndex += 1
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- self.refreshUI()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// MARK: - Edit Actions
|
|
|
|
|
|
@objc private func _insertPages(pages: Array<CPDFPage>, indexs: IndexSet) -> IndexSet {
|
|
@@ -549,6 +553,16 @@ class KMPDFThumbViewBaseController: KMBaseViewController {
|
|
|
return newIndexs
|
|
|
}
|
|
|
|
|
|
+ private func _replacePages(of targetIndexs: IndexSet, with pages: [CPDFPage], at index: Int) {
|
|
|
+ self.thumbnailView.document?.removePage(at: targetIndexs)
|
|
|
+
|
|
|
+ var insertIndex = index
|
|
|
+ for page in pages {
|
|
|
+ self.thumbnailView.document?.insertPageObject(page, at:UInt(insertIndex))
|
|
|
+ insertIndex += 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: - Undo & Redo Actions
|
|
|
|
|
|
@objc private func _undo_insertPages(pages: Array<CPDFPage>, indexs: IndexSet) {
|
|
@@ -611,6 +625,22 @@ class KMPDFThumbViewBaseController: KMBaseViewController {
|
|
|
self.refreshUIForKeepSelecteds()
|
|
|
}
|
|
|
|
|
|
+ @objc private func _undo_replace(of targetIndexs: IndexSet, with pages: [CPDFPage], at index: Int) {
|
|
|
+ self.kmUndoManager?.beginUndoGrouping()
|
|
|
+ // 先删除
|
|
|
+ self._undo_deletePages(indexs: targetIndexs)
|
|
|
+ // 再插入
|
|
|
+ var indexs = IndexSet()
|
|
|
+ var insertIndex = index
|
|
|
+ for _ in pages {
|
|
|
+ indexs.insert(insertIndex)
|
|
|
+ insertIndex += 1
|
|
|
+ }
|
|
|
+ self._undo_insertPages(pages: pages, indexs: indexs)
|
|
|
+ self.kmUndoManager?.endUndoGrouping()
|
|
|
+ self.refreshUI()
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: - Menu
|
|
|
|
|
|
func addMenuItem(menu: NSMenu, item: KMPDFThumbViewMenu.Item) -> NSMenuItem? {
|