|
@@ -96,55 +96,6 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
return selectedIndexes
|
|
|
}
|
|
|
-
|
|
|
- func addoutline(parent parentOutline: CPDFOutline?, addOutline: CPDFOutline, index: Int, needExpand: Bool) {
|
|
|
- var tempO: CPDFOutline? = addOutline
|
|
|
- if addOutline.label != nil {
|
|
|
- parentOutline?.insertChild(addOutline, at: UInt(index))
|
|
|
- } else {
|
|
|
- let outline = parentOutline?.insertChild(at: UInt(index))
|
|
|
- outline?.label = String(format: "%@ %ld", KMLocalizedString("Page", nil), self.listView.currentPageIndex+1)
|
|
|
- outline?.destination = self.listView.currentDestination
|
|
|
- tempO = outline
|
|
|
- }
|
|
|
-
|
|
|
- guard let outline = tempO else {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
-// [[[self.document undoManager] prepareWithInvocationTarget:self] removeOutlineWithParent:parentOutline removeOutline:addOutline index:index needExpand:needExpand];
|
|
|
-
|
|
|
- self.view.window?.makeFirstResponder(nil)
|
|
|
-
|
|
|
- Task { @MainActor in
|
|
|
- self.tocOutlineView.reloadData()
|
|
|
-
|
|
|
- if (needExpand) {
|
|
|
- self.tocOutlineView.expandItem(parentOutline)
|
|
|
- }
|
|
|
- let idx = self.tocOutlineView.row(forItem: outline)
|
|
|
- self.tocOutlineView.selectRowIndexes(IndexSet(integer: idx), byExtendingSelection: false)
|
|
|
-
|
|
|
- self.newAddOutlineEntryEditingMode(index)
|
|
|
- }
|
|
|
-
|
|
|
-// __block PDFOutline *taddOutline = [addOutline retain];
|
|
|
-// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
-// [self.leftSideController.tocOutlineView scrollRowToVisible:[leftSideController.tocOutlineView rowForItem:taddOutline]];
|
|
|
-// [taddOutline release];
|
|
|
-// });
|
|
|
- }
|
|
|
-
|
|
|
- func removeOutline(parent parentOutline: CPDFOutline?, removeOutline: CPDFOutline, index: Int, needExpand: Bool) {
|
|
|
-// [[[self.document undoManager] prepareWithInvocationTarget:self] addoutlineWithParent:parentOutline addOutline:removeOutline index:index needExpand:YES];
|
|
|
- removeOutline.removeFromParent()
|
|
|
- if (needExpand) {
|
|
|
- self.tocOutlineView.expandItem(parentOutline)
|
|
|
- }
|
|
|
- Task { @MainActor in
|
|
|
- self.tocOutlineView.reloadData()
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
func editOutlineUI(_ editVC: KMOutlineEditViewController) {
|
|
|
if editVC.pageButton.state == .on {
|
|
@@ -199,7 +150,51 @@ extension KMLeftSideViewController {
|
|
|
self.renamePDFOutline(editVC.outline, label: editVC.outlineNameTextView.string)
|
|
|
}
|
|
|
|
|
|
+ @objc func outlineContextMenuItemClicked_AddEntry(_ sender: AnyObject?) {
|
|
|
+ let PDFOutlineArray = NSMutableArray()
|
|
|
+ let rowSet = self.selectedRowIndexes()
|
|
|
|
|
|
+ for idx in rowSet {
|
|
|
+ PDFOutlineArray.add(self.tocOutlineView.item(atRow: idx))
|
|
|
+ }
|
|
|
+
|
|
|
+ if (PDFOutlineArray.count == 0) {
|
|
|
+ var lastPDFLine = self.tocOutlineView.item(atRow: self.tocOutlineView.numberOfRows-1) as? CPDFOutline
|
|
|
+
|
|
|
+ var rootPDFOutline: CPDFOutline?
|
|
|
+ if (lastPDFLine != nil) {
|
|
|
+ while (lastPDFLine!.parent != nil) {
|
|
|
+ lastPDFLine = lastPDFLine?.parent
|
|
|
+ }
|
|
|
+ rootPDFOutline = lastPDFLine
|
|
|
+ } else {
|
|
|
+ rootPDFOutline = self.listView.document.outlineRoot()
|
|
|
+ if ((rootPDFOutline == nil)) {
|
|
|
+// rootPDFOutline = CPDFOutline()
|
|
|
+// self.listView.document.setOutlineRoot(rootPDFOutline)
|
|
|
+ rootPDFOutline = self.listView.document.setNewOutlineRoot()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let addOutLine = CPDFOutline()
|
|
|
+ addOutLine.label = String(format: "%@ %ld", KMLocalizedString("Page", nil), self.listView.currentPageIndex+1)
|
|
|
+ addOutLine.destination = self.listView.currentDestination
|
|
|
+ self.addoutline(parent: rootPDFOutline, addOutline: addOutLine, index: Int(rootPDFOutline?.numberOfChildren ?? 0), needExpand: false)
|
|
|
+ } else {
|
|
|
+ let currentPDFline = PDFOutlineArray.lastObject as? CPDFOutline
|
|
|
+ let currentIndex = currentPDFline?.index ?? 0
|
|
|
+ var parent: CPDFOutline?
|
|
|
+ parent = currentPDFline?.parent
|
|
|
+
|
|
|
+ let addOutLine = CPDFOutline()
|
|
|
+
|
|
|
+ addOutLine.label = String(format: "%@ %ld", KMLocalizedString("Page", nil), self.listView.currentPageIndex+1)
|
|
|
+ addOutLine.destination = self.listView.currentDestination
|
|
|
+ self.addoutline(parent: parent, addOutline: addOutLine, index: Int(currentIndex) + 1, needExpand: false)
|
|
|
+ self.tocOutlineView.scrollRowToVisible(Int(currentIndex) + 1)
|
|
|
+ self.tocOutlineView.deselectRow(Int(currentIndex)+1)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// MARK: - Undo & Redo
|
|
@@ -269,6 +264,54 @@ extension KMLeftSideViewController {
|
|
|
|
|
|
self.tocOutlineView.km_selectItem(promoteOutline, byExtendingSelection: false)
|
|
|
}
|
|
|
+
|
|
|
+ @objc dynamic func addoutline(parent parentOutline: CPDFOutline?, addOutline: CPDFOutline, index: Int, needExpand: Bool) {
|
|
|
+ var tempO: CPDFOutline? = addOutline
|
|
|
+ if addOutline.label != nil {
|
|
|
+ parentOutline?.insertChild(addOutline, at: UInt(index))
|
|
|
+ } else {
|
|
|
+ let outline = parentOutline?.insertChild(at: UInt(index))
|
|
|
+ outline?.label = String(format: "%@ %ld", KMLocalizedString("Page", nil), self.listView.currentPageIndex+1)
|
|
|
+ outline?.destination = self.listView.currentDestination
|
|
|
+ tempO = outline
|
|
|
+ }
|
|
|
+
|
|
|
+ guard let outline = tempO else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).removeOutline(parent: parentOutline, removeOutline: outline, index: index, needExpand: needExpand)
|
|
|
+ self.view.window?.makeFirstResponder(nil)
|
|
|
+
|
|
|
+ Task { @MainActor in
|
|
|
+ self.tocOutlineView.reloadData()
|
|
|
+
|
|
|
+ if (needExpand) {
|
|
|
+ self.tocOutlineView.expandItem(parentOutline)
|
|
|
+ }
|
|
|
+ let idx = self.tocOutlineView.row(forItem: outline)
|
|
|
+ self.tocOutlineView.selectRowIndexes(IndexSet(integer: idx), byExtendingSelection: false)
|
|
|
+
|
|
|
+ self.newAddOutlineEntryEditingMode(index)
|
|
|
+ }
|
|
|
+
|
|
|
+// __block PDFOutline *taddOutline = [addOutline retain];
|
|
|
+// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+// [self.leftSideController.tocOutlineView scrollRowToVisible:[leftSideController.tocOutlineView rowForItem:taddOutline]];
|
|
|
+// [taddOutline release];
|
|
|
+// });
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc dynamic func removeOutline(parent parentOutline: CPDFOutline?, removeOutline: CPDFOutline, index: Int, needExpand: Bool) {
|
|
|
+ (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).addoutline(parent: parentOutline, addOutline: removeOutline, index: index, needExpand: true)
|
|
|
+ removeOutline.removeFromParent()
|
|
|
+ if (needExpand) {
|
|
|
+ self.tocOutlineView.expandItem(parentOutline)
|
|
|
+ }
|
|
|
+ Task { @MainActor in
|
|
|
+ self.tocOutlineView.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// MARK: - Menu Actions
|
|
@@ -310,7 +353,7 @@ extension KMLeftSideViewController {
|
|
|
let addOutLine = CPDFOutline()
|
|
|
addOutLine.label = String(format: "%@ %ld", KMLocalizedString("Page", nil), "\(self.listView.currentPageIndex + 1)")
|
|
|
addOutLine.destination = self.listView.currentDestination
|
|
|
- self.addoutline(parent: grandfatherOutLine, addOutline: addOutLine, index: Int(fatherOutLine?.numberOfChildren ?? 0) + 1, needExpand: false)
|
|
|
+ self.addoutline(parent: grandfatherOutLine, addOutline: addOutLine, index: Int(fatherOutLine?.index ?? 0) + 1, needExpand: false)
|
|
|
}
|
|
|
}
|
|
|
|