Selaa lähdekoodia

【BOTA】undo/redo 缩图旋转

lizhe 1 vuosi sitten
vanhempi
commit
01be0cc5f7

+ 2 - 2
PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Annotation/KMAnnotationViewController.swift

@@ -604,7 +604,7 @@ extension KMAnnotationViewController {
         self.tableView.deselectAll(nil)
         self.selectedRowIndexs = []
         
-        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
             self.addAnnotations(annotationItems: tempAnnotations)
         }
     }
@@ -622,7 +622,7 @@ extension KMAnnotationViewController {
         self.listView.setNeedsDisplayForVisiblePages()
         self.reloadData()
         
-        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
             self.deleteAnnotations(annotationItems: annotationItems)
         }
     }

+ 3 - 3
PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Outline/KMOutlineViewController.swift

@@ -787,7 +787,7 @@ extension KMOutlineViewController {
         self.outlineView.reloadData()
         self.outlineView.expandItem(parent)
         
-        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
             self.movePDFOutline(outline: outline, toIndex: NSInteger(indexTemp), atParent: parentTemp)
         }
     }
@@ -831,7 +831,7 @@ extension KMOutlineViewController {
             self.outlineView.expandItem(parent)
         }
 
-        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
             self.addOutline(outlineItems: outlineItems)
         }
     }
@@ -862,7 +862,7 @@ extension KMOutlineViewController {
             }
         }
         
-        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
             self.deleteOutline(outlineItems: outlineItems)
         }
     }

+ 51 - 35
PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMThumbnailViewController.swift

