Jelajahi Sumber

【PDF阅读页】右键菜单的顺序 和 分组 错乱了?

liujiajie 6 bulan lalu
induk
melakukan
8c32b9a961

+ 38 - 34
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -642,7 +642,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
         return menu;
     } else {
        
-        if (annotationSel) {
+        if (annotationSel && self.activeAnnotations.count > 0) {
             NSDictionary *dictPresentObject = @{@"page":page,@"annotation":annotationSel};
             bringForwardItem.representedObject = dictPresentObject;
             bringFrontItem.representedObject = dictPresentObject;
@@ -689,6 +689,36 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             if([self.activeAnnotation isKindOfClass:[CPDFMarkupAnnotation class]] ||
                [self.activeAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
                 [menu insertItem:editNoteItem atIndex:0];
+                __block typeof(self) blockSelf = self;
+                if([self.activeAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
+//                    [menu insertItem:[NSMenuItem separatorItem] atIndex:0];
+                    NSArray *colors = @[[NSColor colorWithRed:255.0/255.0 green:254.0/255.0 blue:84.0/255.0 alpha:1.0],
+                                        [NSColor colorWithRed:234.0/255.0 green:51.0/255.0 blue:35.0/255.0 alpha:1.0],
+                                        [NSColor colorWithRed:239.0/255.0 green:134.0/255.0 blue:51.0/255.0 alpha:1.0],
+                                        [NSColor colorWithRed:117.0/255.0 green:250.0/255.0 blue:76.0/255.0 alpha:1.0]];
+                    if([self.pdfListViewDelegate respondsToSelector:@selector(PDFListViewEventMarkupColorWithAnnotation:)]) {
+                        colors = [self.pdfListViewDelegate PDFListViewEventMarkupColorWithAnnotation:self.activeAnnotation];
+                    }
+                    
+                    CPDFListViewColorMenuItemView *itemView = [[CPDFListViewColorMenuItemView alloc] initWithTitle:nil
+                                                                                                        colorArray:colors
+                                                                                                   needsColorWheel:NO
+                                                                                                   completeHandler:^(NSColor *color) {
+                        CGFloat red,green,blue,alpha;
+                        if (color) {
+                            [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
+                        }
+                        CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc]initWithPDFAnnotations:blockSelf.activeAnnotations];;
+                        annotationModel.color = color;
+                        annotationModel.opacity = alpha;
+                        [blockSelf setNeedsDisplayAnnotation:blockSelf.activeAnnotation];
+                        [menu cancelTracking];
+                    }];
+                    
+                    NSMenuItem * colorItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Highlight", @"Menu item title") action:nil keyEquivalent:@""];
+                    colorItem.view = itemView;
+                    [menu insertItem:colorItem atIndex:0];
+                }
             } else if ([self.activeAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
                 [menu insertItem:editNoteItem atIndex:0];
                 if ([self.activeAnnotation isKindOfClass:[CPDFListStampAnnotation class]]) {
@@ -758,45 +788,19 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                 }
                 [menu insertItem:cutItem atIndex:0];
             }
+            if ([self.activeAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
+                [menu insertItem:pasteItem atIndex:0];
+            }
             [menu insertItem:copyItem atIndex:0];
-            __block typeof(self) blockSelf = self;
             
-            if([self.activeAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
-                [menu insertItem:[NSMenuItem separatorItem] atIndex:0];
-                NSArray *colors = @[[NSColor colorWithRed:255.0/255.0 green:254.0/255.0 blue:84.0/255.0 alpha:1.0],
-                                    [NSColor colorWithRed:234.0/255.0 green:51.0/255.0 blue:35.0/255.0 alpha:1.0],
-                                    [NSColor colorWithRed:239.0/255.0 green:134.0/255.0 blue:51.0/255.0 alpha:1.0],
-                                    [NSColor colorWithRed:117.0/255.0 green:250.0/255.0 blue:76.0/255.0 alpha:1.0]];
-                if([self.pdfListViewDelegate respondsToSelector:@selector(PDFListViewEventMarkupColorWithAnnotation:)]) {
-                    colors = [self.pdfListViewDelegate PDFListViewEventMarkupColorWithAnnotation:self.activeAnnotation];
-                }
-                
-                CPDFListViewColorMenuItemView *itemView = [[CPDFListViewColorMenuItemView alloc] initWithTitle:nil
-                                                                                                    colorArray:colors
-                                                                                               needsColorWheel:NO
-                                                                                               completeHandler:^(NSColor *color) {
-                    CGFloat red,green,blue,alpha;
-                    if (color) {
-                        [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
-                    }
-                    CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc]initWithPDFAnnotations:blockSelf.activeAnnotations];;
-                    annotationModel.color = color;
-                    annotationModel.opacity = alpha;
-                    [blockSelf setNeedsDisplayAnnotation:blockSelf.activeAnnotation];
-                    [menu cancelTracking];
-                }];
-                
-                NSMenuItem * colorItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Highlight", @"Menu item title") action:nil keyEquivalent:@""];
-                colorItem.view = itemView;
-                [menu insertItem:colorItem atIndex:0];
-            }
         }
         
         if (self.currentSelection) {
             if(CPDFSelectionTypeImage == [self.currentSelection selectionType]) {
-                
-                NSMenuItem * exportImageItem = [self creatExportItem];
-                [menu insertItem:exportImageItem atIndex:0];
+                if (self.activeAnnotations.count < 1) {
+                    NSMenuItem * exportImageItem = [self creatExportItem];
+                    [menu insertItem:exportImageItem atIndex:0];
+                }
                 //                [menu insertItem:[NSMenuItem separatorItem] atIndex:0];
             }
             if ([[NSPasteboard generalPasteboard] canReadObjectForClasses:[NSArray arrayWithObjects:[CPDFAnnotation class], [NSString class],[NSImage class], nil] options:[NSDictionary dictionary]]) {

+ 14 - 10
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+UI.swift

@@ -1707,7 +1707,7 @@ extension KMMainViewController: CPDFViewDelegate,CPDFListViewDelegate {
             currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 3)
             currentMenu.insertItem(self.addReadModelStype(), at: currentMenu.items.count - 3)
         }
-        if listView.currentSelection != nil{
+        if listView.currentSelection != nil && listView.activeAnnotations.count < 1{
             if listView.currentSelection.selectionType() == .text {
                 currentMenu.insertItem(NSMenuItem.separator(), at: 3)
                 currentMenu.insertItem(self.setSearchBaiduStype(), at: 3)
@@ -1716,9 +1716,9 @@ extension KMMainViewController: CPDFViewDelegate,CPDFListViewDelegate {
                 currentMenu.insertItem(NSMenuItem.separator(), at: 3)
                 currentMenu.insertItem(self.addOutlineStype(), at: 3)
                 currentMenu.insertItem(NSMenuItem.separator(), at: 3)
-                if listView.activeAnnotation == nil{
+//                if listView.activeAnnotation == nil{
                     currentMenu.insertItem(self.setAnnotationToolStype(), at: 3)
-                }
+//                }
                 currentMenu.insertItem(self.setTTSStype(), at: 3)
                 currentMenu.insertItem(NSMenuItem.separator(), at: 3)
                 currentMenu.insertItem(self.setShareStype(), at: 3)
@@ -1730,14 +1730,18 @@ extension KMMainViewController: CPDFViewDelegate,CPDFListViewDelegate {
 //
 //                    currentMenu.insertItem(self.setCutStype(), at: 1)
 //                }
-                if listView.activeAnnotations.count > 0 {
-                    currentMenu.insertItem(self.setDeleteStype(), at: 3)
+//                if listView.activeAnnotations.count > 0 {
+//                    currentMenu.insertItem(self.setDeleteStype(), at: 3)
                     currentMenu.insertItem(NSMenuItem.separator(), at: 6)
-                    currentMenu.insertItem(self.setEditNoteStype(), at: 6)
-                    currentMenu.insertItem(self.setRotateStype(), at: 6)
-                    currentMenu.insertItem(self.setLinesStype(), at: 6)
-                    currentMenu.insertItem(self.setColorsStype(), at: 6)
-                }
+                    currentMenu.insertItem(self.addOutlineStype(), at: 6)
+                    currentMenu.insertItem(NSMenuItem.separator(), at: 6)
+                    currentMenu.insertItem(self.setAnnotationToolStype(), at: 6)
+                   
+//                    currentMenu.insertItem(self.setEditNoteStype(), at: 6)
+//                    currentMenu.insertItem(self.setRotateStype(), at: 6)
+//                    currentMenu.insertItem(self.setLinesStype(), at: 6)
+//                    currentMenu.insertItem(self.setColorsStype(), at: 6)
+//                }
             }
             if listView.currentSelection.selectionType() == .text {
                 currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count)