Browse Source

【综合】BOTA右键菜单调式

tangchao 1 year ago
parent
commit
62bb595988

+ 32 - 0
PDF Office/PDF Master.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -468,5 +468,37 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "69166CF2-DBF6-4024-9BA7-3BA613341AFC"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFTextAnnotation+PDFListView.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "21"
+            endingLineNumber = "21"
+            landmarkName = "isMovable()"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "307D2630-F7B3-4D24-957B-3F640EAA2EA8"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotation+PDFListView.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "900"
+            endingLineNumber = "900"
+            landmarkName = "hasBorder()"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotation+PDFListView.swift

@@ -892,7 +892,7 @@ import Foundation
     }
     
     @objc func isEditable() -> Bool {
-        return self.page == nil
+        return self.page == nil || self.page.isEditable()
     }
     
     @objc func hasBorder() -> Bool {

+ 4 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFPageExtensions/CPDFPage+PDFListView.swift

@@ -33,6 +33,10 @@ import Foundation
         
         return image.tiffRepresentation
     }
+    
+    @objc func isEditable() -> Bool {
+        return true
+    }
 }
 
 // MARK: - KMExtension

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Extension.h

@@ -56,6 +56,8 @@
 
 - (NSArray *)displayedPages;
 
+- (void)scrollAnnotationToVisible:(CPDFAnnotation *)annotation;
+
 @end
 
 extern NSRect KMConstrainRect(NSRect rect, NSRect boundary);

+ 4 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Extension.m

@@ -599,6 +599,10 @@ CGFloat DEFAULT_SNAPSHOT_HEIGHT = 200.0;
     return range;
 }
 
