فهرست منبع

【综合】PDFview 选中文本-右击-新增大纲条目后,需要展开左侧面板大纲列表(已修复)

tangchao 11 ماه پیش
والد
کامیت
9661637c89

+ 89 - 1
PDF Office/PDF Master/Class/Common/Category/CPDFKit/CPDFOutline+KMExtension.swift

@@ -54,18 +54,61 @@ import Foundation
 }
 
 @objc extension CPDFOutline {
-    func km_insertChild(label: String?, dest: CPDFDestination?, at index: Int) -> CPDFOutline? {
+    @objc func km_insertChild(label: String?, dest: CPDFDestination?, at index: Int) -> CPDFOutline? {
         let outline = self.insertChild(at: UInt(index))
         outline?.label = label
         outline?.destination = dest
         return outline
     }
+    
+    @objc func addLast(label: String?, dest: CPDFDestination?) -> CPDFOutline? {
+        self.add(label: label, dest: dest, at: self.numberOfChildren)
+    }
+    
+    @objc func add(label: String?, dest: CPDFDestination?, at index: UInt) -> CPDFOutline? {
+        let ol = self.insertChild(at: index)
+        ol?.label = label
+        ol?.destination = dest
+        return ol
+    }
 }
 
 // CPDFOutline
 
 @objc extension CPDFDocument {
     
+    @objc func addOutlineForRootLast(label: String?, dest: CPDFDestination?) -> CPDFOutline? {
+        if let root = self.outlineRoot() {
+            return self.addOutlineForRoot(label: label, dest: dest, at: root.numberOfChildren)
+        }
+        if let root = self.setNewOutlineRoot() {
+            return self.addOutlineForRoot(label: label, dest: dest, at: root.numberOfChildren)
+        }
+        return nil
+    }
+    
+    @objc func addOutlineLast(for ol: CPDFOutline, label: String?, dest: CPDFDestination?) -> CPDFOutline? {
+        return self.addOutline(for: ol, label: label, dest: dest, at: ol.numberOfChildren)
+    }
+    
+    @objc func addOutlineForRoot(label: String?, dest: CPDFDestination?, at index: UInt) -> CPDFOutline? {
+        if let root = self.outlineRoot() {
+            return self.addOutline(for: root, label: label, dest: dest, at: index)
+        }
+        if let root = self.setNewOutlineRoot() {
+            return self.addOutline(for: root, label: label, dest: dest, at: index)
+        }
+        return nil
+    }
+    
+    @objc func addOutline(for ol: CPDFOutline, label: String?, dest: CPDFDestination?, at index: UInt) -> CPDFOutline? {
+        return ol.add(label: label, dest: dest, at: index)
+    }
+    
+    @objc func remove(outline ol: CPDFOutline) {
+        ol.removeFromParent()
+    }
+    
     @objc func canPromote(outline ol: CPDFOutline) -> Bool {
         if self.isLocked {
             return false
@@ -170,9 +213,39 @@ import Foundation
 @objc extension CPDFListView {
     static let outlineKey =                 "outline"
     static let outlineUndoKey =             "undo"
+    static let outlineAddKey =              "add"
+    static let outlineRemoveKey =           "remove"
     static let outlineDemoteKey =           "demote"
     static let outlinePromoteKey =          "promote"
     
+    @objc func addOutlineForRoot(label: String?, dest: CPDFDestination?, at index: UInt) -> CPDFOutline? {
+        if let addOL = self.document?.addOutlineForRoot(label: label, dest: dest, at: index) {
+            (self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_remove(outline: addOL)
+            
+            self.pdfListViewDelegate.pdfListView?(self, documentDataDidChanged: addOL, withInfo: [Self.outlineKey : true, Self.outlineAddKey : true])
+            return addOL
+        }
+        return nil
+    }
+    
+    @objc func addOutline(for ol: CPDFOutline, label: String?, dest: CPDFDestination?, at index: UInt) -> CPDFOutline? {
+        if let addOL = self.document?.addOutline(for: ol, label: label, dest: dest, at: index) {
+            (self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_remove(outline: addOL)
+            
+            self.pdfListViewDelegate.pdfListView?(self, documentDataDidChanged: addOL, withInfo: [Self.outlineKey : true, Self.outlineAddKey : true])
+            return addOL
+        }
+        return nil
+    }
+    
+    @objc func remove(outline ol: CPDFOutline) {
+        (self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_add(for: ol.parent, label: ol.label, dest: ol.destination, at: ol.index)
+        
+        self.document.remove(outline: ol)
+        
+        self.pdfListViewDelegate.pdfListView?(self, documentDataDidChanged: ol, withInfo: [Self.outlineKey : true, Self.outlineRemoveKey : true])
+    }
+    
     @objc func canPromote(outline ol: CPDFOutline) -> Bool {
         return self.document?.canPromote(outline: ol) ?? false
     }
@@ -206,6 +279,21 @@ import Foundation
         self.pdfListViewDelegate.pdfListView?(self, documentDataDidChanged: ol, withInfo: [Self.outlineKey : true, Self.outlinePromoteKey : true])
     }
     
+    private func _undo_add(for ol: CPDFOutline, label: String?, dest: CPDFDestination?, at index: UInt) {
+        if let addOL = self.document.addOutline(for: ol, label: label, dest: dest, at: index) {
+            (self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_remove(outline: addOL)
+            self.pdfListViewDelegate.pdfListView?(self, documentDataDidChanged: addOL, withInfo: [Self.outlineKey : true, Self.outlineAddKey : true, Self.outlineUndoKey : true])
+        }
+    }
+    
+    private func _undo_remove(outline ol: CPDFOutline) {
+        (self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_add(for: ol.parent, label: ol.label, dest: ol.destination, at: ol.index)
+        
+        self.document.remove(outline: ol)
+        
+        self.pdfListViewDelegate.pdfListView?(self, documentDataDidChanged: ol, withInfo: [Self.outlineKey : true, Self.outlineRemoveKey : true, Self.outlineUndoKey : true])
+    }
+    
     private func _undo_demote(outline ol: CPDFOutline, at index: UInt) {
         (self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_promote(outline: ol, at: ol.index)
         

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

@@ -392,6 +392,31 @@ extension KMLeftSideViewController {
         return num
     }
     
+    func addOutlineAfter(_ ol: CPDFOutline) {
+        if self.leftView.segmentedControl.selectedSegment == 1 {
+            
+        } else {
+            self.leftView.segmentedControl.selectedSegment = 1
+        }
+        
+        Task { @MainActor in
+            self.tocOutlineView.reloadData()
+            let idx = self.tocOutlineView.row(forItem: ol)
+            self.tocOutlineView.km_selectItem(ol, byExtendingSelection: false)
+            self.newAddOutlineEntryEditingMode(idx)
+        }
+
+        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
+            self.tocOutlineView.scrollRowToVisible(self.tocOutlineView.row(forItem: ol))
+        }
+    }
+    
+    func removeOutlineAfter(_ ol: CPDFOutline) {
+        Task { @MainActor in
+            self.tocOutlineView.reloadData()
+        }
+    }
+    
     func demoteOutlineAfter(_ ol: CPDFOutline) {
         Task { @MainActor in
             self.tocOutlineView.reloadData()

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

@@ -712,10 +712,20 @@ extension KMMainViewController {
     }
     
     @objc func addOutLineItemAction() {
-        //在当前page上添加
-//        self.listView.currentPageIndex
-//        self.listView.currentPage()
-        self.leftSideViewController.outlineContextMenuItemClicked_AddEntry(nil)
+        let labelString = "\(KMLocalizedString("Page", nil)) \((self.listView?.currentPageIndex ?? 0) + 1)"
+        let label = self.listView?.currentSelection?.string() ?? labelString
+        let dest =  self.listView?.currentDestination
+        if let row = self.leftSideViewController.selectedRowIndexes().last {
+            if let ol = self.leftSideViewController.tocOutlineView.item(atRow: row) as? CPDFOutline {
+                _ = self.listView.addOutline(for: ol.parent, label: label, dest: dest, at: ol.index+1)
+            } else {
+                let idx = self.listView?.document?.outlineRoot()?.numberOfChildren ?? 0
+                _ = self.listView.addOutlineForRoot(label: label, dest:dest, at: idx)
+            }
+        } else {
+            let idx = self.listView?.document?.outlineRoot()?.numberOfChildren ?? 0
+            _ = self.listView.addOutlineForRoot(label: label, dest:dest, at: idx)
+        }
     }
     
     @objc func showTTSView() {

+ 9 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -3223,6 +3223,15 @@ let LOCKED_KEY  = "locked"
             guard let ol = docData as? CPDFOutline else {
                 return
             }
+            let add = info?[CPDFListView.outlineAddKey] as? Bool ?? false
+            let remove = info?[CPDFListView.outlineRemoveKey] as? Bool ?? false
+            if add {
+                self.leftSideViewController.addOutlineAfter(ol)
+            }
+            if remove {
+                self.leftSideViewController.removeOutlineAfter(ol)
+            }
+            
             let demote = info?[CPDFListView.outlineDemoteKey] as? Bool ?? false
             let promote = info?[CPDFListView.outlinePromoteKey] as? Bool ?? false
             if demote {

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

@@ -404,54 +404,6 @@
             </Locations>
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "AEC34DED-6D20-41DF-9D3F-E270C9C7D827"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "2412"
-            endingLineNumber = "2412"
-            landmarkName = "pdfViewEditingAreaDidChanged(_:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "697A5ABC-1570-432F-8220-26DB90FF78C2"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "2517"
-            endingLineNumber = "2517"
-            landmarkName = "pdfViewEditingCropBoundsDidChanged(_:editing:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "817846FD-FB92-4370-BA8D-53B423A56961"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "2524"
-            endingLineNumber = "2524"
-            landmarkName = "pdfViewEditingAddImageArea(_:add:add:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent