|
@@ -54,18 +54,61 @@ import Foundation
|
|
}
|
|
}
|
|
|
|
|
|
@objc extension CPDFOutline {
|
|
@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))
|
|
let outline = self.insertChild(at: UInt(index))
|
|
outline?.label = label
|
|
outline?.label = label
|
|
outline?.destination = dest
|
|
outline?.destination = dest
|
|
return outline
|
|
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
|
|
// CPDFOutline
|
|
|
|
|
|
@objc extension CPDFDocument {
|
|
@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 {
|
|
@objc func canPromote(outline ol: CPDFOutline) -> Bool {
|
|
if self.isLocked {
|
|
if self.isLocked {
|
|
return false
|
|
return false
|
|
@@ -170,9 +213,39 @@ import Foundation
|
|
@objc extension CPDFListView {
|
|
@objc extension CPDFListView {
|
|
static let outlineKey = "outline"
|
|
static let outlineKey = "outline"
|
|
static let outlineUndoKey = "undo"
|
|
static let outlineUndoKey = "undo"
|
|
|
|
+ static let outlineAddKey = "add"
|
|
|
|
+ static let outlineRemoveKey = "remove"
|
|
static let outlineDemoteKey = "demote"
|
|
static let outlineDemoteKey = "demote"
|
|
static let outlinePromoteKey = "promote"
|
|
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 {
|
|
@objc func canPromote(outline ol: CPDFOutline) -> Bool {
|
|
return self.document?.canPromote(outline: ol) ?? false
|
|
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])
|
|
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) {
|
|
private func _undo_demote(outline ol: CPDFOutline, at index: UInt) {
|
|
(self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_promote(outline: ol, at: ol.index)
|
|
(self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_promote(outline: ol, at: ol.index)
|
|
|
|
|