Browse Source

【BOTA】缩略图插入空白页菜单功能补充

tangchao 1 year ago
parent
commit
ffd5eb26b5

+ 16 - 0
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -2567,6 +2567,9 @@
 		BB276A5C2B038D3A00AB5578 /* KMOCRPDFWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB276A5B2B038D3A00AB5578 /* KMOCRPDFWindowController.xib */; };
 		BB276A5D2B038D3A00AB5578 /* KMOCRPDFWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB276A5B2B038D3A00AB5578 /* KMOCRPDFWindowController.xib */; };
 		BB276A5E2B038D3A00AB5578 /* KMOCRPDFWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB276A5B2B038D3A00AB5578 /* KMOCRPDFWindowController.xib */; };
+		BB27BF3C2B33E85200A0BAAE /* CPDFView+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB27BF3B2B33E85200A0BAAE /* CPDFView+KMExtension.swift */; };
+		BB27BF3D2B33E85200A0BAAE /* CPDFView+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB27BF3B2B33E85200A0BAAE /* CPDFView+KMExtension.swift */; };
+		BB27BF3E2B33E85200A0BAAE /* CPDFView+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB27BF3B2B33E85200A0BAAE /* CPDFView+KMExtension.swift */; };
 		BB2A984A2B26A99A00647AF3 /* KMBatchAddWatermarkOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2A98492B26A99A00647AF3 /* KMBatchAddWatermarkOperation.swift */; };
 		BB2A984B2B26A99A00647AF3 /* KMBatchAddWatermarkOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2A98492B26A99A00647AF3 /* KMBatchAddWatermarkOperation.swift */; };
 		BB2A984C2B26A99A00647AF3 /* KMBatchAddWatermarkOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2A98492B26A99A00647AF3 /* KMBatchAddWatermarkOperation.swift */; };
