|
@@ -80,7 +80,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
|
|
|
handdler.delegate = self
|
|
|
|
|
|
- self.addOutlineMenu()
|
|
|
titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold")
|
|
|
self.topView.wantsLayer = true
|
|
|
|
|
@@ -178,44 +177,8 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(KMPDFViewCurrentPageDidChangedNotification), name: NSNotification.Name.init(rawValue: "KMPDFViewCurrentPageDidChanged"), object: nil)
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- private func addOutlineMenu(){
|
|
|
- moreMenu.addItem(withTitle: NSLocalizedString("Expand All", comment: ""), action: #selector(expandAllComments), target: self, tag: 0)
|
|
|
- moreMenu.addItem(withTitle: NSLocalizedString("Collapse All", comment: ""), action: #selector(collapseAllComments), target: self, tag: 1)
|
|
|
- moreMenu.addItem(withTitle: NSLocalizedString("Remove All Outlines", comment: ""), action: #selector(removeAllOutlineItem), target: self, tag: 2)
|
|
|
- }
|
|
|
|
|
|
func addRightMenu(view: NSView, event: NSEvent) {
|
|
|
- let menus : NSMenu = NSMenu(title: "")
|
|
|
- let addItem = self.menuItemWithTitle(title: NSLocalizedString("Add Item", comment: ""), action: #selector(addItemAction))
|
|
|
- let addChildItem = self.menuItemWithTitle(title: NSLocalizedString("Add Sub-Item", comment: ""), action: #selector(addChildItemAction))
|
|
|
- let addHigherItem = self.menuItemWithTitle(title: NSLocalizedString("Add A Higher Level", comment: ""), action: #selector(addHigherItemAction))
|
|
|
- let deleteItem = self.menuItemWithTitle(title: NSLocalizedString("Delete", comment: ""), action: #selector(deleteItemAction))
|
|
|
-// let editItem = self.menuItemWithTitle(title: NSLocalizedString("Edit", comment: ""), action: #selector(editItemAction))
|
|
|
- let renameItem = self.menuItemWithTitle(title: NSLocalizedString("Rename", comment: ""), action: #selector(renameItemAction))
|
|
|
- let changeItem = self.menuItemWithTitle(title: NSLocalizedString("Change Destination", comment: ""), action: #selector(changeItemAction))
|
|
|
- let promoteItem = self.menuItemWithTitle(title: NSLocalizedString("Promote", comment: ""), action: #selector(promoteItemAction))
|
|
|
- let demoteItem = self.menuItemWithTitle(title: NSLocalizedString("Demote", comment: ""), action: #selector(demoteItemAction))
|
|
|
- menus.addItem(addItem)
|
|
|
- menus.addItem(addChildItem)
|
|
|
- menus.addItem(addHigherItem)
|
|
|
- menus.addItem(NSMenuItem.separator())
|
|
|
- menus.addItem(deleteItem)
|
|
|
- menus.addItem(NSMenuItem.separator())
|
|
|
-// menus.addItem(editItem)
|
|
|
- menus.addItem(renameItem)
|
|
|
- menus.addItem(changeItem)
|
|
|
- menus.addItem(NSMenuItem.separator())
|
|
|
- menus.addItem(promoteItem)
|
|
|
- menus.addItem(demoteItem)
|
|
|
-
|
|
|
-// let point = view.convert(event.locationInWindow, from: nil)
|
|
|
-// menus.popUp(positioning: nil, at: point, in: view)
|
|
|
-
|
|
|
-// let idxs = self?.bookTableView.selectedRowIndexes.count ?? 0
|
|
|
-//
|
|
|
-// let tempView = self?.bookTableView.rowView(atRow: row, makeIfNecessary: false)
|
|
|
let point = event.locationInWindow
|
|
|
let tempView = view
|
|
|
var viewHeight: CGFloat = 0
|
|
@@ -240,10 +203,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
}
|
|
|
|
|
|
if self.BOTAOutlineView.outlineView.selectedRowIndexes.count > 1 {
|
|
|
-// if action == #selector(deleteItemAction) {
|
|
|
-// return true
|
|
|
-// }
|
|
|
-// return false
|
|
|
for data in menuItemArr {
|
|
|
if data.text == KMLocalizedString("Delete") {
|
|
|
data.isDisabled = false
|
|
@@ -265,9 +224,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
}
|
|
|
return
|
|
|
} else if self.BOTAOutlineView.outlineView.selectedRowIndexes.count > 0 {
|
|
|
-// if action == #selector(addChildItemAction) || action == #selector(changeItemAction) {
|
|
|
-// return true
|
|
|
-// }
|
|
|
for data in menuItemArr {
|
|
|
if data.text == KMLocalizedString("Add Sub-Item") || data.text == KMLocalizedString("Change Destination") {
|
|
|
data.isDisabled = false
|
|
@@ -277,11 +233,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
if self.BOTAOutlineView.outlineView.clickedRow == -1 {
|
|
|
-// if action == #selector(addItemAction) {
|
|
|
-// return true
|
|
|
-// } else {
|
|
|
-// return false
|
|
|
-// }
|
|
|
for data in menuItemArr {
|
|
|
if data.text == KMLocalizedString("Add Item") {
|
|
|
data.isDisabled = false
|
|
@@ -292,9 +243,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
} else {
|
|
|
let outlineItem : KMBOTAOutlineItem = self.BOTAOutlineView.outlineView.item(atRow: self.BOTAOutlineView.outlineView.clickedRow) as! KMBOTAOutlineItem
|
|
|
if outlineItem.outline.index > 0 {
|
|
|
-// if action == #selector(demoteItemAction) {
|
|
|
-// return true
|
|
|
-// }
|
|
|
for data in menuItemArr {
|
|
|
if data.text == KMLocalizedString("Demote") {
|
|
|
data.isDisabled = false
|
|
@@ -303,9 +251,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
-// if action == #selector(demoteItemAction) {
|
|
|
-// return false
|
|
|
-// }
|
|
|
for data in menuItemArr {
|
|
|
if data.text == KMLocalizedString("Demote") {
|
|
|
data.isDisabled = true
|
|
@@ -318,11 +263,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
let parentOutline = outlineItem.outline.parent
|
|
|
let grandparentOutline = parentOutline?.parent
|
|
|
if grandparentOutline != nil {
|
|
|
-// if action == #selector(addHigherItemAction) {
|
|
|
-// return true
|
|
|
-// } else if action == #selector(promoteItemAction) {
|
|
|
-// return true
|
|
|
-// }
|
|
|
for data in menuItemArr {
|
|
|
if data.text == KMLocalizedString("Add A Higher Level") || data.text == KMLocalizedString("Promote") {
|
|
|
data.isDisabled = false
|
|
@@ -331,11 +271,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
-// if action == #selector(addHigherItemAction) {
|
|
|
-// return false
|
|
|
-// } else if action == #selector(promoteItemAction) {
|
|
|
-// return false
|
|
|
-// }
|
|
|
for data in menuItemArr {
|
|
|
if data.text == KMLocalizedString("Add A Higher Level") || data.text == KMLocalizedString("Promote") {
|
|
|
data.isDisabled = true
|
|
@@ -360,12 +295,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func menuItemWithTitle(title:String, action:Selector?) -> NSMenuItem {
|
|
|
- let menuItem = NSMenuItem.init(title: title as String, action: action, keyEquivalent: "")
|
|
|
- menuItem.target = self
|
|
|
- return menuItem
|
|
|
- }
|
|
|
-
|
|
|
func reloadData() {
|
|
|
self.BOTAOutlineView.reloadData(expandItemType: .none)
|
|
|
}
|
|
@@ -721,11 +650,6 @@ extension KMOutlineViewController {
|
|
|
self.addItemAction()
|
|
|
}
|
|
|
|
|
|
- @IBAction func moreButton_click(_ sender: NSButton) {
|
|
|
- let rect = sender.convert(sender.bounds, to: self.view)
|
|
|
- moreMenu.popUp(positioning: nil, at: NSPoint(x: rect.origin.x, y: rect.origin.y-10), in: self.view)
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
@IBAction func escButtonAction(_ sender: Any) {
|
|
|
self.cancelSelect()
|
|
@@ -788,7 +712,6 @@ extension KMOutlineViewController {
|
|
|
}
|
|
|
|
|
|
func updateOutlineSelection() {
|
|
|
- KMPrint("updateOutlineSelection")
|
|
|
let currentPageIndex = self.handdler.currentPageIndex
|
|
|
let numRows = self.BOTAOutlineView.outlineView.numberOfRows
|
|
|
if numRows > 0 {
|
|
@@ -978,62 +901,6 @@ extension KMOutlineViewController: NSPopoverDelegate {
|
|
|
extension KMOutlineViewController: NSMenuDelegate, NSMenuItemValidation {
|
|
|
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
|
|
let action = menuItem.action
|
|
|
- if action == #selector(addItemAction) ||
|
|
|
- action == #selector(addChildItemAction) ||
|
|
|
- action == #selector(addHigherItemAction) ||
|
|
|
- action == #selector(deleteItemAction) ||
|
|
|
- action == #selector(editItemAction) ||
|
|
|
- action == #selector(changeItemAction) ||
|
|
|
- action == #selector(renameItemAction) ||
|
|
|
- action == #selector(promoteItemAction) ||
|
|
|
- action == #selector(demoteItemAction) {
|
|
|
- if self.BOTAOutlineView.outlineView.selectedRowIndexes.count > 1 {
|
|
|
- if action == #selector(deleteItemAction) {
|
|
|
- return true
|
|
|
- }
|
|
|
- return false
|
|
|
- } else if self.BOTAOutlineView.outlineView.selectedRowIndexes.count > 0 {
|
|
|
- if action == #selector(addChildItemAction) || action == #selector(changeItemAction) {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- if self.BOTAOutlineView.outlineView.clickedRow == -1 {
|
|
|
- if action == #selector(addItemAction) {
|
|
|
- return true
|
|
|
- } else {
|
|
|
- return false
|
|
|
- }
|
|
|
- } else {
|
|
|
- let outlineItem : KMBOTAOutlineItem = self.BOTAOutlineView.outlineView.item(atRow: self.BOTAOutlineView.outlineView.clickedRow) as! KMBOTAOutlineItem
|
|
|
- if outlineItem.outline.index > 0 {
|
|
|
- if action == #selector(demoteItemAction) {
|
|
|
- return true
|
|
|
- }
|
|
|
- } else {
|
|
|
- if action == #selector(demoteItemAction) {
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let parentOutline = outlineItem.outline.parent
|
|
|
- let grandparentOutline = parentOutline?.parent
|
|
|
- if grandparentOutline != nil {
|
|
|
- if action == #selector(addHigherItemAction) {
|
|
|
- return true
|
|
|
- } else if action == #selector(promoteItemAction) {
|
|
|
- return true
|
|
|
- }
|
|
|
- } else {
|
|
|
- if action == #selector(addHigherItemAction) {
|
|
|
- return false
|
|
|
- } else if action == #selector(promoteItemAction) {
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
if (action == #selector(undo)) {
|
|
|
return handdler.canUndo()
|
|
|
}
|
|
@@ -1041,42 +908,6 @@ extension KMOutlineViewController: NSMenuDelegate, NSMenuItemValidation {
|
|
|
return handdler.canRedo()
|
|
|
}
|
|
|
|
|
|
- if (action == #selector(expandAllComments)) {
|
|
|
- var canExpand = false
|
|
|
- for row in 0..<self.BOTAOutlineView.outlineView.numberOfRows {
|
|
|
- // 检查当前项目是否可以展开
|
|
|
- let item = self.BOTAOutlineView.outlineView.item(atRow: row)
|
|
|
- if self.BOTAOutlineView.outlineView.isExpandable(item) {
|
|
|
- if !self.BOTAOutlineView.outlineView.isItemExpanded(item) {
|
|
|
- canExpand = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return canExpand
|
|
|
- }
|
|
|
-
|
|
|
- if (action == #selector(collapseAllComments)) {
|
|
|
- var canCollapse = false
|
|
|
- for row in 0..<self.BOTAOutlineView.outlineView.numberOfRows {
|
|
|
- let item = self.BOTAOutlineView.outlineView.item(atRow: row)
|
|
|
- if self.BOTAOutlineView.outlineView.isExpandable(item) {
|
|
|
- if self.BOTAOutlineView.outlineView.isItemExpanded(item) {
|
|
|
- canCollapse = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return canCollapse
|
|
|
- }
|
|
|
-
|
|
|
- if (action == #selector(removeAllOutlineItem)) {
|
|
|
- if self.BOTAOutlineView.outlineView.item(atRow: 0) != nil {
|
|
|
- return true
|
|
|
- } else {
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
return true
|
|
|
}
|
|
|
}
|
|
@@ -1175,46 +1006,11 @@ extension KMOutlineViewController {
|
|
|
//MARK: - undoRedo
|
|
|
extension KMOutlineViewController {
|
|
|
func moveOutline(outlineItem: KMBOTAOutlineItem, index: NSInteger, parent: KMBOTAOutlineItem!) {
|
|
|
-// let tempOutlineView = self.BOTAOutlineView!
|
|
|
-
|
|
|
-// let indexTemp = outlineItem.outline.index
|
|
|
-// let parentTemp = outlineItem.parent
|
|
|
-
|
|
|
- //元数据移除
|
|
|
-// outlineItem.outline.removeFromParent()
|
|
|
-// parent.outline.insertChild(outlineItem.outline, at: UInt(index))
|
|
|
-
|
|
|
handdler.moveOutline(outlineItem: outlineItem, index: index, parent: parent)
|
|
|
-//
|
|
|
-// //显示数据刷新
|
|
|
-// outlineItem.parent?.children.removeObject(outlineItem)
|
|
|
-// parent?.children.insert(outlineItem, at: index)
|
|
|
-// outlineItem.parent = parent
|
|
|
-// tempOutlineView.outlineView.reloadData()
|
|
|
-// tempOutlineView.cancelSelect()
|
|
|
-//
|
|
|
-// //展开
|
|
|
-// outlineItem.isItemExpanded = true
|
|
|
-// outlineItem.parent?.isItemExpanded = true
|
|
|
-// tempOutlineView.outlineView.expandItem(outlineItem)
|
|
|
-// tempOutlineView.outlineView.expandItem(outlineItem.parent)
|
|
|
-
|
|
|
-// self.listView.undoManager?.registerUndo(withTarget: self) { [weak self] targetType in
|
|
|
-// self?.moveOutline(outlineItem: outlineItem, index: NSInteger(indexTemp), parent: parentTemp)
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
func changeLocation(outlineItem: KMBOTAOutlineItem, destination: CPDFDestination) {
|
|
|
-// let tempOutlineView = self.BOTAOutlineView!
|
|
|
-
|
|
|
-// let temp = outlineItem.outline.destination
|
|
|
-// outlineItem.outline.destination = CPDFDestination(document: destination.document, pageIndex: destination.pageIndex, at: destination.point, zoom: destination.zoom)
|
|
|
handdler.changeLocation(outlineItem: outlineItem, destination: destination)
|
|
|
-// tempOutlineView.outlineView.reloadItem(outlineItem)
|
|
|
-
|
|
|
-// self.listView.undoManager?.registerUndo(withTarget: self) { [weak self] targetType in
|
|
|
-// self?.changeLocation(outlineItem: outlineItem, destination: temp!)
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
func renamePDFOutline(outlineItem: KMBOTAOutlineItem!, label: String) {
|
|
@@ -1225,47 +1021,15 @@ extension KMOutlineViewController {
|
|
|
if outlineItem.outline.label == label {
|
|
|
return
|
|
|
}
|
|
|
-// let temp: String = outlineItem.outline.label
|
|
|
-// outlineItem.outline.label = label
|
|
|
+
|
|
|
handdler.renamePDFOutline(outlineItem: outlineItem, label: label)
|
|
|
-// tempOutlineView.outlineView.reloadItem(outlineItem)
|
|
|
-
|
|
|
-// self.listView.undoManager?.registerUndo(withTarget: self) { [weak self] targetType in
|
|
|
-// self?.renamePDFOutline(outlineItem: outlineItem, label: temp)
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
func deleteOutline(outlineItems: [KMBOTAOutlineItem]) {
|
|
|
NSApp.mainWindow?.makeFirstResponder(self.BOTAOutlineView)
|
|
|
let tempOutlineView = self.BOTAOutlineView!
|
|
|
|
|
|
-// var tempOutlineItems: [KMBOTAOutlineItem] = outlineItems
|
|
|
-// tempOutlineItems.sort(){$0.toIndex > $1.toIndex}
|
|
|
-//
|
|
|
-// for outlineItem in tempOutlineItems {
|
|
|
-// outlineItem.outline.removeFromParent()
|
|
|
-// let index = outlineItem.parent?.children.firstIndex(of: outlineItem)
|
|
|
-// outlineItem.toIndex = index!
|
|
|
-// outlineItem.parent?.children.removeObject(outlineItem)
|
|
|
-// }
|
|
|
-
|
|
|
handdler.deleteOutline(outlineItems: outlineItems)
|
|
|
-
|
|
|
-// //展开
|
|
|
-// for outlineItem in tempOutlineItems {
|
|
|
-// outlineItem.parent?.isItemExpanded = true
|
|
|
-// tempOutlineView.outlineView.expandItem(outlineItem.parent)
|
|
|
-// }
|
|
|
-//
|
|
|
-// tempOutlineView.outlineView.reloadData()
|
|
|
-// //删除需要取消选中
|
|
|
-// tempOutlineView.cancelSelect()
|
|
|
-//
|
|
|
-// //刷新nil数据
|
|
|
-// self.updateExtempViewState()
|
|
|
-// self.listView.undoManager?.registerUndo(withTarget: self) { [weak self] targetType in
|
|
|
-// self?.addOutline(outlineItems: tempOutlineItems)
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
func addOutline(outlineItems: [KMBOTAOutlineItem]) {
|
|
@@ -1278,41 +1042,6 @@ extension KMOutlineViewController {
|
|
|
tempOutlineItems.sort(){$0.toIndex < $1.toIndex}
|
|
|
|
|
|
handdler.addOutline(outlineItems: tempOutlineItems)
|
|
|
-// for outlineItem in tempOutlineItems {
|
|
|
-// if outlineItem.outline.label != nil {
|
|
|
-// outlineItem.parent?.outline.insertChild(outlineItem.outline, at: UInt(outlineItem.toIndex))
|
|
|
-// } else {
|
|
|
-// let outline = outlineItem.parent?.outline.insertChild(at: UInt(outlineItem.toIndex))
|
|
|
-// outline?.label = outlineItem.label
|
|
|
-// outline?.destination = outlineItem.destination
|
|
|
-// outlineItem.outline = outline!
|
|
|
-// }
|
|
|
-// outlineItem.parent?.children.insert(outlineItem, at: outlineItem.toIndex)
|
|
|
-// }
|
|
|
-
|
|
|
-// if tempOutlineView.data?.children.count == 0 || tempOutlineView.data == nil {
|
|
|
-// tempOutlineView.inputData = self.handdler.outlineRoot()
|
|
|
-// } else {
|
|
|
-// tempOutlineView.outlineView.reloadData()
|
|
|
-// }
|
|
|
-//
|
|
|
-// //展开
|
|
|
-//// DispatchQueue.main.async {
|
|
|
-// for outlineItem in tempOutlineItems {
|
|
|
-// var tempParent = outlineItem
|
|
|
-// while tempParent.parent != nil {
|
|
|
-// tempParent.isItemExpanded = true
|
|
|
-// tempParent = tempParent.parent!
|
|
|
-// tempOutlineView.outlineView.expandItem(tempParent)
|
|
|
-// }
|
|
|
-// tempOutlineView.outlineView.expandItem(tempParent.parent)
|
|
|
-// }
|
|
|
-//// }
|
|
|
-//
|
|
|
-// self.updateExtempViewState()
|
|
|
-// self.listView.undoManager?.registerUndo(withTarget: self) { [weak self] targetType in
|
|
|
-// self?.deleteOutline(outlineItems: tempOutlineItems)
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
@IBAction func undo(_ sender: Any) {
|