Browse Source

【综合】BOTA 注释列表-删除所有注释后,右击缺少“导出注释”选项(已修复)

tangchao 11 months ago
parent
commit
7cf996449c

+ 20 - 201
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Action.swift

@@ -53,45 +53,7 @@ extension KMLeftSideViewController {
                 NSMenu.popUpContextMenu(menu, with: data, for: button)
             }
         } else if (tag == 302) {
-            let menu = NSMenu()
-            let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(toc_expandAllComments), target: self)
-            expandAllCommentsItem?.representedObject = self.tocOutlineView
-
-            let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(toc_foldAllComments), target: self)
-            expandAllCommentsItem?.representedObject = self.tocOutlineView
-            let item = self.outlineRoot()
-
-            var num = 0
-            for i in 0 ..< Int(item?.numberOfChildren ?? 0) {
-                let outline = item?.child(at: UInt(i))
-                if self.tocOutlineView.isItemExpanded(outline) {
-                    num += 1
-                }
-            }
-
-            if let cnt = item?.numberOfChildren, cnt > 0 && num == 0 {
-                self.tocType = .fold
-            } else if let cnt = item?.numberOfChildren, cnt > 0 && num == cnt {
-                self.tocType = .unfold
-            } else {
-                self.tocType = .none
-            }
-
-            if (self.tocType == .unfold) {
-                expandAllCommentsItem?.state = .on
-                foldAllCommentsItem?.state = .off
-            } else if (self.tocType == .fold) {
-                expandAllCommentsItem?.state = .off
-                foldAllCommentsItem?.state = .on
-            } else {
-                expandAllCommentsItem?.state = .off
-                foldAllCommentsItem?.state = .off
-            }
-            let removeEntryItem = menu.addItem(title: KMLocalizedString("Remove All Outlines", nil), action: #selector(leftSideEmptyAnnotationClick_DeleteOutline), target: self)
-            removeEntryItem?.representedObject = self.tocOutlineView
-            if let data = NSApp.currentEvent {
-                NSMenu.popUpContextMenu(menu, with: data, for: button)
-            }
+            self.outlineMoreMenu(button)
         } else if (tag == 304) {
             let menu = NSMenu()
             let object = KMPopupMenuObject()
@@ -463,113 +425,7 @@ extension KMLeftSideViewController: NSMenuDelegate {
                 item?.representedObject = controller
             }
         } else if menu.isEqual(to: self.noteOutlineView.menu) {
-            var items: NSArray?
-            var rowIndexes = self.noteOutlineView.selectedRowIndexes
-            let row = self.noteOutlineView.clickedRow
-            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]
-                guard let foldNote = self.fetchNote(for: row) else {
-                    return
-                }
-                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())
-                let hideNotes = self.hideNotes()
-                if hideNotes == false && (items?.count ?? 0) == 1 {
-                    let annotation = self.noteItems(items!).lastObject as? CPDFAnnotation
-                    if let data = annotation?.isEditable(), data {
-                        if annotation?.type == nil {
-                            let isNote = annotation?.isNote() ?? false
-                            if 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
-                        }
-                    }
-                }
-
-                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)
-                }
-            } 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)
-            }
+            self.annoListMenu(menu)
         }
     }
 }
@@ -602,31 +458,19 @@ extension KMLeftSideViewController: NSMenuItemValidation {
             action == #selector(outlineContextMenuItemClicked_SetDestination) ||
             action == #selector(outlineContextMenuItemClicked_Rename) ||
             action == #selector(outlineContextMenuItemClicked_Promote) ||
-            action == #selector(outlineContextMenuItemClicked_Demote)) {
+            action == #selector(outlineContextMenuItemClicked_Demote) ||
+            action == #selector(leftSideEmptyAnnotationClick_DeleteOutline)) {
             return self.outlineListValidateMenuItem(menuItem)
         } else if action == #selector(toggleOutlineCaseInsensitiveSearch) {
             menuItem.state = self.outlineIgnoreCaseFlag ? .on : .off
             return true
