Forráskód Böngészése

【综合】BOTA 注释列表,无注释时- more,只有“显示注释”和“导出注释”是高亮的(已修复)

tangchao 11 hónapja
szülő
commit
aeed6fec4e

+ 0 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Action.swift

@@ -377,7 +377,6 @@ extension KMLeftSideViewController: NSMenuItemValidation {
         if (action == #selector(note_expandAllComments) ||
                    action == #selector(note_foldAllComments) ||
                    action == #selector(exportAnnotationNotes) ||
-                   action == #selector(leftSideEmptyAnnotationClick_DeleteAnnotation) ||
                    action == #selector(removeAllAnnotations) ||
                    action == #selector(unfoldNoteAction) ||
                    action == #selector(foldNoteAction) ||

+ 66 - 40
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift

@@ -172,8 +172,8 @@ extension KMLeftSideViewController {
         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)
+            _ = self._addExportPDFMenu(menu)
+            _ = self._addDeleteAllAnnoItem(menu)
             return
         }
         if rowIndexes.contains(row) == false {
@@ -237,12 +237,12 @@ extension KMLeftSideViewController {
                 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)
+            _ = self._addDeleteAllAnnoItem(menu)
         }
     }
     
     private func _addExportPDFMenu(_ menu: NSMenu) -> NSMenu {
-        var item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "", comment: ""), action: #selector(exportAnnotationNotes), target: self)
+        var item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "", comment: ""), action: nil, target: self)
         
         let subMenu = NSMenu()
         item?.submenu = subMenu
@@ -263,6 +263,10 @@ extension KMLeftSideViewController {
         return menu
     }
     
