Browse Source

【综合】整理代码

tangchao 6 months ago
parent
commit
af49988366

+ 59 - 1
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -1035,9 +1035,67 @@ class KMPDFEditViewController: KMPDFThumbViewBaseController {
             self.pdfDocument?.insertPageObject(page, at: UInt(insertIndex+index))
             selectIndexs.insert(insertIndex+index)
             if (currentPage?.pageIndex() == page.pageIndex()) {
-//                self._listViewCurrentIndex = insertIndex+index
+                //                self._listViewCurrentIndex = insertIndex+index
             }
         }
+    }
+    
+//    @objc private func dragPages(_ indexs: IndexSet, _ toIndex: Int, dp: NSCollectionView.DropOperation, reversed: Bool = false) {
+//        if (indexs.count <= 0) {
+//            return
+//        }
+//
+//        self.listViewCurrentPageUpdateForDrag(indexs: indexs, toIndex: toIndex)
+//
+//        // 插入位置偏移量
+//        var toIndexOffset: Int = 0
+//        // 需要移动的页面index数组
+//        var newPages: [CPDFPage] = []
+//        var currentPage: CPDFPage?
+//        var originalIndex = self.listViewCurrentIndex
+//        // 从后面往前删除
+//        for index in indexs.reversed() {
+//            let newPage = (self.pdfDocument?.page(at: UInt(index)))?.copy() as? CPDFPage
+//            if (newPage == nil) {
+//                continue
+//            }
+//            newPages.insert(newPage!, at: 0)
+////            self.pdfDocument?.removePage(at: UInt(index))
+//            if (index < toIndex) { /// 删除了插入位置前面的页面,需要改变 toIndex
+//                toIndexOffset += 1
+//            }
+//            if (currentPage == nil) && (originalIndex == index)  {
+//                currentPage = newPage
+//            }
+//        }
+//        var after = false
+//        if (indexs.last! < toIndex && dp == .on) { // 往后拖拽
+//            toIndexOffset -= 1
+//            after = true
+//        }
+//
+//        let insertIndex = max(0, toIndex-toIndexOffset)
+//        var selectIndexs: IndexSet = []
+//        for (index, page) in newPages.enumerated() {
+////            self.pdfDocument?.insertPageObject(page, at: UInt(insertIndex+index))
+//            selectIndexs.insert(insertIndex+index)
+//            if (currentPage?.pageIndex() == page.pageIndex()) {
+////                self._listViewCurrentIndex = insertIndex+index
+//            }
+////            self.pdfDocument?.movePage(at: UInt(index), withPageAt: UInt(insertIndex+index))
+//        }
+//
+//        if after {
+//            var offset = 0
+//            for index in indexs {
+//                self.pdfDocument?.movePage(at: UInt(index-offset), withPageAt: UInt(toIndex))
+//                offset += 1
+//            }
+//        } else {
+//            for index in indexs.reversed() {
+//                self.pdfDocument?.movePage(at: UInt(index), withPageAt: UInt(toIndex))
+//            }
+//        }
         
         // 新增 undo
         self.kmUndoManager?.registerUndo(withTarget: self) { target in

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Tool.m

@@ -135,6 +135,8 @@
             if (CNoteToolMode == self.toolMode)
                 area &= ~CPDFLinkArea;
             
+            NSRect rect = CPDFListViewRectFromCenterAndSize(p, CGSizeMake(80, 100));
+            CPDFSelection *sel = [page selectionForRect:rect];
             if ([self isEditWithCurrentFreeText:self.activeAnnotation] && [[self.activeAnnotation page] isEqual:page] && NSPointInRect(p, [self.activeAnnotation bounds])) {
                 area = CPDFTextFieldArea;
             } else if ((area & CReadingBarArea) == 0) {