-        }
-//        } else if (action == @selector(note_expandAllComments:) ||
-//                   action == @selector(note_foldAllComments:) ||
-//                   action == @selector(exportAnnotationNotes:) ||
-//                   action == @selector(leftSideEmptyAnnotationClick_DeleteAnnotation:) ||
-//                   action == @selector(removeAllAnnotations:)) {
-//            if (@available(macOS 10.13, *)) {
-//                if (notes.count == 0) {
-//                    return NO;
-//                } else {
-//                    return YES;
-//                }
-//            } else {
-//                if (action == @selector(note_expandAllComments:) ||
-//                    action == @selector(note_foldAllComments:)) {
-//                    return NO;
-//                }
-//            }
-//        } else
-        if (action == #selector(unfoldNoteAction) ||
+        } else if (action == #selector(note_expandAllComments) ||
+                   action == #selector(note_foldAllComments) ||
+                   action == #selector(exportAnnotationNotes) ||
+                   action == #selector(leftSideEmptyAnnotationClick_DeleteAnnotation) ||
+                   action == #selector(removeAllAnnotations)) {
+            return self.annotations.count > 0
+        } else if (action == #selector(unfoldNoteAction) ||
             action == #selector(foldNoteAction)) {
             let row = self.noteOutlineView.clickedRow
 //            NSArray *noteArr = [rightSideController.noteArrayController arrangedObjects];
@@ -647,48 +491,23 @@ extension KMLeftSideViewController: NSMenuItemValidation {
             } else {
                 return true
             }
-        }
-//        else if (action == @selector(editNoteFromTable:)) {
-//            NSInteger row = [rightSideController.noteOutlineView clickedRow];
-//            NSArray * noteArr = [rightSideController.noteArrayController arrangedObjects];
-//            PDFAnnotation *foldNote = (PDFAnnotation *)noteArr[row];
+        } else if (action == #selector(editNoteFromTable)) {
+            let row = self.noteOutlineView.clickedRow
+            let foldNote = self.fetchNote(for: row)
 //            if (@available(macOS 10.13, *)) {
 //                if ([foldNote.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
 //                    return NO;
 //                }
 //            }
-//            if ([foldNote isKindOfClass:[PDFAnnotationStamp class]] ||
-//                [foldNote isKindOfClass:[KMAnnotationStamp class]]) {
-//                return NO;
-//            } else {
-//                return YES;
-//            }
-//        }
-        else if (action == #selector(menuItemClick_SelectAll)) {
+            if foldNote is CPDFStampAnnotation || foldNote is KMAnnotationStamp || foldNote is CPDFListStampAnnotation {
+                return false
+            } else {
+                return true
+            }
+        } else if (action == #selector(menuItemClick_SelectAll)) {
             menuItem.state = self.snapshotListIsAllSelected() ? .on : .off
             return true
         }
-//        else if (action == @selector(leftSideEmptyAnnotationClick_DeleteOutline:)) {
-//            PDFOutline * item = [[pdfView document] outlineRoot];
-//            if (self.isSearchOutlineMode) {
-//                NSInteger num = 0;
-//                for (NSUInteger i = 0; i < [item numberOfChildren]; i++) {
-//                    PDFOutline *outline = [item childAtIndex:i];
-//                    if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:outline]) {
-//                        num ++;
-//                    }
-//                }
-//                if (num > 0)
-//                    return YES;
-//                else
-//                    return NO;
-//            } else {
-//                if ([item numberOfChildren] > 0)
-//                    return YES;
-//                else
-//                    return NO;
-//            }
-//        }
         return true
     }
 }

+ 103 - 132
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift

@@ -17,7 +17,7 @@ extension KMLeftSideViewController.Key {
     static let noteFilterAuther = "kKMNoteFilterAnnotationAutherKey"
 }
 
