Ver código fonte

【BOTA】大纲升级节点菜单功能补充

tangchao 1 ano atrás
pai
commit
7b3f9ac0a7

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

@@ -247,6 +247,23 @@ extension KMLeftSideViewController {
 
         self.tocOutlineView.km_selectItem(demoteOutline, byExtendingSelection: false)
     }
+    
+    func promoteOutlineWithGrandParent(_ grandParentOutline: CPDFOutline, promoteOutline: CPDFOutline, rowIndex: Int) {
+//        [[[self.document undoManager] prepareWithInvocationTarget:self] demoteOutlineWithGrandParent:grandParentOutline demoteOutline:promoteOutline index:rowIndex];
+        let index = promoteOutline.parent?.index ?? 0
+        
+        if grandParentOutline.isEqual(to: promoteOutline.parent) {
+            promoteOutline.removeFromParent()
+            grandParentOutline.parent.insertChild(promoteOutline, at: index+1)
+        } else {
+            promoteOutline.removeFromParent()
+            grandParentOutline.insertChild(promoteOutline, at: index+1)
+        }
+
+        self.tocOutlineView.reloadData()
+        
+        self.tocOutlineView.km_selectItem(promoteOutline, byExtendingSelection: false)
+    }
 }
 
 // MARK: - Menu Actions
@@ -382,4 +399,18 @@ extension KMLeftSideViewController {
 
         self.demoteOutlineWithGrandParent(newParentOutLine!, demoteOutline: currentOutline, index: Int(currentIndex))
     }
+    
+    //升级节点
+    
+    @objc func outlineContextMenuItemClicked_Promote(_ sender: AnyObject?) {
+        guard let currentOutline: CPDFOutline = self.tocOutlineView.km.clickedItem() else {
+            return
+        }
+
+        let parentOutLine = currentOutline.parent
+
+        if let grandParentOutLine = parentOutLine?.parent {
+            self.promoteOutlineWithGrandParent(grandParentOutLine, promoteOutline: currentOutline, rowIndex:Int(currentOutline.index))
+        }
+    }
 }

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

@@ -4687,10 +4687,6 @@ extension KMLeftSideViewController {
         }
     }
     
-    @objc func outlineContextMenuItemClicked_Promote(_ sender: AnyObject?) {
-        KMPrint("KMLeftSideViewController-outlineContextMenuItemClicked_Promote...")
-    }
-    
     private func _tableView(_ tv: NSTableView, cutRowsWithIndexes rowIndexes: IndexSet) {
         if tv.isEqual(to: self.thumbnailTableView) {
             self._copysPages.removeAll()