+- (void)scrollAnnotationToVisible:(CPDFAnnotation *)annotation {
+    [self goToRect:[annotation bounds] onPage:[annotation page]];
+}
+
 @end
 
 NSRect KMConstrainRect(NSRect rect, NSRect boundary) {

+ 100 - 131
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Action.swift

@@ -95,14 +95,15 @@ extension KMLeftSideViewController: NSMenuDelegate {
                 item = menu.addItem(title: displayStr, action: #selector(displayPageSize), target: self)
                 item?.representedObject = IndexSet(integer: row)
                 
-                item = menu.addItem(title: KMLocalizedString("Share", "Menu item title"), action: nil, target: self)
-
-//                NSString * tName = [self fileNameWithSelectedPages:leftSideController.thumbnailTableView.selectedRowIndexes];
-//                if (tName.length > 50) {
-//                   tName = [tName substringWithRange:NSMakeRange(0, 50)];
-//                }
-                let tName = self.listView.document.documentURL.lastPathComponent
-                item?.submenu = NSSharingServicePicker.menu(forSharingItems: [self.listView.document.documentURL], subjectContext: tName, withTarget: self, selector: #selector(sharePage), serviceDelegate: nil)
+                if let doct = self.listView?.document {
+                    item = menu.addItem(title: KMLocalizedString("Share", "Menu item title"), action: nil, target: self)
+                    
+                    var tName = self.fileNameWithSelectedPages(self.thumbnailTableView.selectedRowIndexes)
+                    if (tName.count > 50) {
+                        tName = tName.substring(to: 50)
+                    }
+                    item?.submenu = NSSharingServicePicker.menu(forSharingItems: [doct.documentURL as Any], subjectContext: tName, withTarget: self, selector: #selector(sharePage), serviceDelegate: nil)
+                }
             }
         } else if menu.isEqual(to: self.findTableView.menu) {
             var rowIndexes = self.findTableView.selectedRowIndexes
@@ -214,136 +215,104 @@ extension KMLeftSideViewController: NSMenuDelegate {
             if (row != -1) {
                 if rowIndexes.contains(row) == false {
                     rowIndexes = IndexSet(integer: row)
-                    items = self.noteOutlineView.itemsAtRowIndexes(rowIndexes) as NSArray
-                    
-//                 PDFAnnotation *foldNote = (PDFAnnotation *)notes[row];
-                    let foldNote = self.allAnnotations[row]
-                    var isFold = true
-                    if self.allFoldNotes.contains(foldNote) {
-                        isFold = false
-                    }
-                    item = menu.addItem(title: KMLocalizedString("Expand", nil), action: #selector(unfoldNoteAction), target: self)
-                    if (isFold) {
-                        item?.state = .off
-                    } else {
-                        item?.state = .on
-                    }
-                    item?.representedObject = items
-                    item = menu.addItem(title: KMLocalizedString("Collapse", nil), action: #selector(foldNoteAction), target: self)
-                    if (isFold) {
-                        item?.state = .on
-                    } else {
-                        item?.state = .off
+                }
+                items = self.noteOutlineView.itemsAtRowIndexes(rowIndexes) as NSArray
+                
+                //                 PDFAnnotation *foldNote = (PDFAnnotation *)notes[row];
+                let foldNote = self.allAnnotations[row]
+                var isFold = true
+                if self.allFoldNotes.contains(foldNote) {
+                    isFold = false
+                }
+                item = menu.addItem(title: KMLocalizedString("Expand", nil), action: #selector(unfoldNoteAction), target: self)
+                if (isFold) {
+                    item?.state = .off
+                } else {
+                    item?.state = .on
+                }
+                item?.representedObject = items
+                item = menu.addItem(title: KMLocalizedString("Collapse", nil), action: #selector(foldNoteAction), target: self)
+                if (isFold) {
+                    item?.state = .on
+                } else {
+                    item?.state = .off
+                }
+                item?.representedObject = items
+                
+                menu.addItem(.separator())
+                if self.listView.hideNotes == false {
+                    //                                if ([pdfView hideNotes] == NO && [items count] == 1) {
+                    let annotation = self.noteItems(items!).lastObject as? CPDFAnnotation
+                    if let data = annotation?.isEditable(), data {
+                        if annotation?.type == nil {
+                            if annotation!.isNote() {
+                                // [NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis]
+                                item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editNoteTextFromTable), target: self)
+                                item?.representedObject = annotation
+                            }
+                        } else if let data = self.noteOutlineView.tableColumn(withIdentifier: NSUserInterfaceItemIdentifier("note"))?.isHidden, data  {
+//                            [NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis]
+                            item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editThisAnnotation), target: self)
+                            item?.representedObject = annotation
+                        } else {
+                            item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editNoteFromTable), target: self)
+                            item?.representedObject = annotation
+                            item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editThisAnnotation), target: self)
+                            item?.representedObject = annotation
+                            item?.keyEquivalentModifierMask = [.option]
+                            item?.isAlternate = true
+                        }
                     }
-                    item?.representedObject = items
+                }
+
+                if menu.numberOfItems > 0 {
+                    item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                    
+                    let subMenu = NSMenu()
+                    item?.submenu = subMenu
+                    item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                    item?.tag = 0
+                    item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                    item?.tag = 1
+                    item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                    item?.tag = 2
+                    item = subMenu.addItem(title: NSLocalizedString("Notes as Texts", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                    item?.tag = 3
+                    item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                    item?.tag = 4
+                    item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                    item?.tag = 5
+                    item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                    item?.tag = 6
                     
-                    //UX改版删除
-                    //            if ([self outlineView:rightSideController.noteOutlineView canCopyItems:items]) {
-                    //                item = [menu addItemWithTitle:NSLocalizedString(@"Copy", @"Menu item title") action:@selector(copyNotes:) target:self];
-                    //                [item setRepresentedObject:items];
-                    //            }
                     menu.addItem(.separator())
-                    if self.listView.hideNotes == false {
-                        //                                if ([pdfView hideNotes] == NO && [items count] == 1) {
-                        //                                    PDFAnnotation *annotation = [[self noteItems:items] lastObject];
-                        //                                    if ([annotation isEditable]) {
-                        //                                        if ([(PDFAnnotation *)[items lastObject] type] == nil) {
-                        //                                            if ([[(SKNoteText *)[items lastObject] note] isNote]) {
-                        //                                                item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editNoteTextFromTable:) target:self];
-                        //                                                [item setRepresentedObject:annotation];
-                        //                                            }
-                        //                                        } else if ([[rightSideController.noteOutlineView tableColumnWithIdentifier:NOTE_COLUMNID] isHidden]) {
-                        //                                            item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editThisAnnotation:) target:pdfView];
-                        //                                            [item setRepresentedObject:annotation];
-                        //                                        } else {
-                        //                                            item = [menu addItemWithTitle:NSLocalizedString(@"Edit", @"Menu item title") action:@selector(editNoteFromTable:) target:self];
-                        //                                            [item setRepresentedObject:annotation];
-                        //                                            item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editThisAnnotation:) target:pdfView];
-                        //                                            [item setRepresentedObject:annotation];
-                        //                                            [item setKeyEquivalentModifierMask:NSEventModifierFlagOption];
-                        //                                            [item setAlternate:YES];
-                        //                                        }
-                        //                                    }
-                        //                if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
-                        //                    if ([pdfView activeAnnotation] == annotation) {
-                        //                        item = [menu addItemWithTitle:NSLocalizedString(@"Deselect", @"Menu item title") action:@selector(deselectNote:) target:self];
-                        //                        [item setRepresentedObject:annotation];
-                        //                    } else {
-                        //                        item = [menu addItemWithTitle:NSLocalizedString(@"Select", @"Menu item title") action:@selector(selectNote:) target:self];
-                        //                        [item setRepresentedObject:annotation];
-                        //                    }
-                        //                    item = [menu addItemWithTitle:NSLocalizedString(@"Show", @"Menu item title") action:@selector(revealNote:) target:self];
-                        //                    [item setRepresentedObject:annotation];
-                        //                }
-                        //                                }
-                        //            if ([menu numberOfItems] > 0)
-                        //                [menu addItem:[NSMenuItem separatorItem]];
-                        //            item = [menu addItemWithTitle:[items count] == 1 ? NSLocalizedString(@"Auto Size Row", @"Menu item title") : NSLocalizedString(@"Auto Size Rows", @"Menu item title") action:@selector(autoSizeNoteRows:) target:self];
-                        //            [item setRepresentedObject:items];
-                        //            item = [menu addItemWithTitle:[items count] == 1 ? NSLocalizedString(@"Undo Auto Size Row", @"Menu item title") : NSLocalizedString(@"Undo Auto Size Rows", @"Menu item title") action:@selector(resetHeightOfNoteRows:) target:self];
-                        //            [item setRepresentedObject:items];
-                        //            [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
-                        //            [item setAlternate:YES];
-                        //            [menu addItemWithTitle:NSLocalizedString(@"Auto Size All", @"Menu item title") action:@selector(autoSizeNoteRows:) target:self];
-                        //            item = [menu addItemWithTitle:NSLocalizedString(@"Undo Auto Size All", @"Menu item title") action:@selector(resetHeightOfNoteRows:) target:self];
-                        //            [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
-                        //            [item setAlternate:YES];
-                        //            [menu addItemWithTitle:NSLocalizedString(@"Automatically Resize", @"Menu item title") action:@selector(toggleAutoResizeNoteRows:) target:self];
-                        
-                        if menu.numberOfItems > 0 {
-                            item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-                            
-                            let subMenu = NSMenu()
-                            item?.submenu = subMenu
-                            item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-                            item?.tag = 0
-                            item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-                            item?.tag = 1
-                            item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-                            item?.tag = 2
-                            item = subMenu.addItem(title: NSLocalizedString("Notes as Texts", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-                            item?.tag = 3
-                            item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-                            item?.tag = 4
-                            item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-                            item?.tag = 5
-                            item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-                            item?.tag = 6
-                            
-                            menu.addItem(.separator())
-                            if self.outlineView(self.noteOutlineView, canDeleteItems: items as! [Any]) {
-                            item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteNotes), target: self)
-                                item?.representedObject = items
-                            }
-                            item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
-                        }
+                    if self.outlineView(self.noteOutlineView, canDeleteItems: items as! [Any]) {
+                        item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteNotes), target: self)
+                        item?.representedObject = items
                     }
+                    item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
                 }
+            } else {
+                let subMenu = NSMenu()
+                item?.submenu = subMenu
+                item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                item?.tag = 0
+                item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                item?.tag = 1
+                item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                item?.tag = 2
+                item = subMenu.addItem(title: NSLocalizedString("Notes as Texts", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                item?.tag = 3
+                item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                item?.tag = 4
+                item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                item?.tag = 5
+                item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
+                item?.tag = 6
+                
+                item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
             }
         }
-//            else {
-//                item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Export Annotations…", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
-//
-//                NSMenu *subMenu = [NSMenu menu];
-//                item.submenu = subMenu;
-//                item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
-//                item.tag = 0;
-//                item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Bundle", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
-//                item.tag = 1;
-//                item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Reader Pro Edition Notes", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
-//                item.tag = 2;
-//                item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as Text", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
-//                item.tag = 3;
-//                item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
-//                item.tag = 4;
-//                item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTFD", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
-//                item.tag = 5;
-//                item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as FDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
-//                item.tag = 6;
-//
-//                item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Remove All Annotations", @"MainMenu", @"Menu item title") action:@selector(removeAllAnnotations:) target:self];
-//            }
-//        }
     }
 }
 

+ 21 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift

@@ -144,4 +144,25 @@ extension KMLeftSideViewController {
     @objc func removeAllAnnotations(_ sender: AnyObject?) {
         self.leftSideEmptyAnnotationClick_DeleteAnnotation(nil)
     }
+    
+    @objc func editNoteTextFromTable(_ sender: NSMenuItem) {
+//        PDFAnnotation *annotation = [sender representedObject];
+        guard let annotation = sender.representedObject as? CPDFAnnotation else {
+            return
+        }
+        self.listView.scrollAnnotationToVisible(annotation)
+//        self.listView.activeAnnotation = annotation
+//        [self showNote:annotation];
+//        SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation];
+//        [[noteController window] makeFirstResponder:[noteController textView]];
+//        [[noteController textView] selectAll:nil];
+    }
+    
+    @objc func editThisAnnotation(_ sender: AnyObject?) {
+        KMPrint("editThisAnnotation ...")
+    }
+    
+    @objc func editNoteFromTable(_ sender: AnyObject?) {
+        KMPrint("editNoteFromTable ...")
+    }
 }