|
@@ -230,6 +230,9 @@ class KMLeftSideViewController: KMSideViewController {
|
|
|
|
|
|
private var allFoldNotes: [CPDFAnnotation] = []
|
|
|
|
|
|
+ var renamePDFOutline: CPDFOutline?
|
|
|
+ var renamePDFOutlineTextField: NSTextField?
|
|
|
+
|
|
|
override func loadView() {
|
|
|
super.loadView()
|
|
|
|
|
@@ -901,8 +904,6 @@ class KMLeftSideViewController: KMSideViewController {
|
|
|
frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
|
|
|
self.snapshotTableView.enclosingScrollView?.frame = frame
|
|
|
|
|
|
-// [self updateOutlineSelection];
|
|
|
-
|
|
|
let view = self.tocOutlineView.enclosingScrollView!
|
|
|
let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
|
|
|
|
|
@@ -910,6 +911,7 @@ class KMLeftSideViewController: KMSideViewController {
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
self.tocOutlineView.reloadData()
|
|
|
+ self.updateOutlineSelection()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1407,52 +1409,6 @@ class KMLeftSideViewController: KMSideViewController {
|
|
|
self.outlineSearchField.becomeFirstResponder()
|
|
|
}
|
|
|
|
|
|
-// @objc func outlineContextMenuItemClicked_AddEntry(_ sender: NSMenuItem) {
|
|
|
-// NSMutableArray *PDFOutlineArray = [[NSMutableArray new] autorelease];
|
|
|
-// NSIndexSet *rowSet = [self selectedRowIndexes] ;
|
|
|
-//
|
|
|
-// [rowSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-// [PDFOutlineArray addObject:[leftSideController.tocOutlineView itemAtRow:idx]];
|
|
|
-// }];
|
|
|
-//
|
|
|
-// if (PDFOutlineArray.count == 0) {
|
|
|
-// PDFOutline *lastPDFLine = [leftSideController.tocOutlineView itemAtRow:leftSideController.tocOutlineView.numberOfRows - 1];
|
|
|
-//
|
|
|
-// PDFOutline *rootPDFOutline;
|
|
|
-// if (lastPDFLine) {
|
|
|
-// while (lastPDFLine.parent) {
|
|
|
-// lastPDFLine = lastPDFLine.parent;
|
|
|
-// }
|
|
|
-// rootPDFOutline = lastPDFLine;
|
|
|
-// } else {
|
|
|
-// rootPDFOutline = self.pdfView.document.outlineRoot;
|
|
|
-// if (!rootPDFOutline) {
|
|
|
-// rootPDFOutline = [[[PDFOutline alloc] init] autorelease];
|
|
|
-// [self.pdfView.document setOutlineRoot:rootPDFOutline];
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
|
|
|
-// addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
|
|
|
-// addOutLine.destination = self.pdfView.currentDestination;
|
|
|
-// [self addoutlineWithParent:rootPDFOutline addOutline:addOutLine index:rootPDFOutline.numberOfChildren needExpand:NO];
|
|
|
-//
|
|
|
-// } else {
|
|
|
-// PDFOutline *currentPDFline = PDFOutlineArray.lastObject;
|
|
|
-// NSInteger currentIndex = currentPDFline.index;
|
|
|
-// PDFOutline *parent;
|
|
|
-// parent = currentPDFline.parent;
|
|
|
-//
|
|
|
-// PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
|
|
|
-// addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
|
|
|
-// addOutLine.destination = self.pdfView.currentDestination;
|
|
|
-// [self addoutlineWithParent:parent addOutline:addOutLine index:currentIndex + 1 needExpand:NO];
|
|
|
-// [self.leftSideController.tocOutlineView scrollRowToVisible:currentIndex + 1];
|
|
|
-// [self.leftSideController.tocOutlineView deselectRow:currentIndex+1];
|
|
|
-//
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
@IBAction func toc_expandAllComments(_ sender: AnyObject?) {
|
|
|
if (self.tocType == .unfold) {
|
|
|
return
|
|
@@ -5539,7 +5495,49 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
|
|
|
@objc func outlineContextMenuItemClicked_AddEntry(_ sender: AnyObject?) {
|
|
|
- KMPrint("KMLeftSideViewController-outlineContextMenuItemClicked_AddEntry...")
|
|
|
+ var 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@objc func outlineContextMenuItemClicked_AddChildEntry(_ sender: AnyObject?) {
|
|
@@ -5924,6 +5922,53 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
return ""
|
|
|
}
|
|
|
+
|
|
|
+ // MARK: - Outline
|
|
|
+
|
|
|
+ func selectedRowIndexes() -> IndexSet {
|
|
|
+ var selectedIndexes = self.tocOutlineView.selectedRowIndexes
|
|
|
+ let clickedRow = self.tocOutlineView.clickedRow
|
|
|
+ if clickedRow != -1 && selectedIndexes.contains(clickedRow) == false {
|
|
|
+ var indexes = IndexSet(integer: clickedRow)
|
|
|
+ selectedIndexes = indexes
|
|
|
+ }
|
|
|
+ return selectedIndexes
|
|
|
+ }
|
|
|
+
|
|
|
+ func addoutline(parent parentOutline: CPDFOutline?, addOutline: CPDFOutline, index: Int, needExpand: Bool) {
|
|
|
+ var tempO = 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!
|
|
|
+ }
|
|
|
+
|
|
|
+// [[[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: tempO)
|
|
|
+ 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];
|
|
|
+// });
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|