Forráskód Böngészése

综合-页面编辑拖拽排序后撤销页面消失(已修复)

tangchao 1 éve
szülő
commit
20b2fdfbed

BIN
PDF Office/PDF Office.xcodeproj/project.xcworkspace/xcuserdata/kdanmobile.xcuserdatad/UserInterfaceState.xcuserstate


+ 9 - 39
PDF Office/PDF Office/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -200,14 +200,6 @@ class KMPDFEditViewController: NSViewController {
             self?.pageRangeView?.stringValue = KMPageRangeTools.newParseSelectedIndexs(selectedIndex: indexs)
         }
         
-        self.thumbnailView.doubleClickItem = {
-            [weak self] (index: Int) in
-            guard let callback = self?.itemClick else {
-                return
-            }
-            callback(1, index)
-        }
-        
         let menu = NSMenu()
         menu.delegate = self
         self.view.menu = menu
@@ -317,24 +309,6 @@ class KMPDFEditViewController: NSViewController {
         self.deletePages(indexs: newIndexs)
     }
     
-    private func dragPagesForDescSort(_ indexs: IndexSet, _ toIndex: Int) {
-        if (indexs.count <= 0) {
-            return
-        }
-
-        /// 数据降序排序
-        let indexArray = indexs.sorted { index1, index2 in
-            return index1 > index2
-        }
-        
-        var newIndexs: IndexSet = []
-        for index in indexArray {
-            newIndexs.insert(index)
-        }
-        
-        self.dragPages(newIndexs, toIndex)
-    }
-    
     @objc private func insertPagesForDescSort(pages: Array<CPDFPage>, indexs: IndexSet) {
 //        var newPages = pages
         
@@ -471,7 +445,6 @@ class KMPDFEditViewController: NSViewController {
         }
     }
     
-    /// MARK: indexs 需要降序排序后
     @objc private func dragPages(_ indexs: IndexSet, _ toIndex: Int) {
         if (indexs.count <= 0) {
             return
@@ -481,9 +454,10 @@ class KMPDFEditViewController: NSViewController {
         var toIndexOffset: Int = 0
         // 需要移动的页面index数组
         var newPages: [CPDFPage] = []
-        for index in indexs {
+        // 从后面往前删除
+        for index in indexs.reversed() {
             let newPage: CPDFPage = self.listView?.document.page(at: UInt(index)).copy() as! CPDFPage
-            newPages.append(newPage)
+            newPages.insert(newPage, at: 0)
             self.listView?.document.removePage(at: UInt(index))
             if (index < toIndex) { /// 删除了插入位置前面的页面,需要改变 toIndex
                 toIndexOffset += 1
@@ -504,7 +478,6 @@ class KMPDFEditViewController: NSViewController {
         self.refreshUI()
     }
     
-    /// indexs 需要降序排序后
     @objc private func dragPages_reversed(_ indexs: IndexSet, _ toIndex: Int, _ pages: [CPDFPage]) {
         if (indexs.count <= 0) {
             return
@@ -530,13 +503,13 @@ class KMPDFEditViewController: NSViewController {
             self.listView?.document.removePage(at: UInt(index))
         }
         // 再插入到对应的位置
-        for index in indexs {
+        for (index,value) in indexs.enumerated() {
             var page: CPDFPage?
             if (index < pages.count) {
                 page = pages[index]
             }
             if (page != nil) {
-                self.listView?.document.insertPageObject(page!, at: UInt(index))
+                self.listView?.document.insertPageObject(page!, at: UInt(value))
             }
             
         }
@@ -570,7 +543,7 @@ class KMPDFEditViewController: NSViewController {
         if (self.itemSize.width > self.defaultItemSize.width) {
             self.itemSize = self.defaultItemSize
         } else if (self.itemSize.width == self.defaultItemSize.width) {
-            self.itemSize = NSSize(width: self.defaultItemSize.width*0.67, height: self.defaultItemSize.height*0.67)
+            self.itemSize = NSSize(width: self.defaultItemSize.width*0.5, height: self.defaultItemSize.height*0.5)
         }
         
         self.thumbnailView.zoomIn()
@@ -1418,7 +1391,7 @@ extension KMPDFEditViewController: KMSelectPopButtonDelegate {
         let pages = KMPageRangeTools.findSelectPage(pageRangeString: self.pageRangeView!.stringValue, pageCount: Int((self.listView?.document.pageCount)!))
         if (pages.isEmpty) {
             let alert = NSAlert()
-            alert.messageText = "Invalid page range or the page number is out of range. Please try again."
+            alert.messageText = NSLocalizedString("Invalid page range or the page number is out of range. Please try again.", comment: "")
             alert.runModal()
             return
         }
@@ -1471,7 +1444,7 @@ extension KMPDFEditViewController: KMPDFThumbnailViewDelegate {
         for page in pages {
             indexs.insert(page)
         }
-        self.dragPagesForDescSort(indexs, toIndex)
+        self.dragPages(indexs, toIndex)
     }
     
     // MARK: thumbanView layout
@@ -1493,15 +1466,12 @@ extension KMPDFEditViewController: KMPDFThumbnailViewDelegate {
     }
     
     func thumbnailView(thumbanView: KMPDFThumbnailView, itemForRepresentedObjectAt indexpath: IndexPath) -> NSCollectionViewItem {
-        
         let cellView: KMPageEditThumbnailItem = thumbanView.collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMPageEditThumbnailItem"), for: indexpath) as! KMPageEditThumbnailItem
         cellView.isShowPageSize = self.thumbnailView.isShowPageSize
         cellView.page = self.thumbnailView.document.page(at: UInt(indexpath.item))
         cellView.setPage(page: self.thumbnailView.document.page(at: UInt(indexpath.item)))
         
-        cellView.doubleClickAction = {
-            [weak self] in
-            
+        cellView.doubleClickAction = { [weak self] in
             guard let callback = self?.itemClick else {
                 return
             }

+ 6 - 1
PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMPDFThumbnailView.swift

@@ -259,7 +259,12 @@ extension KMPDFThumbnailView: NSCollectionViewDelegate {
                 return false
             }
             
-            self.delegate?.thumbnailView?(thumbanView: self, didDragPages: [dragIndex], indexpath: indexPath)
+            var dragPages: [Int] = []
+            for indexpath in dragedIndexPaths {
+                dragPages.append(indexpath.item)
+            }
+            
+            self.delegate?.thumbnailView?(thumbanView: self, didDragPages: dragPages, indexpath: indexPath)
             return true
         } else if ((pboard.availableType(from: [.fileURL])) != nil) {
             //获取url