|
@@ -142,10 +142,89 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ func editOutlineUI(_ editVC: KMOutlineEditViewController) {
|
|
|
+ if editVC.pageButton.state == .on {
|
|
|
+ let numberString = editVC.outlineTargetPageIndexTextField.stringValue
|
|
|
+ let idx = Int(numberString) ?? 1
|
|
|
+ let newPage = editVC.pdfView.document.page(at: UInt(idx-1))
|
|
|
+ let originalPage = editVC.originalDestination?.page()
|
|
|
+ if let data = newPage?.isEqual(to: originalPage), data {
|
|
|
+ //新page不存在
|
|
|
+ if (newPage == nil) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ let pageSize = newPage?.bounds(for: .cropBox).size ?? .zero
|
|
|
+ if let destination = CPDFDestination(page: newPage, at: CGPointMake(pageSize.width, pageSize.height)) {
|
|
|
+ self.changePDFOutlineDestination(destination, PDFoutline: editVC.outline)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if editVC.urlButton.state == .on {
|
|
|
+ var urlString = editVC.outlineURLTextField.stringValue
|
|
|
+ let tLowerUrl = urlString.lowercased()
|
|
|
+ if tLowerUrl.hasPrefix("https://") == false && tLowerUrl.hasPrefix("ftp://") == false && tLowerUrl.hasPrefix("http://") == false && urlString.isEmpty == false {
|
|
|
+ urlString = "http://\(urlString)"
|
|
|
+ }
|
|
|
+
|
|
|
+ if let urlAction = CPDFURLAction(url: urlString) {
|
|
|
+ if editVC.originalURLString != editVC.outlineURLTextField.stringValue {
|
|
|
+ self.changePDFAction(urlAction, PDFOutline: editVC.outline)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if editVC.mailButton.state == .on {
|
|
|
+ var mailString = editVC.mailAddressTextField.stringValue
|
|
|
+ let tLowerStr = mailString.lowercased()
|
|
|
+ if tLowerStr.hasPrefix("mailto:") == false {
|
|
|
+ mailString = "mailto:\(mailString)"
|
|
|
+ }
|
|
|
+
|
|
|
+ if var urlAction = CPDFURLAction(url: mailString) {
|
|
|
+ if urlAction.url() == nil {
|
|
|
+ urlAction = CPDFURLAction(url: "mailto:")
|
|
|
+ }
|
|
|
+ if mailString != editVC.originalURLString {
|
|
|
+ self.changePDFAction(urlAction, PDFOutline: editVC.outline)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if editVC.outlineNameTextView.string == editVC.originalLabel {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ self.renamePDFOutline(editVC.outline, label: editVC.outlineNameTextView.string)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Undo & Redo
|
|
|
+
|
|
|
+extension KMLeftSideViewController {
|
|
|
@objc dynamic func changePDFOutlineDestination(_ destination: CPDFDestination, PDFoutline outline: CPDFOutline) {
|
|
|
(self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).changePDFOutlineDestination(outline.destination, PDFoutline: outline)
|
|
|
outline.destination = destination
|
|
|
}
|
|
|
+
|
|
|
+ @objc dynamic func changePDFAction(_ action: CPDFAction, PDFOutline outline: CPDFOutline) {
|
|
|
+ (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).changePDFAction(outline.action, PDFOutline: outline)
|
|
|
+ outline.action = action
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc dynamic func renamePDFOutline(_ outline: CPDFOutline, label: String) {
|
|
|
+ if (self.isRenameNoteOutline) {
|
|
|
+ if outline is CPDFAnnotation {
|
|
|
+// if([outline isKindOfClass:[PDFAnnotation class]]) {
|
|
|
+// PDFAnnotation *annotation = (PDFAnnotation *)outline;
|
|
|
+// annotation.string = label;
|
|
|
+// [rightSideController.noteOutlineView reloadData];
|
|
|
+// [rightSideController.noteOutlineView selectRowIndexes:[[[NSIndexSet alloc] initWithIndex:[rightSideController.noteOutlineView rowForItem:outline]] autorelease] byExtendingSelection:NO];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).renamePDFOutline(outline, label: outline.label)
|
|
|
+ outline.label = label
|
|
|
+ self.tocOutlineView.reloadData()
|
|
|
+ self.tocOutlineView.km_selectItem(outline, byExtendingSelection: false)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// MARK: - Menu Actions
|
|
@@ -227,4 +306,18 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //弹出菜单
|
|
|
+
|
|
|
+ @objc func outlineContextMenuItemClicked_Edit(_ sender: AnyObject?) {
|
|
|
+ let popover = NSPopover()
|
|
|
+ popover.delegate = self
|
|
|
+ let targetOutline: CPDFOutline? = self.tocOutlineView.km.clickedItem()
|
|
|
+ let outlineEditViewController = KMOutlineEditViewController(outline: targetOutline, document: self.listView)
|
|
|
+ let cell = self.tocOutlineView.rowView(atRow: self.tocOutlineView.clickedRow, makeIfNecessary: true)
|
|
|
+ popover.contentViewController = outlineEditViewController
|
|
|
+ popover.animates = true
|
|
|
+ popover.behavior = .transient
|
|
|
+ popover.show(relativeTo: cell?.bounds ?? .zero, of: cell!, preferredEdge: .minX)
|
|
|
+ }
|
|
|
}
|