@@ -408,22 +408,25 @@ class KMThumbnailViewController: NSViewController {
         let indexs = self.thumbnailView.collectionView.selectionIndexes
         let indexPaths = self.thumbnailView.collectionView.selectionIndexPaths
         if indexs.count >= 0 {
+            var pageItems: [KMThumbnailPageItem] = []
             let newDocument = self.thumbnailView.document
             for index in indexs {
                 let page : CPDFPage = newDocument.page(at: UInt(index))
-                if page.rotation == 0 {
-                    page.rotation = 90
-                } else if page.rotation == 90 {
-                    page.rotation = 180
-                } else if page.rotation == 180 {
-                    page.rotation = 270
-                } else if page.rotation == 270 {
-                    page.rotation = 0
+                var rotation = page.rotation
+                if rotation == 0 {
+                    rotation = 90
+                } else if rotation == 90 {
+                    rotation = 180
+                } else if rotation == 180 {
+                    rotation = 270
+                } else if rotation == 270 {
+                    rotation = 0
                 }
+                
+                let pageItem = KMThumbnailPageItem(page: page, rotate: rotation, oldRotate: page.rotation)
+                pageItems.append(pageItem)
             }
-            self.listView.layoutDocumentView()
-            self.thumbnailView.reloadData()
-            self.thumbnailView.collectionView.selectItems(at: indexPaths, scrollPosition: .top)
+            self.rotatePageItems(pageItems: pageItems, indexPaths: indexPaths)
         }
     }
     
@@ -431,22 +434,24 @@ class KMThumbnailViewController: NSViewController {
         let indexs = self.thumbnailView.collectionView.selectionIndexes
         let indexPaths = self.thumbnailView.collectionView.selectionIndexPaths
         if indexs.count >= 0 {
+            var pageItems: [KMThumbnailPageItem] = []
             let newDocument = self.thumbnailView.document
             for index in indexs {
                 let page : CPDFPage = newDocument.page(at: UInt(index))
-                if page.rotation == 0 {
-                    page.rotation = 270
-                } else if page.rotation == 90 {
-                    page.rotation = 0
-                } else if page.rotation == 180 {
-                    page.rotation = 90
-                } else if page.rotation == 270 {
-                    page.rotation = 180
+                var rotation = page.rotation
+                if rotation == 0 {
+                    rotation = 270
+                } else if rotation == 90 {
+                    rotation = 0
+                } else if rotation == 180 {
+                    rotation = 90
+                } else if rotation == 270 {
+                    rotation = 180
                 }
+                let pageItem = KMThumbnailPageItem(page: page, rotate: rotation, oldRotate: page.rotation)
+                pageItems.append(pageItem)
             }
-            self.listView.layoutDocumentView()
-            self.thumbnailView.reloadData()
-            self.thumbnailView.collectionView.selectItems(at: indexPaths, scrollPosition: .top)
+            self.rotatePageItems(pageItems: pageItems, indexPaths: indexPaths)
         }
     }
     
@@ -488,7 +493,7 @@ class KMThumbnailViewController: NSViewController {
     @IBAction func deletePageItemAction(menu:NSMenuItem) {
         let indexs = self.thumbnailView.collectionView.selectionIndexes
         if indexs.count > 0 {
-            self.deletePageItemWithIndex(indexs: indexs)
+            self.deletePageItemWithIndexs(indexs: indexs)
         }
     }
     
@@ -537,7 +542,7 @@ class KMThumbnailViewController: NSViewController {
                 self.copysPages.append(page ?? CPDFPage())
             }
             
-            self.deletePageItemWithIndex(indexs: indexs)
+            self.deletePageItemWithIndexs(indexs: indexs)
         }
     }
     
@@ -732,17 +737,28 @@ extension KMThumbnailViewController : NSMenuDelegate,NSMenuItemValidation {
 
 //MARK: undoRedo
 extension KMThumbnailViewController {
-    func rotatePageItemWithIndex(indexs: IndexSet) {
-        var pageItems: [KMThumbnailPageItem] = []
-        for index in indexs {
-            let page: CPDFPage = self.listView.document.page(at: UInt(index))
-            let pageItem = KMThumbnailPageItem(page: page, index: index, oldIndex: index)
-            pageItems.append(pageItem)
+    func rotatePageItems(pageItems: [KMThumbnailPageItem], indexPaths: Set<IndexPath>) {
+        let tempPageItems = pageItems
+        for pageItem in tempPageItems {
+            pageItem.page.rotation = pageItem.rotate
+        }
+        
+        self.listView.layoutDocumentView()
+        self.thumbnailView.reloadData()
+        self.thumbnailView.collectionView.selectItems(at: indexPaths, scrollPosition: .top)
+        
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
+            //替换下标顺序
+            var tempPageItems: [KMThumbnailPageItem] = []
+            for pageItem in pageItems {
+                let item = KMThumbnailPageItem(page: pageItem.page, rotate: pageItem.oldRotate, oldRotate: pageItem.rotate)
+                tempPageItems.append(item)
+            }
+            self.rotatePageItems(pageItems: tempPageItems, indexPaths: indexPaths)
         }
-        self.deletePageItems(pageItems: pageItems)
     }
     
-    func deletePageItemWithIndex(indexs: IndexSet) {
+    func deletePageItemWithIndexs(indexs: IndexSet) {
         var pageItems: [KMThumbnailPageItem] = []
         for index in indexs {
             let page: CPDFPage = self.listView.document.page(at: UInt(index))
@@ -763,7 +779,7 @@ extension KMThumbnailViewController {
         self.thumbnailView.reloadData()
         self.pdfCurrentPageChange()
         
-        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
             self.addPageItems(pageItems: tempPageItems)
         }
     }
@@ -778,7 +794,7 @@ extension KMThumbnailViewController {
         self.thumbnailView.reloadData()
         self.pdfCurrentPageChange()
         
-        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
             self.deletePageItems(pageItems: tempPageItems)
         }
     }
@@ -802,7 +818,7 @@ extension KMThumbnailViewController {
         self.listView?.layoutDocumentView()
         self.thumbnailView.reloadData()
         
-        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
             //替换下标顺序
             var tempPageItems: [KMThumbnailPageItem] = []
             for pageItem in pageItems {