|
@@ -174,14 +174,13 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
|
|
|
}
|
|
|
|
|
|
@objc private func removeAllOutline() {
|
|
|
- var selectedPDFOutlineArr = [CPDFOutline]();
|
|
|
- for index in 0 ... self.listView.document.outlineRoot().numberOfChildren-1 {
|
|
|
+ var outlineItems: [KMOutlineItem] = []
|
|
|
+ for index in 0...self.listView.document.outlineRoot().numberOfChildren-1 {
|
|
|
let outline : CPDFOutline = self.listView.document.outlineRoot().child(at: index)
|
|
|
- selectedPDFOutlineArr.append(outline)
|
|
|
- }
|
|
|
- for tOutline in selectedPDFOutlineArr {
|
|
|
- self.removePDFOutline(outline: tOutline, toIndex: NSInteger(tOutline.index), atParent: tOutline.parent)
|
|
|
+ outlineItems.append(KMOutlineItem(toIndex: Int(outline.index), outline: outline, parent: outline.parent))
|
|
|
}
|
|
|
+
|
|
|
+ self.deleteOutline(outlineItems: outlineItems)
|
|
|
}
|
|
|
|
|
|
@objc private func addItemAction() {
|
|
@@ -250,7 +249,7 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
|
|
|
} else {
|
|
|
var outlineItems: [KMOutlineItem] = []
|
|
|
for index in selectedRowIndexes {
|
|
|
- var outline: CPDFOutline = self.outlineView.item(atRow: index) as! CPDFOutline
|
|
|
+ let outline: CPDFOutline = self.outlineView.item(atRow: index) as! CPDFOutline
|
|
|
outlineItems.append(KMOutlineItem(toIndex: index, outline: outline, parent: outline.parent))
|
|
|
}
|
|
|
self.deleteOutline(outlineItems: outlineItems)
|
|
@@ -284,7 +283,7 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
|
|
|
|
|
|
@objc func changeItemAction() {
|
|
|
if self.outlineView.clickedRow >= 0 {
|
|
|
- let outline = self.outlineView.item(atRow: self.outlineView.clickedRow)
|
|
|
+ let outline: CPDFOutline = self.outlineView.item(atRow: self.outlineView.clickedRow) as! CPDFOutline
|
|
|
let alter = NSAlert()
|
|
|
alter.alertStyle = NSAlert.Style.informational
|
|
|
alter.messageText = NSLocalizedString("Are you sure you want to set the target location of the selected outline to the current page?", comment: "")
|
|
@@ -292,7 +291,7 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
|
|
|
alter.addButton(withTitle: NSLocalizedString("No", comment:""))
|
|
|
let modlres = alter.runModal()
|
|
|
if modlres == NSApplication.ModalResponse.alertFirstButtonReturn {
|
|
|
- self.setPDFOutline(outline: outline as? CPDFOutline, destination: self.listView.currentDestination)
|
|
|
+ self.changeLocation(outline: outline, destination: self.listView.currentDestination)
|
|
|
}
|
|
|
} else {
|
|
|
__NSBeep()
|
|
@@ -474,17 +473,6 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func removePDFOutline(outline:CPDFOutline! , toIndex index : NSInteger , atParent parent : CPDFOutline!) {
|
|
|
- outline.removeFromParent()
|
|
|
- self.outlineView.reloadData()
|
|
|
- self.outlineView.expandItem(parent)
|
|
|
- }
|
|
|
-
|
|
|
- func setPDFOutline(outline:CPDFOutline! , destination : CPDFDestination!) {
|
|
|
- outline.destination = destination
|
|
|
- self.outlineView.reloadData()
|
|
|
- }
|
|
|
-
|
|
|
func editOutlineUI(editVC : KMOutlineEditViewController!) {
|
|
|
if editVC.pageButton.state == NSControl.StateValue.on {
|
|
|
let index = Int(editVC.outlineTargetPageIndexTextField.stringValue)!
|
|
@@ -788,15 +776,14 @@ extension KMOutlineViewController : NSPopoverDelegate {
|
|
|
|
|
|
//MARK: undoRedo
|
|
|
extension KMOutlineViewController {
|
|
|
- func changeLocation(oldBookMark: KMBookMark, newBookMark: KMBookMark) {
|
|
|
- self.listView.document.removeBookmark(forPageIndex: oldBookMark.index)
|
|
|
- self.listView.document.addBookmark(newBookMark.label, forPageIndex: newBookMark.index)
|
|
|
-
|
|
|
- self.reloadData()
|
|
|
- self.listView.setNeedsDisplayForVisiblePages()
|
|
|
+ func changeLocation(outline: CPDFOutline, destination: CPDFDestination) {
|
|
|
+ let temp = CPDFDestination(document: outline.destination.document, pageIndex: outline.destination.pageIndex, at: outline.destination.point, zoom: outline.destination.zoom)
|
|
|
+
|
|
|
+ outline.destination = destination
|
|
|
+ self.outlineView.reloadData()
|
|
|
|
|
|
self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
|
|
|
- self.changeLocation(oldBookMark: newBookMark, newBookMark: oldBookMark)
|
|
|
+ self.changeLocation(outline: outline, destination: temp!)
|
|
|
}
|
|
|
}
|
|
|
|