+    private func _addDeleteAllAnnoItem(_ menu: NSMenu) -> NSMenuItem? {
+        return menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "", comment: ""), action: #selector(removeAllAnnotations), target: self)
+    }
+    
     func annoListMoreMenu(_ view: NSButton) {
         let menu = NSMenu()
         let object = KMPopupMenuObject()
@@ -307,8 +311,8 @@ extension KMLeftSideViewController {
         _ = 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
+        let removeAllItem = self._addDeleteAllAnnoItem(menu)
+//        removeAllItem?.representedObject = self.noteOutlineView
         if let data = NSApp.currentEvent {
             NSMenu.popUpContextMenu(menu, with: data, for: view, with: nil)
         }
@@ -319,7 +323,6 @@ extension KMLeftSideViewController {
         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) ||
@@ -397,35 +400,6 @@ extension KMLeftSideViewController {
         doc?.saveTo(sender)
     }
     
-    @objc func leftSideEmptyAnnotationClick_DeleteAnnotation(_ sender: AnyObject?) {
-        guard let doc = self.pdfDocument() else {
-            return
-        }
-        Task {
-            let response = await KMAlertTool.runModel(message: KMLocalizedString("This will permanently remove all annotations. Are you sure to continue?", nil), buttons: [KMLocalizedString("Yes", nil), KMLocalizedString("No", nil)])
-            if response == .alertFirstButtonReturn {
-                var annos: [CPDFAnnotation] = []
-                for i in 0 ..< doc.pageCount {
-                    let page = self.pdfDocument()?.page(at: i)
-                    for anno in page?.annotations ?? [] {
-                        if anno is CPDFTextWidgetAnnotation || anno is CPDFButtonWidgetAnnotation || anno is CPDFChoiceWidgetAnnotation {
-                            continue
-                        }
-                        //                        if ([annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
-                        //                            continue;
-                        //                        }
-                        annos.append(anno)
-                    }
-                }
-                for anno in annos {
-                    self.listView?.remove(anno)
-                }
-                
-                self.reloadAnnotation()
-            }
-        }
-    }
-    
     @objc func unfoldNoteAction(_ sender: NSMenuItem) {
         if sender.state == .on {
             return
@@ -477,7 +451,32 @@ extension KMLeftSideViewController {
     }
     
     @objc func removeAllAnnotations(_ sender: AnyObject?) {
-        self.leftSideEmptyAnnotationClick_DeleteAnnotation(nil)
+        guard let doc = self.pdfDocument() else {
+            return
+        }
+        Task {
+            let response = await KMAlertTool.runModel(message: KMLocalizedString("This will permanently remove all annotations. Are you sure to continue?", nil), buttons: [KMLocalizedString("Yes", nil), KMLocalizedString("No", nil)])
+            if response == .alertFirstButtonReturn {
+                var annos: [CPDFAnnotation] = []
+                for i in 0 ..< doc.pageCount {
+                    let page = self.pdfDocument()?.page(at: i)
+                    for anno in page?.annotations ?? [] {
+                        if anno is CPDFTextWidgetAnnotation || anno is CPDFButtonWidgetAnnotation || anno is CPDFChoiceWidgetAnnotation {
+                            continue
+                        }
+                        //                        if ([annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
+                        //                            continue;
+                        //                        }
+                        annos.append(anno)
+                    }
+                }
+                for anno in annos {
+                    self.listView?.remove(anno)
+                }
+                
+                self.reloadAnnotation()
+            }
+        }
     }
     
     @objc func editNoteTextFromTable(_ sender: NSMenuItem) {
@@ -600,6 +599,33 @@ extension KMLeftSideViewController {
 //        self.annotationSort(sortArray: [])
         self.reloadAnnotation()
     }
+    
+    func showNoteEmptyView() {
+        let view = self.noteOutlineView.enclosingScrollView?.documentView
+        let viewFrame = view?.frame ?? .zero
+        let emptyVcSize =  self.leftSideEmptyVC.emptyAnnotationView.frame.size
+        self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((viewFrame.size.width-emptyVcSize.width)/2.0,(viewFrame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
+        
+        self.leftSideEmptyVC.emptyAnnotationView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
+        self.noteOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyAnnotationView)
+        self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = false
+        self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = false
+        
+        if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
+            self.noteHeaderView.isHidden = true
+            self.toolButtonBoxLayoutConstraint.constant = 40.0
+        }
+    }
+    
+    func hideNoteEmptyView() {
+        self.leftSideEmptyVC.emptyAnnotationView.removeFromSuperview()
+        self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = true
+        self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = true
+        if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
+            self.noteHeaderView.isHidden = false
+            self.toolButtonBoxLayoutConstraint.constant = 64.0
+        }
+    }
 }
 
 // MARK: - Note
@@ -639,9 +665,9 @@ extension KMLeftSideViewController {
     func reloadAnnotation() {
         if self.listView != nil {
             let filterKey = self.pdfDocument()?.documentURL.path ?? ""
-            var typeArr: [Any] = KMBotaTools.noteFilterAnnoTypes(key: filterKey)
-            var colorArr: [Any] = KMBotaTools.noteFilterColors(key: filterKey)
-            var authorArr: [Any] = KMBotaTools.noteFilterAuthors(key: filterKey)
+            let typeArr: [Any] = KMBotaTools.noteFilterAnnoTypes(key: filterKey)
+            let colorArr: [Any] = KMBotaTools.noteFilterColors(key: filterKey)
+            let authorArr: [Any] = KMBotaTools.noteFilterAuthors(key: filterKey)
             if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
 //                self.filtrateButton.image = NSImage(named: "KMImageNameAnnotationsFiltrate")
                 self.filterButtonLayer?.isHidden = true

+ 15 - 42
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -523,8 +523,6 @@ class KMLeftSideViewController: KMSideViewController {
     }
     
     func displayNoteViewAnimating(_ animate: Bool) {
-        self.reloadAnnotation()
-        
         self.searchViewController.contentView = nil
         if let data = self.noteOutlineView.enclosingScrollView {
             self.replaceSideView(data, animate: animate)
@@ -555,9 +553,7 @@ class KMLeftSideViewController: KMSideViewController {
         let emptyVcSize =  self.leftSideEmptyVC.emptyAnnotationView.frame.size
         self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((viewFrame.size.width-emptyVcSize.width)/2.0,(viewFrame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
         
-        DispatchQueue.main.async {
-            self.noteOutlineView.reloadData()
-        }
+        self.reloadAnnotation()
     }
     
     func displaySnapshotViewAnimating(_ animate: Bool) {
@@ -1769,39 +1765,15 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                     count += cnt
                 }
             }
-            if (self.allAnnotations.count < 1) {
-                self.noteSearchButton.isEnabled = false
-                self.noteFilterButton.isEnabled = false
-            } else {
-                self.noteSearchButton.isEnabled = true
-                self.noteFilterButton.isEnabled = true
-            }
+
+            let hasAnno = self.allAnnotations.count >= 1
+            self.noteSearchButton.isEnabled = hasAnno
+            self.noteFilterButton.isEnabled = hasAnno
+            self.noteOutlineView.usesAlternatingRowBackgroundColors = false
             if count < 1 {
-                self.noteOutlineView.usesAlternatingRowBackgroundColors = false
-                let view = self.noteOutlineView.enclosingScrollView
-                let viewFrame = view?.frame ?? .zero
-                let emptyVcSize =  self.leftSideEmptyVC.emptyAnnotationView.frame.size
-                self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((viewFrame.size.width-emptyVcSize.width)/2.0,(viewFrame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
-                
-                self.leftSideEmptyVC.emptyAnnotationView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
-                self.noteOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyAnnotationView)
-                self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = false
-                self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = false
-                
-                if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
-                    self.noteHeaderView.isHidden = true
-                    self.toolButtonBoxLayoutConstraint.constant = 40.0
-                }
+                self.showNoteEmptyView()
             } else {
-                self.noteOutlineView.usesAlternatingRowBackgroundColors = false
-                
-                self.leftSideEmptyVC.emptyAnnotationView.removeFromSuperview()
-                self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = true
-                self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = true
-                if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
-                    self.noteHeaderView.isHidden = false
-                    self.toolButtonBoxLayoutConstraint.constant = 64.0
-                }
+                self.hideNoteEmptyView()
             }
             
             return count
@@ -1850,15 +1822,16 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
             if self.noteSearchMode {
                 return self.noteSearchArray[index]
             }
-            var tempArray: [KMBOTAAnnotationItem] = []
+            var items: [KMBOTAAnnotationItem] = []
             for secion in self.annotations {
-                if secion.annotations?.count != 0 {
-                    for _item in secion.annotations! {
-                        tempArray.append(_item)
-                    }
+                guard let eles = secion.annotations, eles.count > 0 else {
+                    continue
+                }
+                for ele in eles {
+                    items.append(ele)
                 }
             }
-            return tempArray[index] as Any
+            return items[index] as Any
         }
         return item as Any
     }

+ 2 - 2
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -542,8 +542,8 @@
             filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "2394"
-            endingLineNumber = "2394"
+            startingLineNumber = "2367"
+            endingLineNumber = "2367"
             landmarkName = "outlineView(_:acceptDrop:item:childIndex:)"
             landmarkType = "7">
          </BreakpointContent>