@@ -5270,6 +5273,7 @@
 		BB254D592B2A985A00C37B3B /* KMTTSWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = KMTTSWindowController.xib; sourceTree = "<group>"; };
 		BB276A572B038D1100AB5578 /* KMOCRPDFWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMOCRPDFWindowController.swift; sourceTree = "<group>"; };
 		BB276A5B2B038D3A00AB5578 /* KMOCRPDFWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = KMOCRPDFWindowController.xib; sourceTree = "<group>"; };
+		BB27BF3B2B33E85200A0BAAE /* CPDFView+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CPDFView+KMExtension.swift"; sourceTree = "<group>"; };
 		BB2A98492B26A99A00647AF3 /* KMBatchAddWatermarkOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMBatchAddWatermarkOperation.swift; sourceTree = "<group>"; };
 		BB2A98512B270B3300647AF3 /* KMBatchAddBackgroundOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMBatchAddBackgroundOperation.swift; sourceTree = "<group>"; };
 		BB2C6A7C28F26CEF00478A33 /* PDF_Master-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PDF_Master-Bridging-Header.h"; sourceTree = "<group>"; };
@@ -8721,6 +8725,7 @@
 		BB135C2729B6CD4500FD5965 /* Category */ = {
 			isa = PBXGroup;
 			children = (
+				BB27BF3A2B33E82100A0BAAE /* CPDFKit */,
 				BB3A81AA2AC2A43A006FC66C /* View */,
 				BBB1A3A529F6B66400E54E47 /* NSPanel+KMExtension.swift */,
 				BBB7B48C2A0384E100B58A5A /* NSCollectionViewItem+KMExtension.swift */,
@@ -9076,6 +9081,14 @@
 			path = OCRNew;
 			sourceTree = "<group>";
 		};
+		BB27BF3A2B33E82100A0BAAE /* CPDFKit */ = {
+			isa = PBXGroup;
+			children = (
+				BB27BF3B2B33E85200A0BAAE /* CPDFView+KMExtension.swift */,
+			);
+			path = CPDFKit;
+			sourceTree = "<group>";
+		};
 		BB2C6A7128F2652500478A33 /* Class */ = {
 			isa = PBXGroup;
 			children = (
@@ -13422,6 +13435,7 @@
 				AD199DEF2B23121000D56FEE /* KMPrintPamphletView.swift in Sources */,
 				BB2EDF4C296E63E5003BCF58 /* KMPageEditInsertCustomPageWindowController.swift in Sources */,
 				9F0CB521298656AA00007028 /* KMDesignToken+BorderRadiusBottomLeft.swift in Sources */,
+				BB27BF3C2B33E85200A0BAAE /* CPDFView+KMExtension.swift in Sources */,
 				BBE0BDF329A22EF300440583 /* KMMainViewController+MenuAction.swift in Sources */,
 				BBF170582AE296B90013CE02 /* KMView.swift in Sources */,
 				BB4EEF382976451E003A3537 /* KMRedactContentBaseView.swift in Sources */,
@@ -14067,6 +14081,7 @@
 				ADE86AC92B034CB200414DFA /* KMAddBackgroundView.swift in Sources */,
 				BB88E45929404752002B3655 /* KMPDFConvert.swift in Sources */,
 				9F080B15298CFDB300FC27DA /* KMTextImageButtonVC.swift in Sources */,
+				BB27BF3D2B33E85200A0BAAE /* CPDFView+KMExtension.swift in Sources */,
 				BBB14A60297929BD00936EDB /* KMRedactPageRangeWindowController.swift in Sources */,
 				ADA08A8B29F21A53009B2A7B /* KMPDFViewAnnotationOnceModeStore.swift in Sources */,
 				BB853C872AF8BC12009C20C1 /* KMAddPasswordOperationQueue.swift in Sources */,
@@ -15091,6 +15106,7 @@
 				BB3A669C2B07520800575343 /* KMCustomOutlineView.swift in Sources */,
 				BB49ED08293F461500C82CA2 /* KMConvertCSVWindowController.swift in Sources */,
 				ADE8BC4029F9458700570F89 /* KMRecommondInfo.m in Sources */,
+				BB27BF3E2B33E85200A0BAAE /* CPDFView+KMExtension.swift in Sources */,
 				ADB2D6E8294740F30029D2B3 /* KMPrintPaperSetWindowController.swift in Sources */,
 				AD867FC329DFC39400F00440 /* KMBOTAAnnotationItem.swift in Sources */,
 				9F53D5592AD6908600CCF9D8 /* KMAnnotationLinkViewController.swift in Sources */,

+ 27 - 0
PDF Office/PDF Master/Class/Common/Category/CPDFKit/CPDFView+KMExtension.swift

@@ -0,0 +1,27 @@
+//
+//  CPDFView+KMExtension.swift
+//  PDF Master
+//
+//  Created by tangchao on 2023/12/21.
+//
+
+import Foundation
+
+@objc extension CPDFView {
+    @objc func insertPage(_ pageSize: NSSize, at index: Int, ownerLimit: Bool = true, ownerAlert: Bool = true) -> Bool {
+        if ownerLimit {
+            if let doc = self.document, doc.allowsCopying == false || doc.allowsPrinting == false {
+                if ownerAlert {
+                    Task {
+                        _ = await KMAlertTool.runModel(message: KMLocalizedString("This is a secured document. Editing is not permitted.", nil))
+                    }
+                }
+                return false
+            }
+        }
+        
+        return self.document?.insertPage(pageSize, at: UInt(index)) ?? false
+    }
+
+    
+}

+ 4 - 0
PDF Office/PDF Master/Class/Common/KMCommonDefine.swift

@@ -45,6 +45,8 @@ let kKMMainMenuAccountRefreshItemTag = 16
 
 let KMSelectorCopy = NSSelectorFromString("copy:")
 
+let KMNormalBlankSize = NSMakeSize(595, 842)
+
 // MARK: - 特定的Block
 
 typealias KMBatchActionBlock = (_ controller: NSWindowController, _ files: [KMFileAttribute]) -> Void
@@ -61,6 +63,7 @@ public struct KM<Base> {
 
 // 凡是遵守了 KMProtocol 协议的类型就都获取了 km 属性
 // km 的类型是 KM, KM的关联类型(泛型)就是他自己
+
 public protocol KMProtocol {}
 extension KMProtocol {
     
@@ -74,6 +77,7 @@ extension KMProtocol {
 }
 
 // 所有 NSObject 的子类都默认遵循了 KMProtocol
+
 extension NSObject: KMProtocol {}
 
 

+ 75 - 24
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -5220,7 +5220,24 @@ extension KMLeftSideViewController {
     }
     
     @objc func quickInsert(_ sender: AnyObject?) {
-        KMPrint("KMLeftSideViewController-quickInsert...")
+//        if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
+//            [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
+//            return;
+//        }
+
+        let idx = self.thumbnailTableView.selectedRowIndexes.first ?? NSNotFound
+        if idx == NSNotFound || idx >= self.listView.document.pageCount {
+            return
+        }
+        
+        let result = self.listView.insertPage(KMNormalBlankSize, at: idx+1)
+        if result == false {
+            return
+        }
+        
+        var selectedIndexSet = IndexSet()
+        selectedIndexSet.insert(idx+1)
+        self.insertPages(selectedIndexSet, pageAt: idx)
     }
     
     @objc func insert(_ sender: AnyObject?) {
@@ -5510,31 +5527,9 @@ extension KMLeftSideViewController {
     }
 }
 
-// MARK: - Other
+// MARK: - Undo & Redo
 
 extension KMLeftSideViewController {
-    @objc func goToSelectedOutlineItem(_ sender: AnyObject?) {
-        let outlineItem = self.tocOutlineView.item(atRow: self.tocOutlineView.selectedRow)
-        let outline = self.tocOutlineView
-        if let cnt = outline?.selectedRowIndexes.count, cnt == 1 {
-            if outlineItem is CPDFOutline {
-                let outline = (outlineItem as! CPDFOutline)
-                if let des = outline.destination {
-                    self.listView.go(to: des)
-                } else if let action = outline.action {
-                    self.listView.perform(action)
-                }
-            } else if outlineItem is CPDFBookmark {
-                let bookmark = outlineItem as! CPDFBookmark
-                self.listView.go(toPageIndex: bookmark.pageIndex, animated: true)
-            }
-        }
-    }
-    
-    @objc func goToSelectedFindResults(_ sender: AnyObject?) {
-        KMPrint("KMLeftSideViewController-goToSelectedFindResults...")
-    }
-    
     @objc dynamic func tableView(_ tv: NSTableView, rotateRowsWithIndexes rowIndexes: NSIndexSet) {
         if tv.isEqual(to: self.thumbnailTableView) {
             for idx in rowIndexes {
@@ -5569,5 +5564,61 @@ extension KMLeftSideViewController {
         let pageIndex = min(index, Int((self.listView.document?.pageCount ?? 0))-1)
         self.listView.go(toPageIndex: pageIndex, animated: false)
     }
+    
+    @objc dynamic func insertPages(_ selectedIndexSet: IndexSet, pageAt index: Int) {
+        (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).deletePages(selectedIndexSet, pageAt: index)
+        self.listView.layoutDocumentView()
+//        [pageLabels setArray:[[pdfView document] pageLabels]];
+        self.resetThumbnails()
+        
+        if let pageIndex = selectedIndexSet.first {
+            self.listView.go(toPageIndex: pageIndex, animated: false)
+        }
+    }
+    
+    @objc dynamic func deletePages(_ selectedIndexSet: IndexSet, pageAt index: Int) {
+        (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).insertPages(selectedIndexSet, pageAt: index)
+        
+        for idx in selectedIndexSet {
+            if idx < self.listView.document.pageCount {
+                self.listView.document.removePage(at: UInt(idx))
+            }
+        }
+        
+        self.listView.layoutDocumentView()
+//        [pageLabels setArray:[[pdfView document] pageLabels]];
+        self.resetThumbnails()
+        let pageIndex = min(index, Int(self.listView.document.pageCount)-1)
+        self.listView.go(toPageIndex: pageIndex, animated: false)
+    }
+}
+
+// MARK: - Other
+
+extension KMLeftSideViewController {
+    @objc func goToSelectedOutlineItem(_ sender: AnyObject?) {
+        let outlineItem = self.tocOutlineView.item(atRow: self.tocOutlineView.selectedRow)
+        let outline = self.tocOutlineView
+        if let cnt = outline?.selectedRowIndexes.count, cnt == 1 {
+            if outlineItem is CPDFOutline {
+                let outline = (outlineItem as! CPDFOutline)
+                if let des = outline.destination {
+                    self.listView.go(to: des)
+                } else if let action = outline.action {
+                    self.listView.perform(action)
+                }
+            } else if outlineItem is CPDFBookmark {
+                let bookmark = outlineItem as! CPDFBookmark
+                self.listView.go(toPageIndex: bookmark.pageIndex, animated: true)
+            }
+        }
+    }
+    
+    @objc func goToSelectedFindResults(_ sender: AnyObject?) {
+        KMPrint("KMLeftSideViewController-goToSelectedFindResults...")
+    }
+    
+
 }
 
+