|
@@ -391,6 +391,21 @@ extension KMLeftSideViewController {
|
|
} while outline != nil
|
|
} while outline != nil
|
|
return num
|
|
return num
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ func demoteOutlineAfter(_ ol: CPDFOutline) {
|
|
|
|
+ Task { @MainActor in
|
|
|
|
+ self.tocOutlineView.reloadData()
|
|
|
|
+ self.tocOutlineView.expandItem(ol.parent)
|
|
|
|
+ self.tocOutlineView.km_selectItem(ol, byExtendingSelection: false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func promoteOutlineAfter(_ ol: CPDFOutline) {
|
|
|
|
+ Task { @MainActor in
|
|
|
|
+ self.tocOutlineView.reloadData()
|
|
|
|
+ self.tocOutlineView.km_selectItem(ol, byExtendingSelection: false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// MARK: - Undo & Redo
|
|
// MARK: - Undo & Redo
|
|
@@ -428,51 +443,12 @@ extension KMLeftSideViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @objc dynamic func demoteOutlineWithGrandParent(_ grandParentOutline: CPDFOutline, demoteOutline: CPDFOutline, index: Int) {
|
|
|
|
- (self.listView?.undoManager?.prepare(withInvocationTarget: self) as AnyObject).promoteOutlineWithGrandParent(grandParentOutline, promoteOutline: demoteOutline, rowIndex: index)
|
|
|
|
-
|
|
|
|
- if grandParentOutline.isEqual(to: demoteOutline.parent) {
|
|
|
|
- let demoteIndex = demoteOutline.index
|
|
|
|
- let previousOutline = grandParentOutline.child(at: demoteIndex-1)
|
|
|
|
- demoteOutline.removeFromParent()
|
|
|
|
- previousOutline?.insertChild(demoteOutline, at: UInt(index))
|
|
|
|
- self.tocOutlineView.reloadData()
|
|
|
|
- self.tocOutlineView.expandItem(previousOutline)
|
|
|
|
- } else {
|
|
|
|
- demoteOutline.removeFromParent()
|
|
|
|
- grandParentOutline.insertChild(demoteOutline, at: grandParentOutline.numberOfChildren)
|
|
|
|
- self.tocOutlineView.reloadData()
|
|
|
|
- self.tocOutlineView.expandItem(grandParentOutline)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- self.tocOutlineView.km_selectItem(demoteOutline, byExtendingSelection: false)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @objc dynamic func promoteOutlineWithGrandParent(_ grandParentOutline: CPDFOutline, promoteOutline: CPDFOutline, rowIndex: Int) {
|
|
|
|
- (self.listView?.undoManager?.prepare(withInvocationTarget: self) as AnyObject).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)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@objc dynamic func addoutline(parent parentOutline: CPDFOutline?, addOutline: CPDFOutline, index: Int, needExpand: Bool) {
|
|
@objc dynamic func addoutline(parent parentOutline: CPDFOutline?, addOutline: CPDFOutline, index: Int, needExpand: Bool) {
|
|
var tempO: CPDFOutline? = addOutline
|
|
var tempO: CPDFOutline? = addOutline
|
|
if addOutline.label != nil {
|
|
if addOutline.label != nil {
|
|
parentOutline?.insertChild(addOutline, at: UInt(index))
|
|
parentOutline?.insertChild(addOutline, at: UInt(index))
|
|
} else {
|
|
} else {
|
|
- let outline = parentOutline?.insertChild(at: UInt(index))
|
|
|
|
- outline?.label = String(format: "%@ %ld", KMLocalizedString("Page", nil), self.currentPageIndex()+1)
|
|
|
|
- outline?.destination = self.currentDestination()
|
|
|
|
|
|
+ let outline = parentOutline?.km_insertChild(label: String(format: "%@ %ld", KMLocalizedString("Page", nil), self.currentPageIndex()+1), dest: self.currentDestination(), at: index)
|
|
tempO = outline
|
|
tempO = outline
|
|
}
|
|
}
|
|
|
|
|
|
@@ -643,41 +619,13 @@ extension KMLeftSideViewController {
|
|
//降级节点
|
|
//降级节点
|
|
|
|
|
|
@objc func outlineContextMenuItemClicked_Demote(_ sender: AnyObject?) {
|
|
@objc func outlineContextMenuItemClicked_Demote(_ sender: AnyObject?) {
|
|
- guard let currentOutline: CPDFOutline = self.tocOutlineView.km.clickedItem() else {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- let parentOutLine = currentOutline.parent
|
|
|
|
- let newParentOutLine = parentOutLine?.child(at: currentOutline.index-1)
|
|
|
|
-
|
|
|
|
- var newIndex = 0
|
|
|
|
- let newParentOutLineExpandState = self.tocOutlineView.isItemExpanded(newParentOutLine)
|
|
|
|
-
|
|
|
|
- if (newParentOutLineExpandState) {
|
|
|
|
- newIndex = self.tocOutlineView.clickedRow
|
|
|
|
- } else {
|
|
|
|
- newIndex = self.tocOutlineView.clickedRow + Int(newParentOutLine?.numberOfChildren ?? 0)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let currentIndex = currentOutline.index
|
|
|
|
- currentOutline.removeFromParent()
|
|
|
|
-
|
|
|
|
- if let data = newParentOutLine {
|
|
|
|
- self.demoteOutlineWithGrandParent(data, demoteOutline: currentOutline, index: Int(currentIndex))
|
|
|
|
- }
|
|
|
|
|
|
+ self.delegate?.controller?(controller: self, itemClick: sender, itemKey: .demote, params: nil)
|
|
}
|
|
}
|
|
|
|
|
|
//升级节点
|
|
//升级节点
|
|
|
|
|
|
@objc func outlineContextMenuItemClicked_Promote(_ sender: AnyObject?) {
|
|
@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))
|
|
|
|
- }
|
|
|
|
|
|
+ self.delegate?.controller?(controller: self, itemClick: sender, itemKey: .promote, params: nil)
|
|
}
|
|
}
|
|
|
|
|
|
@objc func toggleOutlineCaseInsensitiveSearch(_ sender: NSMenuItem) {
|
|
@objc func toggleOutlineCaseInsensitiveSearch(_ sender: NSMenuItem) {
|