|
@@ -42,13 +42,18 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
|
|
|
private lazy var addButton_: ComponentButton = {
|
|
|
let view = ComponentButton()
|
|
|
- view.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, state: .normal, isDisable: false, onlyIcon: true)
|
|
|
+ view.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, state: .normal, isDisable: false, onlyIcon: true, keepPressState: false)
|
|
|
return view
|
|
|
}()
|
|
|
|
|
|
private lazy var moreDropdown_: ComponentDropdown = {
|
|
|
let view = ComponentDropdown()
|
|
|
- view.properties = ComponentDropdownProperty(type: .default_Icon, size: .xxs, state: .normal, split: false, disabled: false)
|
|
|
+ view.properties = ComponentDropdownProperty(type: .split_primary, size: .xxs, state: .normal, split: false, disabled: false)
|
|
|
+ return view
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var headerSearchView_: KMNBotaHeaderSearchView? = {
|
|
|
+ let view = KMNBotaHeaderSearchView.createFromNib()
|
|
|
return view
|
|
|
}()
|
|
|
|
|
@@ -85,6 +90,7 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
searchButton_.km_add_size_constraint(size: NSMakeSize(24, 24))
|
|
|
searchButton_.km_add_centerY_constraint(constant: 1)
|
|
|
searchButton_.km_add_trailing_constraint(equalTo: addButton, attribute: .leading, constant: -4)
|
|
|
+ searchButton_.setTarget(self, action: #selector(_searchAction))
|
|
|
|
|
|
addButton.addSubview(addButton_)
|
|
|
addButton_.km_add_size_constraint(size: NSMakeSize(24, 24))
|
|
@@ -99,6 +105,20 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
moreDropdown_.km_add_centerY_constraint()
|
|
|
moreDropdown_.componentDelegate = self
|
|
|
|
|
|
+ if let data = headerSearchView_ {
|
|
|
+ topView.addSubview(data)
|
|
|
+ headerSearchView_?.frame = topView.bounds
|
|
|
+ headerSearchView_?.autoresizingMask = [.width, .height]
|
|
|
+ }
|
|
|
+ _hideHeaderSearch()
|
|
|
+ headerSearchView_?.itemClick = { [weak self] idx, _ in
|
|
|
+ if idx == 1 { // 忽略大小写
|
|
|
+
|
|
|
+ } else if idx == 2 { // 关闭搜索
|
|
|
+ self?._hideHeaderSearch()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
emptyView.wantsLayer = true
|
|
|
bigTipLabel.stringValue = ""
|
|
|
tipLabel.stringValue = ""
|
|
@@ -109,7 +129,6 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
emptyView_.km_add_leading_constraint()
|
|
|
emptyView_.km_add_trailing_constraint()
|
|
|
|
|
|
-
|
|
|
self.BOTAOutlineView.delegate = self
|
|
|
self.BOTAOutlineView.inputData = self.handdler.outlineRoot()
|
|
|
self.BOTAOutlineView.outlineView.doubleAction = #selector(outlineViewDoubleAction)
|
|
@@ -132,10 +151,14 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
|
|
|
KMMainThreadExecute {
|
|
|
self.contendView.wantsLayer = true
|
|
|
- let color = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
|
|
|
+ let color = KMNColorTools.colorBg_layoutMiddle()
|
|
|
self.contendView.layer?.backgroundColor = color.cgColor
|
|
|
+ self.headerSearchView_?.wantsLayer = true
|
|
|
+ self.headerSearchView_?.layer?.backgroundColor = color.cgColor
|
|
|
+ self.headerSearchView_?.bottomLine.wantsLayer = true
|
|
|
+ self.headerSearchView_?.bottomLine.layer?.backgroundColor = KMNColorTools.colorPrimary_border1().cgColor
|
|
|
|
|
|
- self.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
|
|
|
+ self.titleLabel.textColor = KMNColorTools.colorText_2()
|
|
|
|
|
|
self.addButton_.properties.icon = NSImage(named: "KMBookmarkAdd")
|
|
|
self.addButton_.reloadData()
|
|
@@ -143,7 +166,7 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
self.searchButton_.properties.icon = NSImage(named: "KMImageNameOutlineSearch")
|
|
|
self.searchButton_.reloadData()
|
|
|
|
|
|
- let dividerColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider")
|
|
|
+ let dividerColor = KMNColorTools.colorBorder_divider()
|
|
|
self.topSepline.wantsLayer = true
|
|
|
self.topSepline.layer?.backgroundColor = dividerColor.cgColor
|
|
|
self.lineView.backgroundColor(dividerColor)
|
|
@@ -196,7 +219,7 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
let point = event.locationInWindow
|
|
|
let tempView = view
|
|
|
var viewHeight: CGFloat = 0
|
|
|
- let items: [String] = ["Add Item", "Add Sub-Item", "Add A Higher Level","", "Delete","", "Edit", "Rename", "Change Destination","", "Promote", "Promote"]
|
|
|
+ let items: [String] = ["Add Item", "Add Sub-Item", "Add A Higher Level","", "Delete","", "Edit", "Rename", "Change Destination","", "Promote", "Demote"]
|
|
|
var menuItemArr: [ComponentMenuitemProperty] = []
|
|
|
for value in items {
|
|
|
if value.count == 0 {
|
|
@@ -215,10 +238,113 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
viewHeight += 36
|
|
|
}
|
|
|
}
|
|
|
-// if idxs > 1 {
|
|
|
-// (menuItemArr.safe_element(for: 1) as? ComponentMenuitemProperty)?.isDisabled = true
|
|
|
-// (menuItemArr.safe_element(for: 2) as? ComponentMenuitemProperty)?.isDisabled = true
|
|
|
-// }
|
|
|
+
|
|
|
+ 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
|
|
|
+ } else {
|
|
|
+ data.isDisabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if menuGroupView_ == nil {
|
|
|
+ menuGroupView_ = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
|
|
|
+ }
|
|
|
+
|
|
|
+ if menuGroupView_ != nil {
|
|
|
+ menuGroupView_?.clickedAutoHide = false
|
|
|
+ menuGroupView_?.groupDelegate = self
|
|
|
+ menuGroupView_?.frame = CGRectMake(0, 0, 180, viewHeight)
|
|
|
+ menuGroupView_?.updateGroupInfo(menuItemArr)
|
|
|
+
|
|
|
+ menuGroupView_?.showWithPoint(CGPoint(x: point.x, y: point.y - viewHeight), relativeTo: tempView)
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ } else {
|
|
|
+// data.isDisabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ } else {
|
|
|
+ data.isDisabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } 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
|
|
|
+ } else {
|
|
|
+// data.isDisabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+// if action == #selector(demoteItemAction) {
|
|
|
+// return false
|
|
|
+// }
|
|
|
+ for data in menuItemArr {
|
|
|
+ if data.text == KMLocalizedString("Demote") {
|
|
|
+ data.isDisabled = true
|
|
|
+ } else {
|
|
|
+// data.isDisabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+ } else {
|
|
|
+// data.isDisabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } 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
|
|
|
+ } else {
|
|
|
+// data.isDisabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
if menuGroupView_ == nil {
|
|
|
menuGroupView_ = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
|
|
@@ -296,6 +422,14 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
return alert.runModal()
|
|
|
}
|
|
|
|
|
|
+ private func _showHeaderSearch() {
|
|
|
+ headerSearchView_?.isHidden = false
|
|
|
+ }
|
|
|
+
|
|
|
+ private func _hideHeaderSearch() {
|
|
|
+ headerSearchView_?.isHidden = true
|
|
|
+ }
|
|
|
+
|
|
|
//MARK: - GroupView
|
|
|
|
|
|
func showGroupView() {
|
|
@@ -311,6 +445,43 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
viewHeight += 36
|
|
|
}
|
|
|
|
|
|
+ if let data = menuItemArr.first {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.isDisabled = !canExpand
|
|
|
+ }
|
|
|
+
|
|
|
+ if let data = menuItemArr.safe_element(for: 1) as? ComponentMenuitemProperty {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.isDisabled = !canCollapse
|
|
|
+ }
|
|
|
+
|
|
|
+ if let data = menuItemArr.last {
|
|
|
+ if self.BOTAOutlineView.outlineView.item(atRow: 0) != nil {
|
|
|
+ data.isDisabled = false
|
|
|
+ } else {
|
|
|
+ data.isDisabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if groupView_ == nil {
|
|
|
groupView_ = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
|
|
|
}
|
|
@@ -333,11 +504,7 @@ class KMOutlineViewController: KMNBaseViewController {
|
|
|
moreDropdown_.properties.state = .normal
|
|
|
moreDropdown_.reloadData()
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-//Data
|
|
|
-extension KMOutlineViewController {
|
|
|
+
|
|
|
func updateExtempViewState() {
|
|
|
if(self.handdler.outlineRoot() == nil || self.handdler.outlineRoot()?.numberOfChildren == 0) { //无数据时的图
|
|
|
self.emptyView.isHidden = false
|
|
@@ -347,7 +514,9 @@ extension KMOutlineViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//MARK: - Notification
|
|
|
+
|
|
|
extension KMOutlineViewController {
|
|
|
@objc func KMPDFViewCurrentPageDidChangedNotification(notification: NSNotification) {
|
|
|
if notification.object is CPDFDocument {
|
|
@@ -371,16 +540,18 @@ extension KMOutlineViewController {
|
|
|
}
|
|
|
|
|
|
@objc func addItemAction() {
|
|
|
- let outlineView: KMOutlineView = self.BOTAOutlineView.outlineView
|
|
|
+ guard let outlineView = BOTAOutlineView.outlineView else {
|
|
|
+ return
|
|
|
+ }
|
|
|
let selectRowIndexs = outlineView.selectedRowIndexes
|
|
|
- let dataCount = self.BOTAOutlineView.data?.children.count
|
|
|
- var index: Int
|
|
|
- var parent: KMBOTAOutlineItem = KMBOTAOutlineItem()
|
|
|
- var outlineItem: KMBOTAOutlineItem = KMBOTAOutlineItem()
|
|
|
+ let dataCount = BOTAOutlineView.data?.children.count ?? 0
|
|
|
+ var index: Int = 0
|
|
|
+ var parent: KMBOTAOutlineItem?
|
|
|
+ var outlineItem: KMBOTAOutlineItem?
|
|
|
|
|
|
if selectRowIndexs.count == 0 {
|
|
|
- var lastOulineItem = KMBOTAOutlineItem()
|
|
|
- if dataCount == nil || dataCount == 0 {
|
|
|
+ var lastOulineItem: KMBOTAOutlineItem?
|
|
|
+ if dataCount == 0 {
|
|
|
let item = KMBOTAOutlineItem()
|
|
|
item.outline = self.handdler.document!.setNewOutlineRoot()
|
|
|
item.parent = nil
|
|
@@ -388,18 +559,18 @@ extension KMOutlineViewController {
|
|
|
|
|
|
lastOulineItem = item
|
|
|
} else {
|
|
|
- outlineItem = outlineView.item(atRow: outlineView.numberOfRows - 1) as! KMBOTAOutlineItem
|
|
|
+ outlineItem = outlineView.item(atRow: outlineView.numberOfRows - 1) as? KMBOTAOutlineItem
|
|
|
lastOulineItem = outlineItem
|
|
|
- while lastOulineItem.parent != nil {
|
|
|
- lastOulineItem = lastOulineItem.parent!
|
|
|
+ while lastOulineItem?.parent != nil {
|
|
|
+ lastOulineItem = lastOulineItem?.parent
|
|
|
}
|
|
|
parent = lastOulineItem
|
|
|
}
|
|
|
- index = Int(lastOulineItem.outline.numberOfChildren)
|
|
|
+ index = Int(lastOulineItem?.outline.numberOfChildren ?? 0)
|
|
|
} else {
|
|
|
- outlineItem = outlineView.item(atRow: selectRowIndexs.last ?? 0) as! KMBOTAOutlineItem
|
|
|
- parent = outlineItem.parent ?? KMBOTAOutlineItem()
|
|
|
- index = Int(outlineItem.outline.index + 1)
|
|
|
+ outlineItem = outlineView.item(atRow: selectRowIndexs.last ?? 0) as? KMBOTAOutlineItem
|
|
|
+ parent = outlineItem?.parent ?? KMBOTAOutlineItem()
|
|
|
+ index = Int((outlineItem?.outline.index) ?? 0 + 1)
|
|
|
}
|
|
|
|
|
|
self.addOutlineToIndex(index: index, parent: parent)
|
|
@@ -538,6 +709,10 @@ extension KMOutlineViewController {
|
|
|
self.deleteOutline(outlineItems: data.children)
|
|
|
self.BOTAOutlineView.reloadData(expandItemType: .none)
|
|
|
}
|
|
|
+
|
|
|
+ @objc private func _searchAction() {
|
|
|
+ _showHeaderSearch()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//MARK: - Action
|
|
@@ -571,15 +746,15 @@ extension KMOutlineViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func addOutlineToIndex(index: Int, parent: KMBOTAOutlineItem) {
|
|
|
- let pageIndex: Int = self.handdler.currentPageIndex
|
|
|
- let label: String = self.fetchCurrentLabel(pageIndex: pageIndex)
|
|
|
+ func addOutlineToIndex(index: Int, parent: KMBOTAOutlineItem?) {
|
|
|
+ let pageIndex = self.handdler.currentPageIndex
|
|
|
+ let label = self.fetchCurrentLabel(pageIndex: pageIndex)
|
|
|
let destination = self.handdler.currentDestination()
|
|
|
|
|
|
self.addOutlineToIndex(index: index, pageIndex: pageIndex, destination: destination, lable: label, parent: parent)
|
|
|
}
|
|
|
|
|
|
- func addOutlineToIndex(index: Int, pageIndex: Int, destination: CPDFDestination?, lable: String, parent: KMBOTAOutlineItem) {
|
|
|
+ func addOutlineToIndex(index: Int, pageIndex: Int, destination: CPDFDestination?, lable: String, parent: KMBOTAOutlineItem?) {
|
|
|
let outlineItem = KMBOTAOutlineItem()
|
|
|
outlineItem.destination = destination
|
|
|
outlineItem.label = lable
|
|
@@ -860,10 +1035,10 @@ extension KMOutlineViewController: NSMenuDelegate, NSMenuItemValidation {
|
|
|
}
|
|
|
|
|
|
if (action == #selector(undo)) {
|
|
|
-// return self.listView.undoManager?.canUndo ?? false
|
|
|
+ return handdler.canUndo()
|
|
|
}
|
|
|
if (action == #selector(redo)) {
|
|
|
-// return self.listView.undoManager?.canRedo ?? false
|
|
|
+ return handdler.canRedo()
|
|
|
}
|
|
|
|
|
|
if (action == #selector(expandAllComments)) {
|
|
@@ -910,32 +1085,83 @@ extension KMOutlineViewController: NSMenuDelegate, NSMenuItemValidation {
|
|
|
|
|
|
extension KMOutlineViewController: KMNOutlineHanddlerDelegate {
|
|
|
func handdler(_ handdler: KMNOutlineHanddler, didAdd info: [String : Any]?) {
|
|
|
- let items = info?["data"] as? [Any]
|
|
|
- let outlineItem = items?.first
|
|
|
+ let tempOutlineItems = info?["data"] as? [KMBOTAOutlineItem] ?? []
|
|
|
|
|
|
- let tempOutlineView = self.BOTAOutlineView!
|
|
|
- var index = -1
|
|
|
- if tempOutlineView.outlineView.numberOfRows == 1 || tempOutlineView.data == nil {
|
|
|
- index = 0
|
|
|
+ let tempOutlineView = self.BOTAOutlineView
|
|
|
+ if tempOutlineView?.data?.children.count == 0 || tempOutlineView?.data == nil {
|
|
|
+ tempOutlineView?.inputData = self.handdler.outlineRoot()
|
|
|
} else {
|
|
|
- index = tempOutlineView.outlineView.row(forItem: outlineItem)
|
|
|
- }
|
|
|
-
|
|
|
- tempOutlineView.selectIndex(index: index)
|
|
|
-
|
|
|
- //滑动到指定位置
|
|
|
- if(tempOutlineView.outlineView.selectedRow >= 0) {
|
|
|
- self.renameOutlineWithRow(row: tempOutlineView.outlineView.selectedRow)
|
|
|
+ tempOutlineView?.outlineView.reloadData()
|
|
|
}
|
|
|
|
|
|
- let row = tempOutlineView.outlineView.row(forItem: outlineItem)
|
|
|
- if Thread.current.isMainThread {
|
|
|
- tempOutlineView.outlineView.scrollToVisible(tempOutlineView.outlineView.rect(ofRow: row))
|
|
|
- } else {
|
|
|
- DispatchQueue.main.async {
|
|
|
- tempOutlineView.outlineView.scrollToVisible(tempOutlineView.outlineView.rect(ofRow: row))
|
|
|
+ //展开
|
|
|
+// 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()
|
|
|
+ }
|
|
|
+
|
|
|
+ func handdler(_ handdler: KMNOutlineHanddler, didRemove info: [String : Any]?) {
|
|
|
+ let tempOutlineItems = info?["data"] as? [KMBOTAOutlineItem] ?? []
|
|
|
+ let tempOutlineView = self.BOTAOutlineView
|
|
|
+ //展开
|
|
|
+ for outlineItem in tempOutlineItems {
|
|
|
+ outlineItem.parent?.isItemExpanded = true
|
|
|
+ tempOutlineView?.outlineView.expandItem(outlineItem.parent)
|
|
|
+ }
|
|
|
+
|
|
|
+ tempOutlineView?.outlineView.reloadData()
|
|
|
+ //删除需要取消选中
|
|
|
+ tempOutlineView?.cancelSelect()
|
|
|
+
|
|
|
+ //刷新nil数据
|
|
|
+ self.updateExtempViewState()
|
|
|
+ }
|
|
|
+
|
|
|
+ func handdler(_ handdler: KMNOutlineHanddler, didRename outline: CPDFOutline?, info: [String : Any]?) {
|
|
|
+ let outlineItem = info?["data"] as? KMBOTAOutlineItem
|
|
|
+ let tempOutlineView = self.BOTAOutlineView
|
|
|
+
|
|
|
+ tempOutlineView?.outlineView.reloadItem(outlineItem)
|
|
|
+ }
|
|
|
+
|
|
|
+ func handdler(_ handdler: KMNOutlineHanddler, didChangeLocation outline: CPDFOutline?, info: [String : Any]?) {
|
|
|
+ let outlineItem = info?["data"] as? KMBOTAOutlineItem
|
|
|
+ let tempOutlineView = self.BOTAOutlineView
|
|
|
+
|
|
|
+ tempOutlineView?.outlineView.reloadItem(outlineItem)
|
|
|
+ }
|
|
|
+
|
|
|
+ func handdler(_ handdler: KMNOutlineHanddler, didMove outline: CPDFOutline?, info: [String : Any]?) {
|
|
|
+ guard let outlineItem = info?["data"] as? KMBOTAOutlineItem else {
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
+ let parent = info?["parent"] as? KMBOTAOutlineItem
|
|
|
+ let tempOutlineView = self.BOTAOutlineView
|
|
|
+ let index = info?["index"] as? Int ?? 0
|
|
|
+
|
|
|
+ //显示数据刷新
|
|
|
+ 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)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -949,27 +1175,29 @@ extension KMOutlineViewController {
|
|
|
//MARK: - undoRedo
|
|
|
extension KMOutlineViewController {
|
|
|
func moveOutline(outlineItem: KMBOTAOutlineItem, index: NSInteger, parent: KMBOTAOutlineItem!) {
|
|
|
- let tempOutlineView = self.BOTAOutlineView!
|
|
|
+// let tempOutlineView = self.BOTAOutlineView!
|
|
|
|
|
|
- let indexTemp = outlineItem.outline.index
|
|
|
- let parentTemp = outlineItem.parent
|
|
|
+// let indexTemp = outlineItem.outline.index
|
|
|
+// let parentTemp = outlineItem.parent
|
|
|
|
|
|
//元数据移除
|
|
|
- outlineItem.outline.removeFromParent()
|
|
|
- parent.outline.insertChild(outlineItem.outline, at: UInt(index))
|
|
|
+// outlineItem.outline.removeFromParent()
|
|
|
+// parent.outline.insertChild(outlineItem.outline, at: UInt(index))
|
|
|
|
|
|
- //显示数据刷新
|
|
|
- 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)
|
|
|
+ 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)
|
|
@@ -977,11 +1205,12 @@ extension KMOutlineViewController {
|
|
|
}
|
|
|
|
|
|
func changeLocation(outlineItem: KMBOTAOutlineItem, destination: CPDFDestination) {
|
|
|
- let tempOutlineView = self.BOTAOutlineView!
|
|
|
+// 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)
|
|
|
- tempOutlineView.outlineView.reloadItem(outlineItem)
|
|
|
+// 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!)
|
|
@@ -996,9 +1225,10 @@ extension KMOutlineViewController {
|
|
|
if outlineItem.outline.label == label {
|
|
|
return
|
|
|
}
|
|
|
- let temp: String = outlineItem.outline.label
|
|
|
- outlineItem.outline.label = label
|
|
|
- tempOutlineView.outlineView.reloadItem(outlineItem)
|
|
|
+// 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)
|
|
@@ -1009,28 +1239,30 @@ extension KMOutlineViewController {
|
|
|
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)
|
|
|
- }
|
|
|
-
|
|
|
- //展开
|
|
|
- for outlineItem in tempOutlineItems {
|
|
|
- outlineItem.parent?.isItemExpanded = true
|
|
|
- tempOutlineView.outlineView.expandItem(outlineItem.parent)
|
|
|
- }
|
|
|
+// 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)
|
|
|
+// }
|
|
|
|
|
|
- tempOutlineView.outlineView.reloadData()
|
|
|
- //删除需要取消选中
|
|
|
- tempOutlineView.cancelSelect()
|
|
|
+ handdler.deleteOutline(outlineItems: outlineItems)
|
|
|
|
|
|
- //刷新nil数据
|
|
|
- self.updateExtempViewState()
|
|
|
+// //展开
|
|
|
+// 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)
|
|
|
// }
|
|
@@ -1045,53 +1277,50 @@ extension KMOutlineViewController {
|
|
|
var tempOutlineItems: [KMBOTAOutlineItem] = outlineItems
|
|
|
tempOutlineItems.sort(){$0.toIndex < $1.toIndex}
|
|
|
|
|
|
- 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)
|
|
|
- }
|
|
|
+ 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)
|
|
|
// }
|
|
|
|
|
|
- self.updateExtempViewState()
|
|
|
+// 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) {
|
|
|
-// if (self.listView.undoManager?.canUndo ?? false) {
|
|
|
-// self.listView.undoManager?.undo()
|
|
|
-// }
|
|
|
+ handdler.undo()
|
|
|
}
|
|
|
|
|
|
@IBAction func redo(_ sender: Any) {
|
|
|
-// if (self.listView.undoManager?.canRedo ?? false) {
|
|
|
-// self.listView.undoManager?.redo()
|
|
|
-// }
|
|
|
+ handdler.redo()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1151,6 +1380,8 @@ extension KMOutlineViewController: ComponentGroupDelegate {
|
|
|
} else if index == 11 {
|
|
|
demoteItemAction()
|
|
|
}
|
|
|
+
|
|
|
+ group?.removeFromSuperview()
|
|
|
}
|
|
|
}
|
|
|
}
|