KMOutlineViewController.swift 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. //
  2. // KMOutlineViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lxy on 2022/10/10.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. extension KMNSearchKey.wholeWords {
  10. static let outline = "OutlineSearchWholeWordsKey"
  11. }
  12. extension KMNSearchKey.caseSensitive {
  13. static let outline = "OutlineSearchCaseSensitiveKey"
  14. }
  15. class KMOutlineViewController: KMNBotaBaseViewController {
  16. @IBOutlet var contendView: NSView!
  17. @IBOutlet weak var topView: NSView!
  18. @IBOutlet weak var titleLabel: NSTextField!
  19. @IBOutlet weak var lineView: NSView!
  20. @IBOutlet weak var addButton: NSButton!
  21. @IBOutlet weak var moreButton: NSButton!
  22. @IBOutlet var topSepline: NSView!
  23. @IBOutlet weak var emptyView: NSView!
  24. @IBOutlet weak var bigTipLabel: NSTextField!
  25. @IBOutlet weak var tipLabel: NSTextField!
  26. @IBOutlet weak var BOTAOutlineView: KMBOTAOutlineView!
  27. var dragPDFOutline : KMBOTAOutlineItem!
  28. private var dragPDFOutlines_: [KMBOTAOutlineItem] = []
  29. var renameTextField : NSTextField!
  30. var renamePDFOutline : KMBOTAOutlineItem!
  31. let moreMenu = NSMenu()
  32. var isLocalEvent = false
  33. var model = KMNOutlineModel()
  34. var handdler = KMNOutlineHanddler()
  35. private weak var popover_: NSPopover?
  36. private lazy var addButton_: ComponentButton = {
  37. let view = ComponentButton()
  38. view.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, state: .normal, isDisable: false, onlyIcon: true, keepPressState: false)
  39. return view
  40. }()
  41. private lazy var moreDropdown_: ComponentButton = {
  42. let view = ComponentButton()
  43. view.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, state: .normal, isDisable: false, onlyIcon: true, icon: NSImage(named: "KMImageNameOutlineMore"))
  44. return view
  45. }()
  46. private var emptyView_: ComponentEmpty = {
  47. let view = ComponentEmpty()
  48. view.properties = ComponentEmptyProperty(emptyType: .noOutline, state: .normal, image: NSImage(named: "KMImageNameOutlineEmpty"), text: KMLocalizedString("No Outline"), subText: KMLocalizedString("Here is the description."))
  49. return view
  50. }()
  51. private var groupView_: ComponentGroup?
  52. private var menuGroupView_: ComponentGroup?
  53. private var outlineView_: KMOutlineView? {
  54. get {
  55. return BOTAOutlineView.outlineView
  56. }
  57. }
  58. deinit {
  59. self.BOTAOutlineView.delegate = nil
  60. }
  61. override func viewWillDisappear() {
  62. super.viewWillDisappear()
  63. self.cancelSelect()
  64. }
  65. override func viewDidLoad() {
  66. super.viewDidLoad()
  67. handdler.delegate = self
  68. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold")
  69. self.topView.wantsLayer = true
  70. addButton.image = nil
  71. topView.addSubview(searchButton)
  72. searchButton.km_add_size_constraint(size: NSMakeSize(24, 24))
  73. searchButton.km_add_centerY_constraint(constant: 1)
  74. searchButton.km_add_trailing_constraint(equalTo: addButton, attribute: .leading, constant: -4)
  75. searchButton.setTarget(self, action: #selector(_searchAction))
  76. addButton.addSubview(addButton_)
  77. addButton_.km_add_size_constraint(size: NSMakeSize(24, 24))
  78. addButton_.km_add_centerX_constraint()
  79. addButton_.km_add_centerY_constraint()
  80. addButton_.setTarget(self, action: #selector(addNewOutline))
  81. moreButton.image = nil
  82. moreButton.addSubview(moreDropdown_)
  83. moreDropdown_.km_add_size_constraint(size: NSMakeSize(24, 24))
  84. moreDropdown_.km_add_centerX_constraint()
  85. moreDropdown_.km_add_centerY_constraint()
  86. moreDropdown_.setTarget(self, action: #selector(_moreAction))
  87. if let data = headerSearchView {
  88. topView.addSubview(data)
  89. headerSearchView?.frame = topView.bounds
  90. headerSearchView?.autoresizingMask = [.width, .height]
  91. }
  92. hideHeaderSearch()
  93. headerSearchView?.itemClick = { [weak self] idx, params in
  94. if idx == 1 { // 显示搜索限制条件
  95. guard let button = params.first as? ComponentButton else {
  96. return
  97. }
  98. self?.showSearchGroupView(sender: button)
  99. } else if idx == 2 { // 关闭搜索
  100. self?.hideHeaderSearch()
  101. self?.reloadData()
  102. }
  103. }
  104. headerSearchView?.valueDidChange = { [weak self] sender, info in
  105. let value = info?[.newKey] as? String ?? ""
  106. self?.BOTAOutlineView.searchKey = value
  107. self?.reloadData()
  108. self?.BOTAOutlineView.outlineView.expandItem(nil, expandChildren: true)
  109. }
  110. emptyView.wantsLayer = true
  111. bigTipLabel.stringValue = ""
  112. tipLabel.stringValue = ""
  113. emptyView.addSubview(emptyView_)
  114. emptyView_.km_add_top_constraint(constant: 232)
  115. emptyView_.km_add_bottom_constraint()
  116. emptyView_.km_add_leading_constraint()
  117. emptyView_.km_add_trailing_constraint()
  118. self.BOTAOutlineView.delegate = self
  119. self.BOTAOutlineView.inputData = self.handdler.outlineRoot()
  120. self.BOTAOutlineView.outlineView.doubleAction = #selector(outlineViewDoubleAction)
  121. }
  122. // To create an outline, please right-click on the selected page and choose \"Add Outline\", or click \"Add\" in the upper right corner.
  123. override func updateUILanguage() {
  124. super.updateUILanguage()
  125. KMMainThreadExecute {
  126. self.titleLabel.stringValue = KMLocalizedString("Outline")
  127. self.moreButton.toolTip = KMLocalizedString("More")
  128. self.addButton.toolTip = KMLocalizedString("Add Outline")
  129. }
  130. }
  131. override func updateUIThemeColor() {
  132. super.updateUIThemeColor()
  133. KMMainThreadExecute {
  134. self.contendView.wantsLayer = true
  135. let color = KMNColorTools.colorBg_layoutMiddle()
  136. self.contendView.layer?.backgroundColor = color.cgColor
  137. self.headerSearchView?.wantsLayer = true
  138. self.headerSearchView?.layer?.backgroundColor = color.cgColor
  139. self.headerSearchView?.bottomLine.wantsLayer = true
  140. self.headerSearchView?.bottomLine.layer?.backgroundColor = KMNColorTools.colorPrimary_border1().cgColor
  141. self.titleLabel.textColor = KMNColorTools.colorText_2()
  142. self.addButton_.properties.icon = NSImage(named: "KMBookmarkAdd")
  143. self.addButton_.reloadData()
  144. self.searchButton.properties.icon = NSImage(named: "KMImageNameOutlineSearch")
  145. self.searchButton.reloadData()
  146. let dividerColor = KMNColorTools.colorBorder_divider()
  147. self.topSepline.wantsLayer = true
  148. self.topSepline.layer?.backgroundColor = dividerColor.cgColor
  149. self.lineView.backgroundColor(dividerColor)
  150. }
  151. }
  152. override func showHeaderSearch() {
  153. super.showHeaderSearch()
  154. BOTAOutlineView.isSearchMode = true
  155. }
  156. override func hideHeaderSearch() {
  157. super.hideHeaderSearch()
  158. BOTAOutlineView.isSearchMode = false
  159. }
  160. func addRightMenu(view: NSView, event: NSEvent) {
  161. let point = event.locationInWindow
  162. let tempView = view
  163. var viewHeight: CGFloat = 0
  164. let items: [String] = ["Add Item", "Add Sub-Item", "Add A Higher Level","", "Delete","", "Edit", "Rename", "Change Destination","", "Promote", "Demote"]
  165. var menuItemArr: [ComponentMenuitemProperty] = []
  166. for value in items {
  167. if value.count == 0 {
  168. let property: ComponentMenuitemProperty = ComponentMenuitemProperty.divider()
  169. menuItemArr.append(property)
  170. viewHeight += 8
  171. } else {
  172. let properties_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  173. itemSelected: false,
  174. isDisabled: false,
  175. keyEquivalent: nil,
  176. text: KMLocalizedString(value),
  177. identifier: value)
  178. menuItemArr.append(properties_Menuitem)
  179. viewHeight += 36
  180. }
  181. }
  182. if _isEmptySelection() {
  183. for data in menuItemArr {
  184. if data.text == KMLocalizedString("Add Item") {
  185. data.isDisabled = false
  186. } else {
  187. data.isDisabled = true
  188. }
  189. }
  190. } else if _isMutilSelection() {
  191. for data in menuItemArr {
  192. if data.text == KMLocalizedString("Delete") {
  193. data.isDisabled = false
  194. } else {
  195. data.isDisabled = true
  196. }
  197. }
  198. } else {
  199. let clickedRow = BOTAOutlineView.outlineView.clickedRow
  200. let outlineItem = BOTAOutlineView.outlineView.item(atRow: clickedRow) as? KMBOTAOutlineItem
  201. let idx = outlineItem?.outline.index ?? 0
  202. let canDemote = idx > 0
  203. let grandparentOutline = outlineItem?.outline.parent?.parent
  204. let canPromote = grandparentOutline != nil
  205. let canAddHigher = grandparentOutline != nil
  206. if BOTAOutlineView.isValidSearchMode() {
  207. for data in menuItemArr {
  208. if data.text == KMLocalizedString("Delete") || data.text == KMLocalizedString("Change Destination") {
  209. data.isDisabled = false
  210. } else if data.text == KMLocalizedString("Demote") {
  211. data.isDisabled = !canDemote
  212. } else if data.text == KMLocalizedString("Promote") {
  213. data.isDisabled = !canPromote
  214. } else {
  215. data.isDisabled = true
  216. }
  217. }
  218. } else {
  219. for data in menuItemArr {
  220. if data.text == KMLocalizedString("Add Sub-Item") || data.text == KMLocalizedString("Change Destination") {
  221. data.isDisabled = false
  222. } else if data.text == KMLocalizedString("Demote") {
  223. data.isDisabled = !canDemote
  224. } else if data.text == KMLocalizedString("Promote") {
  225. data.isDisabled = !canPromote
  226. } else if data.text == KMLocalizedString("Add A Higher Level") {
  227. data.isDisabled = !canAddHigher
  228. }
  229. }
  230. }
  231. }
  232. if menuGroupView_ == nil {
  233. menuGroupView_ = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
  234. }
  235. if menuGroupView_ != nil {
  236. menuGroupView_?.clickedAutoHide = false
  237. menuGroupView_?.groupDelegate = self
  238. menuGroupView_?.frame = CGRectMake(0, 0, 180, viewHeight)
  239. menuGroupView_?.updateGroupInfo(menuItemArr)
  240. menuGroupView_?.showWithPoint(CGPoint(x: point.x, y: point.y - viewHeight), relativeTo: tempView)
  241. }
  242. }
  243. func reloadData() {
  244. self.BOTAOutlineView.reloadData(expandItemType: .none)
  245. }
  246. func editOutlineUI(editVC : KMOutlineEditViewController!) {
  247. if editVC.pageRadio.properties.checkboxType == .selected {
  248. let index = Int(editVC.pageInput.properties.text) ?? 0
  249. let pageIndex = max(0, index-1)
  250. if editVC.originalDestination?.pageIndex != pageIndex {
  251. let page = editVC.pdfView?.document.page(at: UInt(pageIndex))
  252. if page != nil {
  253. let destination = CPDFDestination.init(document: editVC.pdfView!.document, pageIndex: pageIndex)
  254. editVC.outline?.destination = destination
  255. } else {
  256. __NSBeep()
  257. }
  258. }
  259. } else if editVC.webRaido.properties.checkboxType == .selected {
  260. if editVC.originalURLString != editVC.webInput.properties.text {
  261. var urlString = editVC.webInput.properties.text
  262. let tLowerUrl = urlString.lowercased()
  263. if !tLowerUrl.hasPrefix("https://") && !tLowerUrl.hasPrefix("pf]://") && !urlString.hasPrefix("https://") &&
  264. urlString.lengthOfBytes(using: String.Encoding(rawValue: String.Encoding.utf16.rawValue)) > 0 {
  265. urlString = "http://\(urlString)"
  266. }
  267. let action = CPDFURLAction.init(url: urlString)
  268. editVC.outline?.action = action
  269. }
  270. } else if editVC.emailRadio.properties.checkboxType == .selected {
  271. var mailString = editVC.emailInput.properties.text
  272. let tLowerStr = mailString.lowercased()
  273. if !tLowerStr.hasPrefix("mailto:") {
  274. mailString = "mailto:\(mailString)"
  275. }
  276. if mailString != editVC.originalURLString {
  277. var action = CPDFURLAction.init(url: mailString)
  278. if action?.url == nil {
  279. action = CPDFURLAction.init(url: "mailto:")
  280. }
  281. editVC.outline?.action = action
  282. }
  283. }
  284. }
  285. // MARK: - Private Methods
  286. private func _showAlert(style: NSAlert.Style, message: String, info: String, buttons: [String]) -> NSApplication.ModalResponse {
  287. let alert = NSAlert()
  288. alert.alertStyle = style
  289. alert.messageText = message
  290. alert.informativeText = info
  291. for button in buttons {
  292. alert.addButton(withTitle: button)
  293. }
  294. return alert.runModal()
  295. }
  296. @objc private func _moreAction() {
  297. self.showGroupView()
  298. }
  299. private func _isEmptySelection() -> Bool {
  300. return BOTAOutlineView.outlineView.clickedRow == -1
  301. }
  302. private func _isMutilSelection() -> Bool {
  303. return BOTAOutlineView.outlineView.selectedRowIndexes.count > 1
  304. }
  305. //MARK: - GroupView
  306. func showGroupView() {
  307. var viewHeight: CGFloat = 8
  308. var menuItemArr: [ComponentMenuitemProperty] = []
  309. for i in ["Expand All", "Collapse All", "Remove All Outlines"] {
  310. let properties_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  311. itemSelected: false,
  312. isDisabled: false,
  313. keyEquivalent: nil,
  314. text: KMLocalizedString(i))
  315. menuItemArr.append(properties_Menuitem)
  316. viewHeight += 36
  317. }
  318. if let data = menuItemArr.first {
  319. var canExpand = false
  320. for row in 0..<self.BOTAOutlineView.outlineView.numberOfRows {
  321. // 检查当前项目是否可以展开
  322. let item = self.BOTAOutlineView.outlineView.item(atRow: row)
  323. if self.BOTAOutlineView.outlineView.isExpandable(item) {
  324. if !self.BOTAOutlineView.outlineView.isItemExpanded(item) {
  325. canExpand = true
  326. break
  327. }
  328. }
  329. }
  330. data.isDisabled = !canExpand
  331. }
  332. if let data = menuItemArr.safe_element(for: 1) as? ComponentMenuitemProperty {
  333. var canCollapse = false
  334. for row in 0..<self.BOTAOutlineView.outlineView.numberOfRows {
  335. let item = self.BOTAOutlineView.outlineView.item(atRow: row)
  336. if self.BOTAOutlineView.outlineView.isExpandable(item) {
  337. if self.BOTAOutlineView.outlineView.isItemExpanded(item) {
  338. canCollapse = true
  339. break
  340. }
  341. }
  342. }
  343. data.isDisabled = !canCollapse
  344. }
  345. if let data = menuItemArr.last {
  346. if self.BOTAOutlineView.outlineView.item(atRow: 0) != nil {
  347. data.isDisabled = false
  348. } else {
  349. data.isDisabled = true
  350. }
  351. }
  352. if groupView_ == nil {
  353. groupView_ = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
  354. }
  355. groupView_?.groupDelegate = self
  356. groupView_?.frame = CGRectMake(310, 0, 200, viewHeight)
  357. groupView_?.updateGroupInfo(menuItemArr)
  358. var point = moreDropdown_.convert(moreDropdown_.frame.origin, to: nil)
  359. point.y -= viewHeight
  360. groupView_?.showWithPoint(point, relativeTo: moreDropdown_)
  361. moreDropdown_.properties.state = .pressed
  362. moreDropdown_.reloadData()
  363. }
  364. func showSearchGroupView(sender: ComponentButton) {
  365. var viewHeight: CGFloat = 8
  366. var menuItemArr: [ComponentMenuitemProperty] = []
  367. let titles = ["Whole Words","Case Sensitive"]
  368. for i in titles {
  369. let menuI = ComponentMenuitemProperty(text: KMLocalizedString(i))
  370. menuItemArr.append(menuI)
  371. viewHeight += 36
  372. }
  373. if let info = menuItemArr.first {
  374. if KMDataManager.ud_bool(forKey: KMNSearchKey.wholeWords.outline) {
  375. info.righticon = NSImage(named: "KMNImageNameMenuSelect")
  376. }
  377. }
  378. if let info = menuItemArr.last {
  379. if KMDataManager.ud_bool(forKey: KMNSearchKey.caseSensitive.outline) {
  380. info.righticon = NSImage(named: "KMNImageNameMenuSelect")
  381. }
  382. }
  383. let groupView = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
  384. searchGroupView = groupView
  385. groupView?.groupDelegate = self
  386. groupView?.frame = CGRectMake(310, 0, 200, viewHeight)
  387. groupView?.updateGroupInfo(menuItemArr)
  388. var point = sender.convert(sender.frame.origin, to: nil)
  389. point.y -= viewHeight
  390. groupView?.showWithPoint(point, relativeTo: sender)
  391. searchGroupTarget = sender
  392. }
  393. func removeGroupView() {
  394. if groupView_ != nil {
  395. groupView_?.removeFromSuperview()
  396. }
  397. moreDropdown_.properties.state = .normal
  398. moreDropdown_.reloadData()
  399. }
  400. func updateExtempViewState() {
  401. if BOTAOutlineView.isValidSearchMode() {
  402. if BOTAOutlineView.data?.searchChildren.isEmpty == true {
  403. self.emptyView.isHidden = false
  404. } else {
  405. self.emptyView.isHidden = true
  406. }
  407. } else {
  408. if(self.handdler.outlineRoot() == nil || self.handdler.outlineRoot()?.numberOfChildren == 0) { //无数据时的图
  409. self.emptyView.isHidden = false
  410. } else {
  411. self.emptyView.isHidden = true
  412. }
  413. }
  414. }
  415. }
  416. //MARK: - Menu 右键菜单
  417. extension KMOutlineViewController {
  418. @objc func outlineViewDoubleAction() {
  419. if(self.BOTAOutlineView.outlineView.clickedRow >= 0) {
  420. self.renameItemAction()
  421. }
  422. }
  423. @objc func addItemAction() {
  424. guard let outlineView = BOTAOutlineView.outlineView else {
  425. return
  426. }
  427. let selectRowIndexs = outlineView.selectedRowIndexes
  428. let dataCount = BOTAOutlineView.data?.children.count ?? 0
  429. var index: Int = 0
  430. var parent: KMBOTAOutlineItem?
  431. var outlineItem: KMBOTAOutlineItem?
  432. if selectRowIndexs.count == 0 {
  433. var lastOulineItem: KMBOTAOutlineItem?
  434. if dataCount == 0 {
  435. let item = KMBOTAOutlineItem()
  436. item.outline = self.handdler.document!.setNewOutlineRoot()
  437. item.parent = nil
  438. parent = item
  439. lastOulineItem = item
  440. } else {
  441. outlineItem = outlineView.item(atRow: outlineView.numberOfRows - 1) as? KMBOTAOutlineItem
  442. lastOulineItem = outlineItem
  443. while lastOulineItem?.parent != nil {
  444. lastOulineItem = lastOulineItem?.parent
  445. }
  446. parent = lastOulineItem
  447. }
  448. index = Int(lastOulineItem?.outline.numberOfChildren ?? 0)
  449. } else {
  450. outlineItem = outlineView.item(atRow: selectRowIndexs.last ?? 0) as? KMBOTAOutlineItem
  451. parent = outlineItem?.parent ?? KMBOTAOutlineItem()
  452. index = Int(((outlineItem?.outline.index) ?? 0) + 1)
  453. }
  454. self.addOutlineToIndex(index: index, parent: parent)
  455. }
  456. @objc func addChildItemAction() {
  457. let outlineView: KMOutlineView = self.BOTAOutlineView.outlineView
  458. let selectRowIndexs = outlineView.selectedRowIndexes
  459. if selectRowIndexs.count != 0 {
  460. let outlineItem: KMBOTAOutlineItem = outlineView.item(atRow: selectRowIndexs.last!) as! KMBOTAOutlineItem
  461. let index = outlineItem.outline.numberOfChildren
  462. self.addOutlineToIndex(index: NSInteger(index), parent: outlineItem)
  463. }
  464. }
  465. @objc func addHigherItemAction() {
  466. let outlineView: KMOutlineView = self.BOTAOutlineView.outlineView
  467. let selectRowIndexs = outlineView.selectedRowIndexes
  468. if selectRowIndexs.count != 0 {
  469. let outlineItem: KMBOTAOutlineItem = outlineView.item(atRow: selectRowIndexs.last!) as! KMBOTAOutlineItem
  470. var parent = outlineItem.parent
  471. let index = NSInteger(parent!.outline.index) + 1
  472. parent = parent?.parent
  473. if parent != nil {
  474. self.addOutlineToIndex(index: index, parent: parent!)
  475. }
  476. }
  477. }
  478. @objc func deleteItemAction() {
  479. let outlineView: KMOutlineView = self.BOTAOutlineView.outlineView
  480. let selectRowIndexs = outlineView.selectedRowIndexes
  481. if selectRowIndexs.count != 0 {
  482. var outlineItems: [KMBOTAOutlineItem] = []
  483. for index in selectRowIndexs {
  484. let outlineItem: KMBOTAOutlineItem = self.BOTAOutlineView.outlineView.item(atRow: index) as! KMBOTAOutlineItem
  485. outlineItem.toIndex = index
  486. outlineItem.parent = outlineItem.parent ?? KMBOTAOutlineItem()
  487. outlineItems.append(outlineItem)
  488. }
  489. self.deleteOutline(outlineItems: outlineItems)
  490. }
  491. }
  492. @objc func editItemAction() {
  493. let clickedRow = BOTAOutlineView.outlineView.clickedRow
  494. if clickedRow < 0 {
  495. NSSound.beep()
  496. return
  497. }
  498. if let rowView = self.BOTAOutlineView.outlineView.rowView(atRow: clickedRow, makeIfNecessary: true) {
  499. let item = self.BOTAOutlineView.outlineView.item(atRow: clickedRow) as? KMBOTAOutlineItem
  500. let vc = KMOutlineEditViewController.init(outline: item?.outline, document: self.handdler.pdfView)
  501. vc.pageCount = handdler.pageCount()
  502. vc.itemClick = { [weak self] idx, params in
  503. if idx == 1 {
  504. self?.popover_?.close()
  505. } else if idx == 2 {
  506. self?.popover_?.close()
  507. if let viewC = params.first as? KMOutlineEditViewController {
  508. let resp = self?._showAlert(style: .informational, message: KMLocalizedString("Are you sure you want to apply edits to this outline?"), info: "", buttons: [KMLocalizedString("Apply"), KMLocalizedString("Cancel")])
  509. if resp == .alertFirstButtonReturn {
  510. self?.editOutlineUI(editVC: viewC)
  511. }
  512. }
  513. }
  514. }
  515. let popover = NSPopover()
  516. popover_ = popover
  517. popover.delegate = self
  518. popover.contentViewController = vc
  519. popover.animates = true
  520. popover.behavior = .transient
  521. popover.setValue(true, forKey: "shouldHideAnchor")
  522. popover.show(relativeTo: rowView.bounds, of: rowView, preferredEdge: .minX)
  523. }
  524. }
  525. @objc func renameItemAction() {
  526. if self.BOTAOutlineView.outlineView.clickedRow >= 0 {
  527. self.renameOutlineWithRow(row: self.BOTAOutlineView.outlineView.clickedRow)
  528. } else {
  529. __NSBeep()
  530. }
  531. }
  532. @objc func changeItemAction() {
  533. guard let currentDest = handdler.currentDestination() else {
  534. NSSound.beep()
  535. return
  536. }
  537. guard let item = outlineView_?.clickedItem() as? KMBOTAOutlineItem else {
  538. NSSound.beep()
  539. return
  540. }
  541. let resp = _showAlert(style: .informational, message: KMLocalizedString("Are you sure you want to set the destination as the current location?"), info: "", buttons: [KMLocalizedString("Yes"), KMLocalizedString("No")])
  542. if resp == .alertFirstButtonReturn {
  543. handdler.changeLocation(outlineItem: item, destination: currentDest)
  544. }
  545. }
  546. @objc func promoteItemAction() {
  547. if self.BOTAOutlineView.outlineView.clickedRow >= 0 {
  548. let outlineItem: KMBOTAOutlineItem = self.BOTAOutlineView.outlineView.item(atRow: self.BOTAOutlineView.outlineView.clickedRow) as! KMBOTAOutlineItem
  549. var parent = outlineItem.parent
  550. let index = NSInteger(parent!.outline.index) + 1
  551. parent = parent?.parent
  552. if parent != nil {
  553. self.moveOutline(outlineItem: outlineItem, index: index, parent: parent)
  554. }
  555. }
  556. }
  557. @objc func demoteItemAction() {
  558. if self.BOTAOutlineView.outlineView.clickedRow >= 0 {
  559. let outlineItem: KMBOTAOutlineItem = self.BOTAOutlineView.outlineView.item(atRow: self.BOTAOutlineView.outlineView.clickedRow) as! KMBOTAOutlineItem
  560. let parent = outlineItem.parent
  561. let newParent = parent?.children[Int(outlineItem.outline.index) - 1]
  562. let index = newParent?.children.count
  563. if (index != nil) {
  564. self.moveOutline(outlineItem: outlineItem, index: NSInteger(index ?? 0), parent: newParent)
  565. }
  566. }
  567. }
  568. @objc private func expandAllComments(item: NSMenuItem) {
  569. self.BOTAOutlineView.expandAllComments(item: item)
  570. }
  571. @objc private func collapseAllComments(item: NSMenuItem) {
  572. self.BOTAOutlineView.collapseAllComments(item: item)
  573. }
  574. @objc private func removeAllOutlineItem(item: NSMenuItem) {
  575. let alter = NSAlert()
  576. alter.alertStyle = NSAlert.Style.informational
  577. alter.messageText = NSLocalizedString("This will permanently remove all outlines. Are you sure to continue?", comment: "")
  578. alter.addButton(withTitle: NSLocalizedString("Yes", comment:""))
  579. alter.addButton(withTitle: NSLocalizedString("No", comment:""))
  580. let modlres = alter.runModal()
  581. if modlres == NSApplication.ModalResponse.alertFirstButtonReturn {
  582. self.removeAllOutline()
  583. }
  584. }
  585. @objc private func removeAllOutline() {
  586. guard let data = self.BOTAOutlineView.data else { return }
  587. for item in data.children {
  588. item.toIndex = Int(item.outline.index)
  589. }
  590. self.deleteOutline(outlineItems: data.children)
  591. self.BOTAOutlineView.reloadData(expandItemType: .none)
  592. }
  593. @objc private func _searchAction() {
  594. searchButton.properties.state = .normal
  595. searchButton.reloadData()
  596. showHeaderSearch()
  597. }
  598. }
  599. //MARK: - Action
  600. extension KMOutlineViewController {
  601. @IBAction func addNewOutline(_ sender: Any) {
  602. self.addItemAction()
  603. }
  604. @IBAction func escButtonAction(_ sender: Any) {
  605. self.cancelSelect()
  606. }
  607. func cancelSelect() {
  608. self.BOTAOutlineView.cancelSelect()
  609. }
  610. func renameOutlineWithRow(row: NSInteger) {
  611. DispatchQueue.main.async {
  612. self.renamePDFOutline = self.BOTAOutlineView.outlineView.item(atRow: row) as? KMBOTAOutlineItem
  613. let cell : KMBOTAOutlineCellView = self.BOTAOutlineView.outlineView.view(atColumn: 0, row: row, makeIfNecessary: true) as! KMBOTAOutlineCellView
  614. self.renameTextField = cell.titleLabel
  615. self.renameTextField.delegate = self
  616. self.renameTextField.isEditable = true
  617. self.renameTextField.becomeFirstResponder()
  618. }
  619. }
  620. func addOutlineToIndex(index: Int, parent: KMBOTAOutlineItem?) {
  621. let pageIndex = self.handdler.currentPageIndex
  622. let label = self.fetchCurrentLabel(pageIndex: pageIndex)
  623. let destination = self.handdler.currentDestination()
  624. self.addOutlineToIndex(index: index, pageIndex: pageIndex, destination: destination, lable: label, parent: parent)
  625. }
  626. func addOutlineToIndex(index: Int, pageIndex: Int, destination: CPDFDestination?, lable: String, parent: KMBOTAOutlineItem?) {
  627. let outlineItem = KMBOTAOutlineItem()
  628. outlineItem.destination = destination
  629. outlineItem.label = lable
  630. outlineItem.parent = parent
  631. outlineItem.toIndex = index
  632. self.addOutline(outlineItems: [outlineItem])
  633. let tempOutlineView = self.BOTAOutlineView!
  634. var index = -1
  635. if tempOutlineView.outlineView.numberOfRows == 1 || tempOutlineView.data == nil {
  636. index = 0
  637. } else {
  638. index = tempOutlineView.outlineView.row(forItem: outlineItem)
  639. }
  640. tempOutlineView.selectIndex(index: index)
  641. //滑动到指定位置
  642. if(tempOutlineView.outlineView.selectedRow >= 0) {
  643. self.renameOutlineWithRow(row: tempOutlineView.outlineView.selectedRow)
  644. }
  645. let row = tempOutlineView.outlineView.row(forItem: outlineItem)
  646. if Thread.current.isMainThread {
  647. tempOutlineView.outlineView.scrollToVisible(tempOutlineView.outlineView.rect(ofRow: row))
  648. } else {
  649. DispatchQueue.main.async {
  650. tempOutlineView.outlineView.scrollToVisible(tempOutlineView.outlineView.rect(ofRow: row))
  651. }
  652. }
  653. }
  654. func updateOutlineSelection() {
  655. let currentPageIndex = self.handdler.currentPageIndex
  656. let numRows = self.BOTAOutlineView.outlineView.numberOfRows
  657. if numRows > 0 {
  658. for i in 0...numRows - 1 {
  659. let outlineItem: KMBOTAOutlineItem = self.BOTAOutlineView.outlineView.item(atRow: i) as! KMBOTAOutlineItem
  660. if (outlineItem.outline.destination == nil) {
  661. continue
  662. }
  663. if outlineItem.outline.destination.pageIndex == currentPageIndex {
  664. self.BOTAOutlineView.selectIndex(index: currentPageIndex)
  665. break
  666. }
  667. }
  668. }
  669. }
  670. func fetchCurrentLabel(pageIndex: Int) -> String {
  671. var label = "\(NSLocalizedString("Page", comment: ""))\(pageIndex + 1)"
  672. let currentSelection = self.handdler.currentSelection()
  673. if currentSelection != nil && currentSelection?.selectionsByLine != nil {
  674. for data in currentSelection?.selectionsByLine ?? [] {
  675. label = data.string() ?? ""
  676. }
  677. }
  678. return label
  679. }
  680. }
  681. //MARK: - KMBOTAOutlineViewDelegate
  682. extension KMOutlineViewController: KMBOTAOutlineViewDelegate {
  683. func BOTAOutlineView(_ outlineView: KMBOTAOutlineView, rightDidMoseDown: KMBOTAOutlineItem, event: NSEvent) {
  684. let row = outlineView.outlineView.row(forItem: rightDidMoseDown)
  685. if outlineView.outlineView.rowView(atRow: row, makeIfNecessary: false) != nil {
  686. let rowView = outlineView.outlineView.rowView(atRow: row, makeIfNecessary: false)
  687. self.addRightMenu(view: rowView!, event: event)
  688. }
  689. }
  690. func BOTAOutlineView(_ outlineView: KMBOTAOutlineView, didReloadData: KMBOTAOutlineItem) {
  691. self.updateExtempViewState()
  692. }
  693. func BOTAOutlineView(_ outlineView: KMBOTAOutlineView, didSelectItem: [KMBOTAOutlineItem]) {
  694. if outlineView_?.selectedRowIndexes.count == 1 {
  695. isLocalEvent = true
  696. guard let item = outlineView_?.selectedItem() as? KMBOTAOutlineItem else {
  697. return
  698. }
  699. handdler.selectOutline(item.outline)
  700. }
  701. }
  702. func BOTAOutlineView(_ outlineView: KMBOTAOutlineView, writeItems items: [Any], to pasteboard: NSPasteboard) -> Bool {
  703. if outlineView.outlineView.selectedRow == -1 {
  704. return false
  705. }
  706. self.dragPDFOutline = items.first as? KMBOTAOutlineItem
  707. self.dragPDFOutlines_ = items as? [KMBOTAOutlineItem] ?? []
  708. let indexSet = [outlineView.outlineView.clickedRow]
  709. let indexSetData: Data = try!NSKeyedArchiver.archivedData(withRootObject: indexSet, requiringSecureCoding: true)
  710. pasteboard.declareTypes([NSPasteboard.PasteboardType(rawValue: "kKMPDFViewOutlineDragDataType")], owner: self)
  711. pasteboard.setData(indexSetData, forType: NSPasteboard.PasteboardType(rawValue: NSPasteboard.PasteboardType.RawValue("kKMPDFViewOutlineDragDataType")))
  712. return true
  713. }
  714. func BOTAOutlineView(_ outlineView: KMBOTAOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
  715. var dragOperation = NSDragOperation.init(rawValue: 0)
  716. if index >= 0 {
  717. dragOperation = NSDragOperation.move
  718. }
  719. return dragOperation
  720. }
  721. func BOTAOutlineView(_ outlineView: KMBOTAOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool {
  722. guard let dragOutlineItem = self.dragPDFOutline else { return false }
  723. let outlineItem: KMBOTAOutlineItem = (item ?? KMBOTAOutlineItem()) as! KMBOTAOutlineItem
  724. if index < 0 {
  725. return false
  726. }
  727. for dragOutlineItem in dragPDFOutlines_ {
  728. if outlineItem.parent == nil {
  729. var root = dragOutlineItem.parent
  730. while root?.parent?.children != nil {
  731. root = root?.parent!
  732. }
  733. if dragOutlineItem.parent!.isEqual(root) {
  734. if dragOutlineItem.outline.index > index {
  735. self.moveOutline(outlineItem: dragOutlineItem, index: index, parent: root)
  736. } else {
  737. self.moveOutline(outlineItem: dragOutlineItem, index: index - 1, parent: root)
  738. }
  739. } else {
  740. self.moveOutline(outlineItem: dragOutlineItem, index: index, parent: root)
  741. }
  742. } else {
  743. if dragOutlineItem.parent!.isEqual(item) {
  744. // if dragOutlineItem.outline.index != 0 {
  745. if dragOutlineItem.outline.index > index {
  746. self.moveOutline(outlineItem: dragOutlineItem, index: index, parent: item as? KMBOTAOutlineItem)
  747. } else {
  748. self.moveOutline(outlineItem: dragOutlineItem, index: index - 1, parent: item as? KMBOTAOutlineItem)
  749. }
  750. // } else {
  751. // return false
  752. // }
  753. } else {
  754. var tOutline = outlineItem
  755. var isContains = false
  756. while (tOutline.parent != nil) {
  757. if tOutline.outline.isEqual(dragOutlineItem.outline) {
  758. isContains = true
  759. break
  760. }
  761. tOutline = tOutline.parent!
  762. }
  763. if isContains == false {
  764. self.moveOutline(outlineItem: dragOutlineItem, index: index, parent: item as? KMBOTAOutlineItem)
  765. }
  766. }
  767. }
  768. }
  769. self.BOTAOutlineView.selectItem(outlineItem: dragOutlineItem)
  770. return true
  771. }
  772. }
  773. //MARK: - NSTextFieldDelegate
  774. extension KMOutlineViewController: NSTextFieldDelegate {
  775. func controlTextDidEndEditing(_ obj: Notification) {
  776. if (self.renameTextField.isEqual(obj.object)) {
  777. let textField : NSTextField = obj.object as! NSTextField
  778. self.renamePDFOutline(outlineItem: self.renamePDFOutline, label: textField.stringValue)
  779. }
  780. }
  781. }
  782. //MARK: - NSPopoverDelegate
  783. extension KMOutlineViewController: NSPopoverDelegate {
  784. func popoverWillClose(_ notification: Notification) {
  785. let popover : NSPopover = notification.object as! NSPopover
  786. if popover.contentViewController!.isKind(of: KMOutlineEditViewController.self) {
  787. }
  788. }
  789. func popoverDidClose(_ notification: Notification) {
  790. if popover_ == (notification.object as? NSPopover) {
  791. popover_ = nil
  792. }
  793. }
  794. }
  795. //MARK: - NSMenuItemValidation
  796. extension KMOutlineViewController: NSMenuDelegate, NSMenuItemValidation {
  797. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  798. let action = menuItem.action
  799. if (action == #selector(undo)) {
  800. return handdler.canUndo()
  801. }
  802. if (action == #selector(redo)) {
  803. return handdler.canRedo()
  804. }
  805. return true
  806. }
  807. }
  808. // MARK: - KMNOutlineHanddlerDelegate
  809. extension KMOutlineViewController: KMNOutlineHanddlerDelegate {
  810. func handdler(_ handdler: KMNOutlineHanddler, didAdd info: [String : Any]?) {
  811. let tempOutlineItems = info?["data"] as? [KMBOTAOutlineItem] ?? []
  812. let tempOutlineView = self.BOTAOutlineView
  813. if tempOutlineView?.data?.children.count == 0 || tempOutlineView?.data == nil {
  814. tempOutlineView?.inputData = self.handdler.outlineRoot()
  815. } else {
  816. if BOTAOutlineView.isValidSearchMode() {
  817. BOTAOutlineView.reloadSearchChildren(item: BOTAOutlineView.data)
  818. }
  819. tempOutlineView?.outlineView.reloadData()
  820. }
  821. //展开
  822. // DispatchQueue.main.async {
  823. for outlineItem in tempOutlineItems {
  824. var tempParent = outlineItem
  825. while tempParent.parent != nil {
  826. tempParent.isItemExpanded = true
  827. tempParent = tempParent.parent!
  828. tempOutlineView?.outlineView.expandItem(tempParent)
  829. }
  830. tempOutlineView?.outlineView.expandItem(tempParent.parent)
  831. }
  832. // }
  833. self.updateExtempViewState()
  834. }
  835. func handdler(_ handdler: KMNOutlineHanddler, didRemove info: [String : Any]?) {
  836. let tempOutlineItems = info?["data"] as? [KMBOTAOutlineItem] ?? []
  837. let tempOutlineView = self.BOTAOutlineView
  838. //展开
  839. for outlineItem in tempOutlineItems {
  840. outlineItem.parent?.isItemExpanded = true
  841. tempOutlineView?.outlineView.expandItem(outlineItem.parent)
  842. }
  843. if BOTAOutlineView.isValidSearchMode() {
  844. BOTAOutlineView.reloadSearchChildren(item: BOTAOutlineView.data)
  845. }
  846. tempOutlineView?.outlineView.reloadData()
  847. //删除需要取消选中
  848. tempOutlineView?.cancelSelect()
  849. //刷新nil数据
  850. self.updateExtempViewState()
  851. }
  852. func handdler(_ handdler: KMNOutlineHanddler, didRename outline: CPDFOutline?, info: [String : Any]?) {
  853. let outlineItem = info?["data"] as? KMBOTAOutlineItem
  854. let tempOutlineView = self.BOTAOutlineView
  855. tempOutlineView?.outlineView.reloadItem(outlineItem)
  856. }
  857. func handdler(_ handdler: KMNOutlineHanddler, didChangeLocation outline: CPDFOutline?, info: [String : Any]?) {
  858. let outlineItem = info?["data"] as? KMBOTAOutlineItem
  859. let tempOutlineView = self.BOTAOutlineView
  860. tempOutlineView?.outlineView.reloadItem(outlineItem)
  861. }
  862. func handdler(_ handdler: KMNOutlineHanddler, didMove outline: CPDFOutline?, info: [String : Any]?) {
  863. guard let outlineItem = info?["data"] as? KMBOTAOutlineItem else {
  864. return
  865. }
  866. let parent = info?["parent"] as? KMBOTAOutlineItem
  867. let tempOutlineView = self.BOTAOutlineView
  868. let index = info?["index"] as? Int ?? 0
  869. if BOTAOutlineView.isValidSearchMode() {
  870. BOTAOutlineView.reloadSearchChildren(item: BOTAOutlineView.data)
  871. }
  872. //显示数据刷新
  873. outlineItem.parent?.children.removeObject(outlineItem)
  874. parent?.children.insert(outlineItem, at: index)
  875. outlineItem.parent = parent
  876. tempOutlineView?.outlineView.reloadData()
  877. tempOutlineView?.cancelSelect()
  878. //展开
  879. outlineItem.isItemExpanded = true
  880. outlineItem.parent?.isItemExpanded = true
  881. tempOutlineView?.outlineView.expandItem(outlineItem)
  882. tempOutlineView?.outlineView.expandItem(outlineItem.parent)
  883. }
  884. }
  885. //MARK: - 快捷键
  886. extension KMOutlineViewController {
  887. @IBAction func delete(_ sender: Any) {
  888. self.deleteItemAction()
  889. }
  890. }
  891. //MARK: - undoRedo
  892. extension KMOutlineViewController {
  893. func moveOutline(outlineItem: KMBOTAOutlineItem, index: NSInteger, parent: KMBOTAOutlineItem!) {
  894. handdler.moveOutline(outlineItem: outlineItem, index: index, parent: parent)
  895. }
  896. func changeLocation(outlineItem: KMBOTAOutlineItem, destination: CPDFDestination) {
  897. handdler.changeLocation(outlineItem: outlineItem, destination: destination)
  898. }
  899. func renamePDFOutline(outlineItem: KMBOTAOutlineItem!, label: String) {
  900. let tempOutlineView = self.BOTAOutlineView!
  901. self.view.window?.makeFirstResponder(tempOutlineView.outlineView)
  902. self.renameTextField.isEditable = false
  903. if outlineItem.outline.label == label {
  904. return
  905. }
  906. handdler.renamePDFOutline(outlineItem: outlineItem, label: label)
  907. }
  908. func deleteOutline(outlineItems: [KMBOTAOutlineItem]) {
  909. NSApp.mainWindow?.makeFirstResponder(self.BOTAOutlineView)
  910. let tempOutlineView = self.BOTAOutlineView!
  911. handdler.deleteOutline(outlineItems: outlineItems)
  912. }
  913. func addOutline(outlineItems: [KMBOTAOutlineItem]) {
  914. NSApp.mainWindow?.makeFirstResponder(self.BOTAOutlineView)
  915. let tempOutlineView = self.BOTAOutlineView!
  916. //先取消选中
  917. tempOutlineView.cancelSelect()
  918. var tempOutlineItems: [KMBOTAOutlineItem] = outlineItems
  919. tempOutlineItems.sort(){$0.toIndex < $1.toIndex}
  920. handdler.addOutline(outlineItems: tempOutlineItems)
  921. }
  922. @IBAction func undo(_ sender: Any) {
  923. handdler.undo()
  924. }
  925. @IBAction func redo(_ sender: Any) {
  926. handdler.redo()
  927. }
  928. }
  929. //MARK: - ComponentDropdownDelegate
  930. extension KMOutlineViewController: ComponentDropdownDelegate {
  931. func componentDropdownDidShowMenuItem(dropdown: ComponentDropdown) {
  932. showGroupView()
  933. }
  934. }
  935. //MARK: - ComponentGroupDelegate
  936. extension KMOutlineViewController: ComponentGroupDelegate {
  937. func componentGroupDidDismiss(group: ComponentGroup?) {
  938. if group == groupView_ {
  939. removeGroupView()
  940. } else if group == menuGroupView_ {
  941. group?.removeFromSuperview()
  942. menuGroupView_ = nil
  943. } else if group == searchGroupView {
  944. // searchGroupView_ = nil
  945. searchGroupTarget?.properties.state = .normal
  946. searchGroupTarget?.reloadData()
  947. searchGroupTarget = nil
  948. }
  949. }
  950. func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
  951. if group == groupView_ {
  952. if let selItem = menuItemProperty {
  953. let index = group?.menuItemArr.firstIndex(of: selItem)
  954. if index == 0 {
  955. expandAllComments(item: NSMenuItem())
  956. } else if index == 1 {
  957. collapseAllComments(item: NSMenuItem())
  958. } else if index == 2 {
  959. removeAllOutlineItem(item: NSMenuItem())
  960. }
  961. }
  962. } else if group == menuGroupView_ {
  963. if let selItem = menuItemProperty {
  964. let index = group?.menuItemArr.firstIndex(of: selItem)
  965. if index == 0 {
  966. addItemAction()
  967. } else if index == 1 {
  968. addChildItemAction()
  969. } else if index == 2 {
  970. addHigherItemAction()
  971. } else if index == 4 {
  972. deleteItemAction()
  973. } else if index == 6 {
  974. group?.removeFromSuperview()
  975. editItemAction()
  976. } else if index == 7 {
  977. renameItemAction()
  978. } else if index == 8 {
  979. changeItemAction()
  980. } else if index == 10 {
  981. promoteItemAction()
  982. } else if index == 11 {
  983. demoteItemAction()
  984. }
  985. group?.removeFromSuperview()
  986. }
  987. } else if group == searchGroupView {
  988. guard let menuI = menuItemProperty else {
  989. return
  990. }
  991. let idx = group?.menuItemArr.firstIndex(of: menuI)
  992. if idx == 0 {
  993. let key = KMNSearchKey.wholeWords.outline
  994. let value = KMDataManager.ud_bool(forKey: key)
  995. KMDataManager.ud_set(!value, forKey: key)
  996. BOTAOutlineView.wholeWords = !value
  997. } else if idx == 1 {
  998. let key = KMNSearchKey.caseSensitive.outline
  999. let value = KMDataManager.ud_bool(forKey: key)
  1000. KMDataManager.ud_set(!value, forKey: key)
  1001. BOTAOutlineView.caseSensitive = !value
  1002. }
  1003. }
  1004. }
  1005. }