|
@@ -45,10 +45,8 @@ extension KMLeftSideViewController {
|
|
|
self.tocOutlineView.botaDelegate = self
|
|
|
self.tocOutlineView.botaDataSource = self
|
|
|
self.tocOutlineView.tocDelegate = self
|
|
|
- // kKMPDFViewOutlineDragDataType
|
|
|
self.tocOutlineView.registerForDraggedTypes([.localDraggedTypes])
|
|
|
self.tocOutlineView.target = self
|
|
|
-// self.tocOutlineView.doubleAction = #selector(goToSelectedOutlineItem)
|
|
|
self.tocOutlineView.doubleAction = #selector(outlineContextMenuItemClicked_Rename)
|
|
|
}
|
|
|
|
|
@@ -129,35 +127,6 @@ extension KMLeftSideViewController {
|
|
|
targrtTextField?.becomeFirstResponder()
|
|
|
}
|
|
|
|
|
|
- func loadUnfoldDate(_ foldType: KMFoldType) {
|
|
|
- // 清空所有折叠数组
|
|
|
- self.allFoldNotes.removeAll()
|
|
|
-
|
|
|
- var mutableArray: [CPDFAnnotation] = []
|
|
|
- if self.noteSearchMode {
|
|
|
- for note in self.noteSearchArray {
|
|
|
- if note is CPDFMarkupAnnotation {
|
|
|
- mutableArray.append(note)
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- for section in self.annotations {
|
|
|
- for item in section.annotations ?? [] {
|
|
|
- if let note = item.annotation, note is CPDFMarkupAnnotation {
|
|
|
- mutableArray.append(note)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-// for note in self.notes {
|
|
|
-// if note is CPDFMarkupAnnotation {
|
|
|
-// mutableArray.append(note)
|
|
|
-// }
|
|
|
-// }
|
|
|
- self.canFoldNotes = mutableArray
|
|
|
- self.allFoldNotes = []
|
|
|
- }
|
|
|
-
|
|
|
func selectedRowIndexes() -> IndexSet {
|
|
|
var selectedIndexes = self.tocOutlineView.selectedRowIndexes
|
|
|
let clickedRow = self.tocOutlineView.clickedRow
|
|
@@ -169,6 +138,10 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
|
|
|
func editOutlineUI(_ editVC: KMOutlineEditViewController) {
|
|
|
+ guard let ol = editVC.outline else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if editVC.pageButton.state == .on {
|
|
|
let numberString = editVC.outlineTargetPageIndexTextField.stringValue
|
|
|
let idx = Int(numberString) ?? 1
|
|
@@ -178,22 +151,17 @@ extension KMLeftSideViewController {
|
|
|
if (newPage == nil) {
|
|
|
|
|
|
} else {
|
|
|
- if let outL = editVC.outline {
|
|
|
- let pageSize = newPage?.bounds(for: .cropBox).size ?? .zero
|
|
|
- if let dest = CPDFDestination(page: newPage, at: CGPointMake(pageSize.width, pageSize.height)) {
|
|
|
- self.changePDFOutlineDestination(dest, PDFoutline: outL)
|
|
|
- }
|
|
|
+ let pageSize = newPage?.bounds(for: .cropBox).size ?? .zero
|
|
|
+ if let dest = CPDFDestination(page: newPage, at: CGPointMake(pageSize.width, pageSize.height)) {
|
|
|
+ self.changePDFOutlineDestination(dest, PDFoutline: ol)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if editVC.urlButton.state == .on {
|
|
|
- guard let ol = editVC.outline else {
|
|
|
- return
|
|
|
- }
|
|
|
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 tLowerUrl.hasPrefix(kHTTPSPrefix) == false && tLowerUrl.hasPrefix(kFTPPrefix) == false && tLowerUrl.hasPrefix(kHTTPPrefix) == false && urlString.isEmpty == false {
|
|
|
+ urlString = "\(kHTTPPrefix)\(urlString)"
|
|
|
}
|
|
|
if let act = CPDFURLAction(url: urlString) {
|
|
|
if editVC.originalURLString != editVC.outlineURLTextField.stringValue {
|
|
@@ -203,25 +171,22 @@ extension KMLeftSideViewController {
|
|
|
} else if editVC.mailButton.state == .on {
|
|
|
var mailString = editVC.mailAddressTextField.stringValue
|
|
|
let tLowerStr = mailString.lowercased()
|
|
|
- if tLowerStr.hasPrefix("mailto:") == false {
|
|
|
- mailString = "mailto:\(mailString)"
|
|
|
+ if tLowerStr.hasPrefix(kEmailPrefix) == false {
|
|
|
+ mailString = "\(kEmailPrefix)\(mailString)"
|
|
|
}
|
|
|
|
|
|
if var urlAction = CPDFURLAction(url: mailString) {
|
|
|
if urlAction.url() == nil {
|
|
|
- urlAction = CPDFURLAction(url: "mailto:")
|
|
|
+ urlAction = CPDFURLAction(url: kEmailPrefix)
|
|
|
}
|
|
|
- if mailString != editVC.originalURLString && editVC.outline != nil {
|
|
|
- self.changePDFAction(urlAction, PDFOutline: editVC.outline!)
|
|
|
+ if mailString != editVC.originalURLString {
|
|
|
+ self.changePDFAction(urlAction, PDFOutline: ol)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if editVC.outlineNameTextView.string == editVC.originalLabel {
|
|
|
- return
|
|
|
- }
|
|
|
- if let outL = editVC.outline {
|
|
|
- self.renamePDFOutline(outL, label: editVC.outlineNameTextView.string)
|
|
|
+ if editVC.outlineNameTextView.string != editVC.originalLabel {
|
|
|
+ self.renamePDFOutline(ol, label: editVC.outlineNameTextView.string)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -299,7 +264,9 @@ extension KMLeftSideViewController {
|
|
|
func showSearchOutlineBlankState(_ toShowState: Bool) {
|
|
|
if (toShowState) {
|
|
|
let documentViewFrame = self.tocOutlineView.enclosingScrollView?.documentView?.frame ?? .zero
|
|
|
- self.leftSideEmptyVC.outlineSearchView.frame = CGRectMake((documentViewFrame.size.width - self.leftSideEmptyVC.outlineSearchView.bounds.size.width)/2.0, (documentViewFrame.size.height - self.leftSideEmptyVC.outlineSearchView.bounds.size.height)/2.0, self.leftSideEmptyVC.outlineSearchView.bounds.size.width, self.leftSideEmptyVC.outlineSearchView.bounds.size.height);
|
|
|
+ let width = self.leftSideEmptyVC.outlineSearchView.bounds.size.width
|
|
|
+ let height = self.leftSideEmptyVC.outlineSearchView.bounds.size.height
|
|
|
+ self.leftSideEmptyVC.outlineSearchView.frame = CGRectMake((documentViewFrame.size.width - width)/2.0, (documentViewFrame.size.height - height)/2.0, width, height)
|
|
|
self.tocOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.outlineSearchView)
|
|
|
self.leftSideEmptyVC.outlineSearchView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
|
|
|
} else {
|
|
@@ -323,8 +290,8 @@ extension KMLeftSideViewController {
|
|
|
guard let ol = self.tocOutlineView.selectedItem() as? CPDFOutline else {
|
|
|
return
|
|
|
}
|
|
|
- var attriString = NSMutableAttributedString()
|
|
|
- var attri = [NSAttributedString.Key.foregroundColor : KMAppearance.Layout.h0Color()]
|
|
|
+ let attriString = NSMutableAttributedString()
|
|
|
+ let attri = [NSAttributedString.Key.foregroundColor : KMAppearance.Layout.h0Color()]
|
|
|
attriString.append(.init(string: ol.label ?? "", attributes: attri))
|
|
|
|
|
|
let row = self.tocOutlineView.selectedRow
|
|
@@ -340,7 +307,7 @@ extension KMLeftSideViewController {
|
|
|
rowH = fmax(rowH, self.tocOutlineView.rowHeight) + 25
|
|
|
|
|
|
let view = self.tocOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
|
|
|
- var frame = view?.frame ?? .zero
|
|
|
+ let frame = view?.frame ?? .zero
|
|
|
view?.frame = NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, rowH)
|
|
|
self.tocOutlineView.reloadData()
|
|
|
}
|
|
@@ -458,7 +425,7 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @objc dynamic func changePDFAction(_ action: CPDFAction, PDFOutline outline: CPDFOutline) {
|
|
|
+ @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
|
|
|
}
|
|
@@ -545,6 +512,81 @@ extension KMLeftSideViewController {
|
|
|
// MARK: - Menu Actions
|
|
|
|
|
|
extension KMLeftSideViewController {
|
|
|
+ func outlineListMenu(_ menu: NSMenu) {
|
|
|
+ _ = menu.addItem(withTitle: NSLocalizedString("Add Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddEntry), target: self, tag: KMOutlineViewMenuItemTag.addEntry.rawValue)
|
|
|
+ _ = menu.addItem(withTitle: NSLocalizedString("Add Sub-Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddChildEntry), target: self, tag: KMOutlineViewMenuItemTag.addChild.rawValue)
|
|
|
+ _ = menu.addItem(withTitle: NSLocalizedString("Add To A Higher Level", comment: ""), action: #selector(outlineContextMenuItemClicked_AddAuntEntry), target: self, tag: KMOutlineViewMenuItemTag.addAunt.rawValue)
|
|
|
+ menu.addItem(.separator())
|
|
|
+ _ = menu.addItem(withTitle: NSLocalizedString("Delete", comment: ""), action: #selector(outlineContextMenuItemClicked_RemoveEntry), target: self, tag: KMOutlineViewMenuItemTag.remove.rawValue)
|
|
|
+ menu.addItem(.separator())
|
|
|
+ _ = menu.addItem(withTitle: NSLocalizedString("Edit", comment: ""), action: #selector(outlineContextMenuItemClicked_Edit), target: self, tag: KMOutlineViewMenuItemTag.edit.rawValue)
|
|
|
+ _ = menu.addItem(withTitle: NSLocalizedString("Change Destination", comment: ""), action: #selector(outlineContextMenuItemClicked_SetDestination), target: self, tag: KMOutlineViewMenuItemTag.setDestination.rawValue)
|
|
|
+ _ = menu.addItem(withTitle: NSLocalizedString("Rename", comment: ""), action: #selector(outlineContextMenuItemClicked_Rename), target: self, tag: KMOutlineViewMenuItemTag.rename.rawValue)
|
|
|
+ menu.addItem(.separator())
|
|
|
+ _ = menu.addItem(withTitle: NSLocalizedString("Promote", comment: ""), action: #selector(outlineContextMenuItemClicked_Promote), target: self, tag: KMOutlineViewMenuItemTag.promote.rawValue)
|
|
|
+ _ = menu.addItem(withTitle: NSLocalizedString("Demote", comment: ""), action: #selector(outlineContextMenuItemClicked_Demote), target: self, tag: KMOutlineViewMenuItemTag.demote.rawValue)
|
|
|
+ }
|
|
|
+
|
|
|
+ func outlineListValidateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
|
|
+ if self.isLocked() {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ let action = menuItem.action
|
|
|
+ if (self.isSearchOutlineMode) {
|
|
|
+ if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
|
|
|
+ action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
|
|
|
+ action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
|
|
|
+ action == #selector(outlineContextMenuItemClicked_Edit) ||
|
|
|
+ action == #selector(outlineContextMenuItemClicked_Rename)
|
|
|
+ ) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (self.tocOutlineView.selectedRowIndexes.count > 1) {
|
|
|
+ if (menuItem.tag == KMOutlineViewMenuItemTag.remove.rawValue) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ } else if (self.tocOutlineView.selectedRowIndexes.count > 0) {
|
|
|
+ if (action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
|
|
|
+ action == #selector(outlineContextMenuItemClicked_SetDestination)) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (self.tocOutlineView.clickedRow == -1) {
|
|
|
+ if (action == #selector(outlineContextMenuItemClicked_AddEntry)) {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let clickedOutline = self.tocOutlineView.item(atRow: self.tocOutlineView.clickedRow) as? CPDFOutline
|
|
|
+ if (action == #selector(outlineContextMenuItemClicked_Demote)) {
|
|
|
+ if let data = clickedOutline {
|
|
|
+ return self.pdfDocument()?.canDemote(outline: data) ?? false
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (action == #selector(outlineContextMenuItemClicked_Promote)) {
|
|
|
+ if let data = clickedOutline {
|
|
|
+ return self.pdfDocument()?.canPromote(outline: data) ?? false
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
|
|
|
+ let parentOutLine = clickedOutline?.parent
|
|
|
+ let grandparentOutLine = parentOutLine?.parent
|
|
|
+ if (grandparentOutLine != nil) {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
//添加子节点
|
|
|
|
|
|
@objc func outlineContextMenuItemClicked_AddChildEntry(_ sender: AnyObject?) {
|
|
@@ -595,7 +637,6 @@ extension KMLeftSideViewController {
|
|
|
let res = await KMAlertTool.runModel(style: .informational, message: KMLocalizedString("Are you sure you want to set the destination as the current location?", nil), buttons: [KMLocalizedString("Yes", nil), KMLocalizedString("No", nil)])
|
|
|
if (res == .alertFirstButtonReturn) {
|
|
|
self.changePDFOutlineDestination(self.currentDestination(), PDFoutline: ol)
|
|
|
-// self.tocOutlineView.reloadData()
|
|
|
let idx = self.tocOutlineView.row(forItem: ol)
|
|
|
self.tocOutlineView.km_safe_selectRowIndexes(.init(integer: idx), byExtendingSelection: false)
|
|
|
}
|