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