Browse Source

【2025】【PDFView 】注释层级移动问题

dinglingui 3 weeks ago
parent
commit
50a8b655e8

+ 12 - 4
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFListViewExtension/CPDFListView+Event.m

@@ -5889,28 +5889,36 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     NSDictionary *dict = sender.representedObject;
     CPDFPage *page = dict[@"page"];
     CPDFAnnotation *annotation = dict[@"annotation"];
-    [self moveAnnotationOnPage:page annotation:annotation newIndex:[page.annotations indexOfObject:annotation] + 1];
+    
+    [self bringAnnotationForward:annotation page:page];
+    [self setNeedsDisplayAnnotationViewForPage:page];
 }
 
 - (IBAction)menuItemClick_SendBackward:(NSMenuItem *)sender {
     NSDictionary *dict = sender.representedObject;
     CPDFPage *page = dict[@"page"];
     CPDFAnnotation *annotation = dict[@"annotation"];
-    [self moveAnnotationOnPage:page annotation:annotation newIndex:[page.annotations indexOfObject:annotation] - 1];
+    
+    [self sendAnnotationBackward:annotation page:page];
+    [self setNeedsDisplayAnnotationViewForPage:page];
 }
 
 - (IBAction)menuItemClick_BringFront:(NSMenuItem *)sender {
     NSDictionary *dict = sender.representedObject;
     CPDFPage *page = dict[@"page"];
     CPDFAnnotation *annotation = dict[@"annotation"];
-    [self moveAnnotationOnPage:page annotation:annotation newIndex:page.annotations.count -1];
+    
+    [self bringAnnotationFront:annotation page:page];
+    [self setNeedsDisplayAnnotationViewForPage:page];
 }
 
 - (IBAction)menuItemClick_SendBack:(NSMenuItem *)sender {
     NSDictionary *dict = sender.representedObject;
     CPDFPage *page = dict[@"page"];
     CPDFAnnotation *annotation = dict[@"annotation"];
-    [self moveAnnotationOnPage:page annotation:annotation newIndex:0];
+    
+    [self sendAnnotationBack:annotation page:page];
+    [self setNeedsDisplayAnnotationViewForPage:page];
 }
 
 - (IBAction)menuItemClick_EditNote:(id)sender {

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

@@ -687,7 +687,6 @@
     for (NSUInteger i = 0; i < newAddArray.count; i++) {
         [aPage addAnnotation:newAddArray[i]];
     }
-    [self setNeedsDisplay:YES];
 }
 
 - (void)showHUDHint:(CPDFAnnotation *)newActiveAnnotation {

+ 5 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.h

@@ -320,6 +320,11 @@ enum {
 - (IBAction)menuItemClick_BringFront:(NSMenuItem *)sender;
 - (IBAction)menuItemClick_SendBack:(NSMenuItem *)sender;
 
+- (void)bringAnnotationForward:(CPDFAnnotation *)annotation page:(CPDFPage*)page;
+- (void)sendAnnotationBackward:(CPDFAnnotation *)annotation page:(CPDFPage*)page;
+- (void)bringAnnotationFront:(CPDFAnnotation *)annotation page:(CPDFPage*)page;
+- (void)sendAnnotationBack:(CPDFAnnotation *)annotation page:(CPDFPage*)page;
+
 - (void)editAnnotation:(CPDFAnnotation *)annotation;
 - (void)redactAddAnnotationPages:(NSMutableArray *)pages redactAnnotation:(CPDFRedactAnnotation *)redactAnnotation;
 - (void)exprotSelection:(CPDFSelection *)selection type:(NSInteger)type; //0 png //1 jpg, 2 pdf

+ 16 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.m

@@ -805,6 +805,22 @@ void CPDFListViewOCDrawLineHandles(CGContextRef context, CGRect rect, CGFloat ra
 }
 
 #pragma mark - Public
+- (void)bringAnnotationForward:(CPDFAnnotation *)annotation page:(CPDFPage*)page {
+    [self moveAnnotationOnPage:page annotation:annotation newIndex:[page.annotations indexOfObject:annotation] + 1];
+}
+
+- (void)sendAnnotationBackward:(CPDFAnnotation *)annotation page:(CPDFPage*)page {
+    [self moveAnnotationOnPage:page annotation:annotation newIndex:[page.annotations indexOfObject:annotation] - 1];
+}
+
+- (void)bringAnnotationFront:(CPDFAnnotation *)annotation page:(CPDFPage*)page {
+    [self moveAnnotationOnPage:page annotation:annotation newIndex:page.annotations.count -1];
+}
+
+- (void)sendAnnotationBack:(CPDFAnnotation *)annotation page:(CPDFPage*)page {
+    [self moveAnnotationOnPage:page annotation:annotation newIndex:0];
+}
+
 - (void)redactAddAnnotationPages:(NSMutableArray *)pages redactAnnotation:(CPDFRedactAnnotation *)redactAnnotation {
     if (pages.count == 0) {
         return;

+ 33 - 6
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -7194,16 +7194,43 @@ extension KMMainViewController: ComponentGroupDelegate {
             UserDefaults.standard.setValue(true, forKey: settingsShowQuickActionBarKey)
             SettingsManager.sharedInstance.showQuickActionBar = true
             reloadPopUIWindow()
-        } else if(menuItemProperty?.identifier == PDFViewMenuIdentifier_Normal_LinkReade) {
-        
         } else if(menuItemProperty?.identifier == PDFViewMenuIdentifier_Normal_SortFirstAnnotation) {
-            listView.menuItemClick_BringFront(nil)
+            let activeAnnotations = listView.activeAnnotations
+            for i in 0 ..< (activeAnnotations?.count ?? 0){
+                let object = activeAnnotations?[i]
+                if let an = object as? CPDFAnnotation {
+                    listView.bringAnnotationFront(an, page: an.page)
+                }
+            }
+            listView.setNeedsDisplayAnnotationViewForVisiblePages()
         } else if(menuItemProperty?.identifier == PDFViewMenuIdentifier_Normal_SortTopAnnotation) {
-            listView.menuItemClick_BringForward(nil)
+            let activeAnnotations = listView.activeAnnotations
+            for i in 0 ..< (activeAnnotations?.count ?? 0){
+                let object = activeAnnotations?[i]
+                if let an = object as? CPDFAnnotation {
+                    listView.bringAnnotationForward(an, page: an.page)
+                }
+            }
+            listView.setNeedsDisplayAnnotationViewForVisiblePages()
         } else if(menuItemProperty?.identifier == PDFViewMenuIdentifier_Normal_SortBottomAnnotation) {
-            listView.menuItemClick_SendBackward(nil)
+            let activeAnnotations = listView.activeAnnotations
+            for i in 0 ..< (activeAnnotations?.count ?? 0){
+                let object = activeAnnotations?[i]
+                if let an = object as? CPDFAnnotation {
+                    listView.sendAnnotationBackward(an, page: an.page)
+                }
+            }
+
+            listView.setNeedsDisplayAnnotationViewForVisiblePages()
         } else if(menuItemProperty?.identifier == PDFViewMenuIdentifier_Normal_SortLastAnnotation) {
-            listView.menuItemClick_SendBack(nil)
+            let activeAnnotations = listView.activeAnnotations
+            for i in 0 ..< (activeAnnotations?.count ?? 0){
+                let object = activeAnnotations?[i]
+                if let an = object as? CPDFAnnotation {
+                    listView.sendAnnotationBack(an, page: an.page)
+                }
+            }
+            listView.setNeedsDisplayAnnotationViewForVisiblePages()
         } else if(menuItemProperty?.identifier == PDFViewMenuIdentifier_Normal_Content) {
             if let activeAnnotation = listView.activeAnnotation {
                 listView.edit(activeAnnotation)

+ 20 - 4
PDF Office/PDF Master/KMClass/KMPDFViewController/KMPDFMenuConfig.swift

@@ -763,15 +763,31 @@ let BOTAMenuIdentifier_Annotation_DeleteMuteRep = "BOTAMenuIdentifier_Annotation
                                                                                        identifier: PDFViewMenuIdentifier_Normal_SortAnnotation)
        
         var subMenuItemArr: [ComponentMenuitemProperty] = []
-        let subItem0Property: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("Bring to Front"),identifier: PDFViewMenuIdentifier_Normal_SortFirstAnnotation,
+        let activeAnnotations = listView?.activeAnnotations as? [CPDFAnnotation]
+        let firstAnnotation = activeAnnotations?.first
+        
+        let pageAnnotationArray = firstAnnotation?.page.annotations
+        
+        var isFirstDisabled = false
+        if(firstAnnotation == pageAnnotationArray?.last) {
+            isFirstDisabled = true
+        }
+
+        let subItem0Property: ComponentMenuitemProperty = ComponentMenuitemProperty(isDisabled:isFirstDisabled,text: KMLocalizedString("Bring to Front"),identifier: PDFViewMenuIdentifier_Normal_SortFirstAnnotation,
                                                                                     representedObject: listView)
-        let subItem1Property: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("Bring Forward"),identifier: PDFViewMenuIdentifier_Normal_SortTopAnnotation,
+        let subItem1Property: ComponentMenuitemProperty = ComponentMenuitemProperty(isDisabled:isFirstDisabled,text: KMLocalizedString("Bring Forward"),identifier: PDFViewMenuIdentifier_Normal_SortTopAnnotation,
                                                                                     representedObject: listView)
+        
+        var isLastDisabled = false
+        if(firstAnnotation == pageAnnotationArray?.first) {
+            isLastDisabled = true
+        }
+        
         let subItem2Property: ComponentMenuitemProperty = ComponentMenuitemProperty(
-                                                                                    text: KMLocalizedString("Send Backward"),identifier: PDFViewMenuIdentifier_Normal_SortBottomAnnotation,
+            isDisabled:isLastDisabled,text: KMLocalizedString("Send Backward"),identifier: PDFViewMenuIdentifier_Normal_SortBottomAnnotation,
                                                                                     representedObject: listView)
         
-        let subItem3Property: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("Send to Back"),identifier: PDFViewMenuIdentifier_Normal_SortLastAnnotation,
+        let subItem3Property: ComponentMenuitemProperty = ComponentMenuitemProperty(isDisabled:isLastDisabled,text: KMLocalizedString("Send to Back"),identifier: PDFViewMenuIdentifier_Normal_SortLastAnnotation,
                                                                                     representedObject: listView)