-// MARK: - Menu
+// MARK: - Action
 
 extension KMLeftSideViewController {
     func note_initSubViews() {
@@ -43,7 +43,7 @@ extension KMLeftSideViewController {
         self.noteDoneButton.action = #selector(leftSideViewDoneButtonAction)
         self.noteDoneButton.target = self
         self.noteDoneButton.tag = 311
-        self.noteDoneButton.isHidden = true        
+        self.noteDoneButton.isHidden = true
         
         self.noteSearchField.delegate = self
         self.noteSearchField.isHidden = true
@@ -161,6 +161,107 @@ extension KMLeftSideViewController {
         self.noteOutlineView.autoresizesOutlineColumn = false
         self.noteOutlineView.indentationPerLevel = 0
     }
+}
+
+// MARK: - Menu
+
+extension KMLeftSideViewController {
+    func annoListMenu(_ menu: NSMenu) {
+        var item: NSMenuItem?
+        var items: NSArray?
+        var rowIndexes = self.noteOutlineView.selectedRowIndexes
+        let row = self.noteOutlineView.clickedRow
+        if row == -1 {
+            self._addExportPDFMenu(menu)
+            item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
+            return
+        }
+        if rowIndexes.contains(row) == false {
+            rowIndexes = IndexSet(integer: row)
+        }
+        items = self.noteOutlineView.itemsAtRowIndexes(rowIndexes) as NSArray
+        guard let foldNote = self.fetchNote(for: row) else {
+            return
+        }
+        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())
+        let hideNotes = self.hideNotes()
+        if hideNotes == false && (items?.count ?? 0) == 1 {
+            let annotation = self.noteItems(items!).lastObject as? CPDFAnnotation
+            if let data = annotation?.isEditable(), data {
+                if annotation?.type == nil {
+                    let isNote = annotation?.isNote() ?? false
+                    if 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
+                }
+            }
+        }
+        
+        if menu.numberOfItems > 0 {
+            self._addExportPDFMenu(menu)
+            
+            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)
+        }
+    }
+    
+    private func _addExportPDFMenu(_ menu: NSMenu) -> NSMenu {
+        var 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
+        return menu
+    }
     
     @IBAction func note_expandAllComments(_ sender: AnyObject?) {
         if (self.foldType == .unfold) { // 已全部展开
@@ -418,136 +519,6 @@ extension KMLeftSideViewController {
 // MARK: - Note
 
 extension KMLeftSideViewController {
-//    func loadAnnotationSortData(_ morePredicates: NSArray) {
-//        var isLink = false
-//        var typeMutableArr = NSMutableArray()
-//        if self.allAnnotations.count > 0 {
-//            for annotation in self.allAnnotations {
-//                if annotation is CPDFLinkAnnotation || annotation is CPDFTextWidgetAnnotation || annotation is CPDFButtonWidgetAnnotation || annotation is CPDFChoiceWidgetAnnotation {
-////                    [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature] ||
-////                    [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeText] ||
-////                    [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeButton] ||
-////                    [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeChoice]) {
-//                    isLink = true
-//                } else {
-//                    if typeMutableArr.contains(annotation.type) == false {
-//                        typeMutableArr.add(annotation.type)
-//                    }
-//                }
-//            }
-//        }
-//
-//        var colorMutableArray = NSMutableArray()
-//        var typeMutableArray = NSMutableArray()
-//        var authorMutableArray = NSMutableArray()
-//        for annotation in self.allAnnotations {
-//            if annotation is CPDFLinkAnnotation || annotation is CPDFTextWidgetAnnotation || annotation is CPDFButtonWidgetAnnotation || annotation is CPDFChoiceWidgetAnnotation {
-////                    [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature] ||
-////                    [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeText] ||
-////                    [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeButton] ||
-////                    [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeChoice]) {
-//                let noteColor = annotation.color ?? .clear
-//                let noteType = annotation.type ?? ""
-//                let authorString = annotation.userName() ?? ""
-//                if (noteColor != nil) {
-//                    if (colorMutableArray.count > 0) {
-//                        if colorMutableArray.contains(noteColor) == false {
-//                            colorMutableArray.add(noteColor)
-//                        }
-//                    } else {
-//                        colorMutableArray.add(noteColor)
-//                    }
-//                }
-//                if noteType.isEmpty == false {
-//                    if typeMutableArray.count > 0 {
-//                        if typeMutableArray.contains(noteType) == false {
-//                            typeMutableArray.add(noteType)
-//                        }
-//                    } else {
-//                        typeMutableArray.add(noteType)
-//                    }
-//                }
-//                if authorString.isEmpty == false {
-//                    if authorString.count > 0 {
-//                        if authorMutableArray.contains(authorString) == false {
-//                            authorMutableArray.add(authorString)
-//                        }
-//                    } else {
-//                        authorMutableArray.add(authorString)
-//                    }
-//                }
-//            } else {
-//                if typeMutableArr.contains(annotation.type) == false {
-//                    typeMutableArr.add(annotation.type)
-//                }
-//            }
-//        }
-//
-//        let sud = UserDefaults.standard
-//        var typeArr = NSMutableArray()
-//
-//        if let typeData = KMDataManager.ud_object(forKey: NoteFilterVC.filterSelectTypeKey) as? Data {
-//            if let data = NSKeyedUnarchiver.unarchiveObject(with: typeData) as? NSArray {
-//                typeArr = NSMutableArray(array: data)
-//            }
-//        }
-//        var colorArr = NSMutableArray()
-//        if let colorData = sud.object(forKey: NoteFilterVC.filterSelectColorKey) as? Data {
-//            if let data = NSKeyedUnarchiver.unarchiveObject(with: colorData) as? NSArray {
-//                colorArr = NSMutableArray(array: data)
-//            }
-//        }
-//        var authorArr = NSMutableArray()
-//        if let authorData = sud.object(forKey: NoteFilterVC.filterSelectAuthorKey) as? Data {
-//            if let data = NSKeyedUnarchiver.unarchiveObject(with: authorData) as? NSArray {
-//                authorArr = NSMutableArray(array: data)
-//            }
-//        }
-//
-//        var temporaryArr1 = NSMutableArray()
-//        var temporaryArr2 = NSMutableArray()
-//        var temporaryArr3 = NSMutableArray()
-//        if (typeArr.count > 0) {
-//            for type in typeArr {
-//                if typeMutableArray.contains(type) == false {
-//                    temporaryArr1.add(type)
-//                }
-//            }
-//        }
-//        if (colorArr.count > 0) {
-//            for color in colorArr {
-//                if colorMutableArray.contains(color) == false {
-//                    temporaryArr2.add(color)
-//                }
-//            }
-//        }
-//        if (authorArr.count > 0) {
-//            for author in authorArr {
-//                if authorMutableArray.contains(author) == false {
-//                    temporaryArr3.add(author)
-//                }
-//            }
-//        }
-//
-//        if (temporaryArr1.count > 0) {
-//            for type in temporaryArr1 {
-//                typeArr.remove(type)
-//            }
-//        }
-//        if (temporaryArr2.count > 0) {
-//            for color in temporaryArr2 {
-//                colorArr.remove(color)
-//            }
-//        }
-//        if (temporaryArr3.count > 0) {
-//            for author in temporaryArr3 {
-//                authorArr.remove(author)
-//            }
-//        }
-//
-//        var predicateMutableArr = NSMutableArray()
-//    }
-    
     func note_refrshUIIfNeed() {
         if self.type.methodType != .Annotation {
             return

+ 50 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Outline.swift

@@ -527,11 +527,61 @@ extension KMLeftSideViewController {
         _ = menu.addItem(withTitle: NSLocalizedString("Demote", comment: ""), action: #selector(outlineContextMenuItemClicked_Demote), target: self, tag: KMOutlineViewMenuItemTag.demote.rawValue)
     }
     
+    func outlineMoreMenu(_ view: NSButton) {
+        let menu = NSMenu()
+        let expandAllItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(toc_expandAllComments), target: self)
+        expandAllItem?.representedObject = self.tocOutlineView
+
+        let foldAllItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(toc_foldAllComments), target: self)
+        foldAllItem?.representedObject = self.tocOutlineView
+        let rootOL = self.outlineRoot()
+        let childNum = rootOL?.numberOfChildren ?? 0
+
+        var num = 0
+        for i in 0 ..< childNum {
+            let ol = rootOL?.child(at: i)
+            if self.tocOutlineView.isItemExpanded(ol) {
+                num += 1
+            }
+        }
+
+        self.tocType = .none
+        if childNum > 0 {
+            if num == 0 {
+                self.tocType = .fold
+            } else if num == childNum {
+                self.tocType = .unfold
+            }
+        }
+
+        expandAllItem?.state = self.tocType == .unfold ? .on : .off
+        foldAllItem?.state = self.tocType == .fold ? .on : .off
+
+        let removeEntryItem = menu.addItem(title: KMLocalizedString("Remove All Outlines", nil), action: #selector(leftSideEmptyAnnotationClick_DeleteOutline), target: self)
+        removeEntryItem?.representedObject = self.tocOutlineView
+        if let data = NSApp.currentEvent {
+            NSMenu.popUpContextMenu(menu, with: data, for: view)
+        }
+    }
+    
     func outlineListValidateMenuItem(_ menuItem: NSMenuItem) -> Bool {
         if self.isLocked() {
             return false
         }
         let action = menuItem.action
+        if (action == #selector(leftSideEmptyAnnotationClick_DeleteOutline)) {
+            guard let rootOL = self.outlineRoot() else {
+                return false
+            }
+            let childNum = rootOL.numberOfChildren
+            if (self.isSearchOutlineMode) {
+                let ols = self.fetchOutlines(for: rootOL, searchString: self.outlineSearchField.stringValue)
+                return ols.count > 0
+            } else {
+                return childNum > 0
+            }
+        }
+       
         if (self.isSearchOutlineMode) {
             if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
                 action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||