ソースを参照

【综合】BOTA 注释列表-搜索状态中,点击文档,搜索框会消失(已修复)

tangchao 11 ヶ月 前
コミット
de93067ab0

+ 13 - 125
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Action.swift

@@ -9,7 +9,7 @@ import Foundation
 
 // MARK: - Action
 
-extension KMLeftSideViewController {
+extension KMLeftSideViewController {    
     @IBAction func leftSideViewMoreButtonAction(_ sender: AnyObject?) {
         guard let button = sender as? NSButton else {
             NSSound.beep()
@@ -55,95 +55,7 @@ extension KMLeftSideViewController {
         } else if (tag == 302) {
             self.outlineMoreMenu(button)
         } else if (tag == 304) {
-            let menu = NSMenu()
-            let object = KMPopupMenuObject()
-            object.menuTag = 1001
-            menu.delegate = object
-            object.enterControllerCallback = { [weak self] isEnter in
-                if (isEnter) {
-                    self?.moreButtonLayer?.isHidden = false
-                } else {
-                    self?.moreButtonLayer?.isHidden = true
-                }
-            }
-            let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(note_expandAllComments), target: self)
-            expandAllCommentsItem?.representedObject = self.noteOutlineView
-            let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(note_foldAllComments), target: self)
-            foldAllCommentsItem?.representedObject = self.noteOutlineView
-            if (self.foldType == .unfold) {
-                expandAllCommentsItem?.state = .on
-                foldAllCommentsItem?.state = .off
-            } else if (self.foldType == .fold) {
-                expandAllCommentsItem?.state = .off
-                foldAllCommentsItem?.state = .on
-            } else {
-                expandAllCommentsItem?.state = .off
-                foldAllCommentsItem?.state = .off
-            }
-
-            let showAnnotationItem = menu.addItem(title: KMLocalizedString("Show Note", nil), action: nil, target: self)
-            let subMenu = NSMenu()
-            var t = subMenu.addItem(title: KMLocalizedString("Page", nil), action: #selector(noteShowNoteAction), target: self)
-            let pageKey = self.noteTypeDict[Self.Key.noteFilterPage] as? Bool ?? false
-            if pageKey {
-                t?.state = .off
-            } else {
-                t?.state = .on
-            }
-            t?.representedObject = self.noteOutlineView
-            t?.tag = 101
-            t = subMenu.addItem(title: KMLocalizedString("Time", nil) , action: #selector(noteShowNoteAction), target: self)
-            let timeKey = self.noteTypeDict[Self.Key.noteFilterTime] as? Bool ?? false
-            if timeKey {
-                t?.state = .off
-            } else {
-                t?.state = .on
-            }
-            t?.representedObject = self.noteOutlineView
-            t?.tag = 102
-            t = subMenu.addItem(title: KMLocalizedString("Author", nil) , action: #selector(noteShowNoteAction), target: self)
-            let authorKey = self.noteTypeDict[Self.Key.noteFilterAuther] as? Bool ?? false
-            if authorKey {
-                t?.state = .off
-            } else {
-                t?.state = .on
-            }
-            t?.representedObject = self.noteOutlineView
-            t?.tag = 103
-            showAnnotationItem?.submenu = subMenu
-            menu.addItem(.separator())
-
-            let exportAnnotationsItem = menu.addItem(title: NSLocalizedString("Export Annotations…", comment: ""), action: nil, target: self)
-            let subMenu2 = NSMenu()
-            var t2 = subMenu2.addItem(title: NSLocalizedString("PDF", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-            t2?.representedObject = self.noteOutlineView
-            t2?.tag = 0
-            t2 = subMenu2.addItem(title: NSLocalizedString("PDF Bundle", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-            t2?.representedObject = self.noteOutlineView
-            t2?.tag = 1
-            t2 = subMenu2.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-            t2?.representedObject = self.noteOutlineView
-            t2?.tag = 2
-            t2 = subMenu2.addItem(title: NSLocalizedString("Notes as Text", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-            t2?.representedObject = self.noteOutlineView
-            t2?.tag = 3
-            t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTF", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-            t2?.representedObject = self.noteOutlineView
-            t2?.tag = 4
-            t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTFD", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-            t2?.representedObject = self.noteOutlineView
-            t2?.tag = 5
-            t2 = subMenu2.addItem(title: NSLocalizedString("Notes as FDF", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-            t2?.representedObject = self.noteOutlineView
-            t2?.tag = 6
-            exportAnnotationsItem?.submenu = subMenu2
-            menu.addItem(.separator())
-
-            let removeAllAnnotationsItem = menu.addItem(title: NSLocalizedString("Remove All Annotations", comment: ""), action: #selector(leftSideEmptyAnnotationClick_DeleteAnnotation), target: self)
-            removeAllAnnotationsItem?.representedObject = self.noteOutlineView
-            if let data = NSApp.currentEvent {
-                NSMenu.popUpContextMenu(menu, with: data, for: button, with: nil)
-            }
+            self.annoListMoreMenu(button)
         }
     }
     
@@ -432,7 +344,7 @@ extension KMLeftSideViewController: NSMenuDelegate {
 
 // MARK: - NSMenuItemValidation
 
-extension KMLeftSideViewController: NSMenuItemValidation {    
+extension KMLeftSideViewController: NSMenuItemValidation {
     func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
         let isLocked = self.isLocked()
         if isLocked {
@@ -459,31 +371,20 @@ extension KMLeftSideViewController: NSMenuItemValidation {
             action == #selector(outlineContextMenuItemClicked_Rename) ||
             action == #selector(outlineContextMenuItemClicked_Promote) ||
             action == #selector(outlineContextMenuItemClicked_Demote) ||
-            action == #selector(leftSideEmptyAnnotationClick_DeleteOutline)) {
+            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) ||
+        }
+        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];
-//            PDFAnnotation *foldNote = (PDFAnnotation *)noteArr[row];
-//            let foldNote = self.allAnnotations[row]
-            let foldNote = self.fetchNote(for: row)
-            // SKNPDFAnnotationNote
-            if foldNote is CPDFMarkupAnnotation || foldNote is CPDFTextAnnotation {
-                return true
-            } else {
-                return false
-            }
-        } else if (action == #selector(menuItemClick_ExportPNG) ||
+                   action == #selector(removeAllAnnotations) ||
+                   action == #selector(unfoldNoteAction) ||
+                   action == #selector(foldNoteAction) ||
+                   action == #selector(editNoteFromTable)) { // 注释列表
+            return self.annoListValidateMenuItem(menuItem)
+        }
+        if (action == #selector(menuItemClick_ExportPNG) ||
             action == #selector(menuItemClick_ExportJPG) ||
             action == #selector(menuItemClick_ExportPDF)) {
             if (self.snapshotTableView.selectedRow == -1 ) {
@@ -491,19 +392,6 @@ extension KMLeftSideViewController: NSMenuItemValidation {
             } else {
                 return true
             }
-        } 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 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

+ 93 - 7
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift

@@ -48,11 +48,11 @@ extension KMLeftSideViewController {
         self.noteSearchField.delegate = self
         self.noteSearchField.isHidden = true
         self.noteSearchField.endEditCallBack = { [unowned self] isEndEdit in
-            if (isEndEdit) {
-                self.noteSearchField.isHidden = true
-                self.noteSearchButton.isHidden = false
-                self.noteTitleLabel.isHidden = false
-            }
+//            if (isEndEdit) {
+//                self.noteSearchField.isHidden = true
+//                self.noteSearchButton.isHidden = false
+//                self.noteTitleLabel.isHidden = false
+//            }
         }
 
         self.sortTypeBox.downCallback = { [unowned self] downEntered, mouseBox, _ in
@@ -230,7 +230,7 @@ extension KMLeftSideViewController {
         }
         
         if menu.numberOfItems > 0 {
-            self._addExportPDFMenu(menu)
+            _ = self._addExportPDFMenu(menu)
             
             menu.addItem(.separator())
             if self.outlineView(self.noteOutlineView, canDeleteItems: items as? [Any] ?? []) {
@@ -242,7 +242,7 @@ extension KMLeftSideViewController {
     }
     
     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)
+        var item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "", comment: ""), action: #selector(exportAnnotationNotes), target: self)
         
         let subMenu = NSMenu()
         item?.submenu = subMenu
@@ -263,6 +263,92 @@ extension KMLeftSideViewController {
         return menu
     }
     
+    func annoListMoreMenu(_ view: NSButton) {
+        let menu = NSMenu()
+        let object = KMPopupMenuObject()
+        object.menuTag = 1001
+        menu.delegate = object
+        object.enterControllerCallback = { [weak self] isEnter in
+            if (isEnter) {
+                self?.moreButtonLayer?.isHidden = false
+            } else {
+                self?.moreButtonLayer?.isHidden = true
+            }
+        }
+        let expandAllItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(note_expandAllComments), target: self)
+        expandAllItem?.representedObject = self.noteOutlineView
+        let foldAllItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(note_foldAllComments), target: self)
+        foldAllItem?.representedObject = self.noteOutlineView
+        expandAllItem?.state = self.foldType == .unfold ? .on : .off
+        foldAllItem?.state = self.foldType == .fold ? .on : .off
+
+        let showItem = menu.addItem(title: KMLocalizedString("Show Note", nil), action: nil, target: self)
+        let subMenu = NSMenu()
+        var pageItem = subMenu.addItem(title: KMLocalizedString("Page", nil), action: #selector(noteShowNoteAction), target: self)
+        let pageKey = self.noteTypeDict[Self.Key.noteFilterPage] as? Bool ?? false
+        pageItem?.state = pageKey ? .off : .on
+        pageItem?.representedObject = self.noteOutlineView
+        pageItem?.tag = 101
+        
+        let timeItem = subMenu.addItem(title: KMLocalizedString("Time", nil) , action: #selector(noteShowNoteAction), target: self)
+        let timeKey = self.noteTypeDict[Self.Key.noteFilterTime] as? Bool ?? false
+        timeItem?.state = timeKey ? .off : .on
+        timeItem?.representedObject = self.noteOutlineView
+        timeItem?.tag = 102
+        
+        let authorItem = subMenu.addItem(title: KMLocalizedString("Author", nil) , action: #selector(noteShowNoteAction), target: self)
+        let authorKey = self.noteTypeDict[Self.Key.noteFilterAuther] as? Bool ?? false
+        authorItem?.state = authorKey ? .off : .on
+        authorItem?.representedObject = self.noteOutlineView
+        authorItem?.tag = 103
+        showItem?.submenu = subMenu
+        menu.addItem(.separator())
+
+        _ = self._addExportPDFMenu(menu)
+        menu.addItem(.separator())
+
+        let removeAllItem = menu.addItem(title: NSLocalizedString("Remove All Annotations", comment: ""), action: #selector(leftSideEmptyAnnotationClick_DeleteAnnotation), target: self)
+        removeAllItem?.representedObject = self.noteOutlineView
+        if let data = NSApp.currentEvent {
+            NSMenu.popUpContextMenu(menu, with: data, for: view, with: nil)
+        }
+    }
+    
+    func annoListValidateMenuItem(_ menuItem: NSMenuItem) -> Bool {
+        let action = menuItem.action
+        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
+            let foldNote = self.fetchNote(for: row)
+            // SKNPDFAnnotationNote
+            if foldNote is CPDFMarkupAnnotation || foldNote is CPDFTextAnnotation {
+                return true
+            } else {
+                return false
+            }
+        } 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 is CPDFStampAnnotation || foldNote is KMAnnotationStamp || foldNote is CPDFListStampAnnotation {
+                return false
+            } else {
+                return true
+            }
+        }
+        return true
+    }
+    
     @IBAction func note_expandAllComments(_ sender: AnyObject?) {
         if (self.foldType == .unfold) { // 已全部展开
             return

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

@@ -580,6 +580,9 @@ extension KMLeftSideViewController {
             } else {
                 return childNum > 0
             }
+        } else if action == #selector(toggleOutlineCaseInsensitiveSearch) {
+            menuItem.state = self.outlineIgnoreCaseFlag ? .on : .off
+            return true
         }
        
         if (self.isSearchOutlineMode) {