KMBatchOperateAddHeaderFooterViewController.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. //
  2. // KMBatchOperateAddHeaderFooterViewController.swift
  3. // PDF Master
  4. //
  5. // Created by liujiajie on 2023/11/7.
  6. //
  7. import Cocoa
  8. class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewController, NSTableViewDelegate,NSTableViewDataSource{
  9. var isBates = false
  10. var onlyManagerTemplate = false
  11. var isBatchOperation = false
  12. var pdfView: CPDFView?
  13. @IBOutlet var topBaseView: NSView!
  14. @IBOutlet var bottomBaseView: NSView!
  15. @IBOutlet var tableView: NSTableView!
  16. @IBOutlet var titleLabel: NSTextField!
  17. @IBOutlet var actionButton: NSButton!
  18. @IBOutlet var managerTemplateTitleLabel: NSTextField!
  19. @IBOutlet var addButton: NSButton!
  20. @IBOutlet var blankView: KMBlankView!
  21. @IBOutlet var managerTemplateTopConstraint: NSLayoutConstraint!
  22. @IBOutlet var managerTemplateButtonHeightConstraint: NSButton!
  23. @IBOutlet var topHeightConstraint: NSLayoutConstraint!
  24. @IBOutlet var lineView: NSView!
  25. var haveFiles = false
  26. var currentObject: KMHeaderFooterModel?
  27. override var interfaceStatus: KMBatchOperateInterfaceStatus?{
  28. set{
  29. super.interfaceStatus = newValue
  30. if newValue == .PrepareProcess {
  31. DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
  32. let files = NSMutableArray()
  33. for url in self.successFilePathURLArray! {
  34. if FileManager.default.fileExists(atPath: url.path) {
  35. files.add(url)
  36. }
  37. }
  38. if files.count > 0 {
  39. let workspace = NSWorkspace.shared
  40. workspace.activateFileViewerSelecting(files as! [URL])
  41. }
  42. }
  43. self.actionButton.tag = 1
  44. self.actionButton.title = KMLocalizedString("Apply", nil)
  45. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  46. } else {
  47. self.actionButton.tag = 0
  48. self.actionButton.title = KMLocalizedString("Cancel", nil)
  49. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  50. }
  51. }
  52. get{
  53. return super.interfaceStatus
  54. }
  55. }
  56. deinit {
  57. NotificationCenter.default.removeObserver(self)
  58. }
  59. override func viewDidLoad() {
  60. super.viewDidLoad()
  61. localizedLanguage()
  62. configuInterface()
  63. NotificationCenter.default.addObserver(self, selector: #selector(headerFootersNotification(notification:)), name: Notification.Name(rawValue: "KMBatchOperateHeaderFootersNotification"), object: nil)
  64. NotificationCenter.default.addObserver(self, selector: #selector(themeChanged(notification:)), name: Notification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  65. NotificationCenter.default.addObserver(self, selector: #selector(batchFilesCountNotification(notification:)), name: NSNotification.Name("KMBatchFilesCountNotification"), object: nil)
  66. }
  67. func localizedLanguage() {
  68. self.addButton.title = KMLocalizedString("Add Template", nil)
  69. self.actionButton.title = KMLocalizedString("Apply", nil)
  70. self.titleLabel.stringValue = KMLocalizedString("Apply", nil)
  71. }
  72. func configuInterface() {
  73. self.titleLabel.font = NSFont.systemFont(ofSize: 14)
  74. self.titleLabel.textColor = KMAppearance.Layout.h0Color()
  75. self.tableView.enclosingScrollView?.borderType = .noBorder
  76. self.actionButton.wantsLayer = true
  77. self.addButton.wantsLayer = true
  78. self.topHeightConstraint.constant = 0
  79. var color = NSColor(red: 227.0/255.0, green: 228.0/255.0, blue: 230.0/255.0, alpha: 1)
  80. if KMAppearance.isSupportNewColor() {
  81. if KMAppearance.isDarkMode() {
  82. color = NSColor(red: 59.0/255.0, green: 61/255.0, blue: 64.0/255.0, alpha: 1)
  83. }
  84. }
  85. self.lineView.wantsLayer = true
  86. self.lineView.layer?.backgroundColor = color.cgColor
  87. self.addButton.imagePosition = .imageLeft
  88. self.addButton.image = NSImage(named: "KMImageNameHeaderFooterAddBtn")
  89. self.addButton.layer?.backgroundColor = KMAppearance.Interactive.s0Color().cgColor
  90. self.addButton.setTitleColor(KMAppearance.Layout.h0Color())
  91. if (onlyManagerTemplate){
  92. managerTemplateTitleLabel.isHidden = false
  93. titleLabel.isHidden = true
  94. self.topBaseView.isHidden = false
  95. topHeightConstraint.constant = 40
  96. }else{
  97. managerTemplateTitleLabel.isHidden = true
  98. titleLabel.isHidden = true
  99. self.topBaseView.isHidden = true
  100. topHeightConstraint.constant = 0
  101. }
  102. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  103. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  104. self.actionButton.imagePosition = .noImage
  105. if !self.onlyManagerTemplate {
  106. if self.files?.count ?? 0 > 0 {
  107. self.haveFiles = true
  108. } else {
  109. self.haveFiles = false
  110. }
  111. } else {
  112. self.haveFiles = true
  113. }
  114. updateActionButtonbackgroundColor()
  115. self.addButton.layer?.cornerRadius = 1.0
  116. self.actionButton.layer?.cornerRadius = 1.0
  117. self.topBaseView.wantsLayer = true
  118. self.topBaseView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  119. self.bottomBaseView.wantsLayer = true
  120. self.bottomBaseView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  121. self.managerTemplateTitleLabel.font = NSFont.systemFont(ofSize: 14)
  122. self.managerTemplateTitleLabel.textColor = KMAppearance.Layout.h0Color()
  123. self.addButton.isHidden = false
  124. self.managerTemplateTitleLabel.stringValue = NSLocalizedString("Manage Templates", comment: "")
  125. self.view.addSubview(self.blankView)
  126. self.blankView.mas_makeConstraints { make in
  127. make?.top.equalTo()(self.topBaseView.mas_bottom)
  128. make?.left.equalTo()(self.view)
  129. make?.right.equalTo()(self.view)
  130. make?.bottom.equalTo()(self.bottomBaseView.mas_top)
  131. make?.height.greaterThanOrEqualTo()(200)
  132. }
  133. self.blankView.titleLabel.stringValue = KMLocalizedString("No Templates", nil)
  134. self.tableView.backgroundColor = KMAppearance.Layout.l0Color()
  135. let menu = NSMenu(title: "")
  136. if !self.isBatchOperation && !self.isBates {
  137. menu.addItem(withTitle: NSLocalizedString("Batch Add Header & Footer", comment: ""), action: #selector(buttonItemClick_addBatch(_:)), keyEquivalent: "")
  138. } else if !self.isBatchOperation && self.isBates {
  139. menu.addItem(withTitle: NSLocalizedString("Batch Add Bates Numbers", comment: ""), action: #selector(buttonItemClick_addBatch(_:)), keyEquivalent: "")
  140. }
  141. if !self.isBates {
  142. menu.addItem(withTitle: NSLocalizedString("Remove All Header & Footer Templates", comment: ""), action: #selector(buttonItemClick_CleanAll(_:)), keyEquivalent: "")
  143. } else {
  144. menu.addItem(withTitle: NSLocalizedString("Remove All Bates Numbers Templates", comment: ""), action: #selector(buttonItemClick_CleanAll(_:)), keyEquivalent: "")
  145. }
  146. self.view.menu = menu
  147. updateViewColor()
  148. }
  149. func updateActionButtonbackgroundColor() {
  150. let row = self.tableView.selectedRow
  151. if (self.files?.count ?? 0 > 0 || self.pdfView != nil) && row > -1 {
  152. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  153. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  154. } else {
  155. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color().withAlphaComponent(0.6))
  156. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.6).cgColor
  157. }
  158. }
  159. @objc func buttonItemClick_addBatch(_ sender: Any) {
  160. let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
  161. if #available(macOS 10.13, *) {
  162. baseWindowController.window?.makeKeyAndOrderFront(nil)
  163. } else {
  164. baseWindowController.showWindow(nil)
  165. }
  166. var arr = NSMutableArray()
  167. let file = KMBatchOperateFile(filePath: self.pdfView!.document!.documentURL!.path, type: self.isBates ? .AddBates : .AddHeaderFooter)
  168. arr.add(file)
  169. baseWindowController.checkNeedPasswordSwitchToOperateType(operateType: self.isBates ? .AddBates : .AddHeaderFooter, files: arr as! [KMBatchOperateFile])
  170. }
  171. @objc func buttonItemClick_CleanAll(_ sender: Any) {
  172. let alert = NSAlert()
  173. alert.alertStyle = .warning
  174. alert.messageText = ""
  175. alert.informativeText = NSLocalizedString("Are you sure to delete all templates?", comment: "")
  176. alert.addButton(withTitle: NSLocalizedString("Delete", comment: ""))
  177. alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
  178. alert.beginSheetModal(for: NSApp.mainWindow!) { (response) in
  179. if response == .alertFirstButtonReturn {
  180. self.deleteAll()
  181. }
  182. }
  183. }
  184. @objc func headerFootersNotification(notification: Notification) {
  185. if let addHeaderFooter = notification.object as? KMBatchOperateAddHeaderFooterViewController {
  186. if self != addHeaderFooter {
  187. loadData()
  188. }
  189. }
  190. }
  191. @objc func themeChanged(notification: Notification) {
  192. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  193. self.updateViewColor()
  194. }
  195. }
  196. @objc func batchFilesCountNotification(notification: Notification) {
  197. let files = notification.object as? [Any]
  198. if files?.count ?? 0 > 0 {
  199. haveFiles = true
  200. } else {
  201. haveFiles = false
  202. }
  203. updateActionButtonbackgroundColor()
  204. }
  205. func loadData() {
  206. self.tableView.reloadData()
  207. }
  208. func updateViewColor() {
  209. if KMAppearance.isDarkMode() {
  210. self.bottomBaseView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  211. self.addButton.layer?.backgroundColor = NSColor(red: 0.337, green: 0.345, blue: 0.353, alpha: 1).cgColor
  212. self.addButton.setTitleColor(NSColor.white)
  213. self.actionButton.layer?.backgroundColor = NSColor(red: 0.306, green: 0.498, blue: 0.859, alpha: 1).cgColor
  214. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  215. } else {
  216. self.bottomBaseView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1).cgColor
  217. self.addButton.layer?.backgroundColor = NSColor(red: 0.855, green: 0.859, blue: 0.871, alpha: 1).cgColor
  218. self.addButton.setTitleColor(NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1))
  219. self.actionButton.layer?.backgroundColor = NSColor(red: 0.153, green: 0.235, blue: 0.384, alpha: 1).cgColor
  220. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  221. }
  222. }
  223. func deleteAll() {
  224. if self.isBates {
  225. for waterMark in KMHeaderFooterManager.defaultManager.onlyBatesObjects {
  226. KMHeaderFooterManager.defaultManager.removeHeaderFooter(waterMark)
  227. }
  228. } else {
  229. for waterMark in KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects {
  230. KMHeaderFooterManager.defaultManager.removeHeaderFooter(waterMark)
  231. }
  232. }
  233. loadData()
  234. reloadTable()
  235. postNotification()
  236. }
  237. func reloadTable() {
  238. self.tableView.noteNumberOfRowsChanged()
  239. var count = 0
  240. var array: [KMHeaderFooterModel] = []
  241. if self.isBates {
  242. count = KMHeaderFooterManager.defaultManager.onlyBatesObjects.count
  243. array = KMHeaderFooterManager.defaultManager.onlyBatesObjects
  244. } else {
  245. count = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects.count
  246. array = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects
  247. }
  248. if array.contains(self.currentObject!) {
  249. let row = array.firstIndex(of: self.currentObject!)!
  250. let indexSet = IndexSet(integer: row)
  251. self.tableView.selectRowIndexes(indexSet, byExtendingSelection: false)
  252. }
  253. updateActionButtonbackgroundColor()
  254. }
  255. func postNotification() {
  256. NotificationCenter.default.post(name: NSNotification.Name("KMBatchOperateHeaderFootersNotification"), object: self)
  257. }
  258. @IBAction func buttonClicked_AddHeaderFooter(_ sender: Any) {
  259. // guard let windowController = self.view.window?.windowController else { return }
  260. // var filePath: String?
  261. // var password: String?
  262. // if let mainWC = windowController as? MainWindowController {
  263. // // filePath = mainWC.pdfView?.document?.documentURL?.path
  264. // // password = (mainWC.pdfView?.document as? CPDFDocument)?.password
  265. // }
  266. // let wc = KMHeaderFooterManagerWindowController(baseFile: filePath, headerFooter: nil, password: password, type: .KMBatchModifyTemplateType_Add)
  267. // wc.isBates = self.isBates
  268. // wc.operateCallBack = { [weak self] obj in
  269. // self?.currentObject = obj
  270. // self?.loadData()
  271. // self?.postNotification()
  272. // DispatchQueue.main.async {
  273. // guard let strongSelf = self else {
  274. // return
  275. // }
  276. // strongSelf.tableView.selectRowIndexes(IndexSet(integer: 0), byExtendingSelection: false)
  277. // }
  278. // }
  279. // wc.beginSheetModal(for: NSApp.keyWindow!, completionHandler: nil)
  280. let filePath: String = Bundle.main.path(forResource: "PDF Master User Guide", ofType: "pdf") ?? ""
  281. var cdocument = self.pdfView?.document
  282. if isBatchOperation {
  283. cdocument = CPDFDocument(url: URL(fileURLWithPath: filePath))
  284. }
  285. let windowController = KMHeaderFooterWindowController(windowNibName: "KMHeaderFooterWindowController")
  286. windowController.isBatch = isBatchOperation
  287. windowController.type = .Add
  288. windowController.isBates = isBates
  289. windowController.pdfDocument = cdocument
  290. windowController.cancelAction = { [unowned self] controller in
  291. self.km_endSheet()
  292. }
  293. windowController.operateCallBack = { wController, model in
  294. self.currentObject = model
  295. self.loadData()
  296. self.postNotification()
  297. let set = NSIndexSet(index: 0)
  298. self.tableView.selectRowIndexes(set as IndexSet, byExtendingSelection: false)
  299. }
  300. self.km_beginSheet(windowC: windowController)
  301. }
  302. @IBAction func buttonClicked_Action(_ sender: Any) {
  303. }
  304. func checkAndResetTask() -> Bool {
  305. if files?.count ?? 0 < 1 {
  306. return false
  307. }
  308. for i in 0..<(files?.count ?? 0) {
  309. if let file = files?[i] as? KMBatchOperateFile {
  310. if isBates {
  311. file.addBatesInfo.resetState()
  312. } else {
  313. file.addHeaderFooterInfo.resetState()
  314. }
  315. }
  316. }
  317. return true
  318. }
  319. func choosePathAndBeginOperation(_ obj: Any) {
  320. let openPanel = NSOpenPanel()
  321. openPanel.canChooseFiles = false
  322. openPanel.canChooseDirectories = true
  323. openPanel.canCreateDirectories = true
  324. openPanel.beginSheetModal(for: self.view.window!) { (result) in
  325. if result == NSApplication.ModalResponse.OK {
  326. for fileURL in openPanel.urls {
  327. self.choosePath = fileURL.path
  328. if self.isBates {
  329. self.beginAddBates(obj as! KMHeaderFooterModel)
  330. } else {
  331. self.beginAddHeaderFooter(obj as! KMHeaderFooterModel)
  332. }
  333. }
  334. }
  335. }
  336. }
  337. func beginAddBates(_ bates: KMHeaderFooterModel) {
  338. hiddenWindowCloseButtonIfNeeded()
  339. successFilePathURLArray?.removeAll()
  340. for i in 0..<(files?.count ?? 0) {
  341. if let file = files?[i] as? KMBatchOperateFile {
  342. if file.fileType == .PDF {
  343. file.addBatesInfo.savePath = choosePath
  344. if file.status == .Waiting {
  345. let operation = KMBatchAddHeaderFooterOperation(file: file, headerFooter: bates)
  346. operation.delegate = self
  347. queue?.addOperation(operation)
  348. }
  349. }
  350. }
  351. }
  352. if queue?.operationCount ?? 0 > 0 {
  353. interfaceStatus = .Processing
  354. }
  355. }
  356. func beginAddHeaderFooter(_ headerFooter: KMHeaderFooterModel) {
  357. hiddenWindowCloseButtonIfNeeded()
  358. successFilePathURLArray?.removeAll()
  359. for i in 0..<(files?.count ?? 0) {
  360. if let file = files?[i] as? KMBatchOperateFile {
  361. if file.fileType == .PDF {
  362. file.addHeaderFooterInfo.savePath = choosePath
  363. if file.status == .Waiting {
  364. let operation = KMBatchAddHeaderFooterOperation(file: file, headerFooter: headerFooter)
  365. operation.delegate = self
  366. queue?.addOperation(operation)
  367. }
  368. }
  369. }
  370. }
  371. if queue?.operationCount ?? 0 > 0 {
  372. interfaceStatus = .Processing
  373. }
  374. }
  375. func modify(obj: KMHeaderFooterModel) {
  376. // let windowController = self.view.window?.windowController
  377. // var filePath: String? = nil
  378. // var password: String? = nil
  379. // if let mainWindowController = windowController as? MainWindowController {
  380. // filePath = mainWindowController.mainViewController.listView?.document?.documentURL?.path
  381. // let document = mainWindowController.mainViewController.listView?.document as? CPDFDocument
  382. // password = document?.password
  383. // }
  384. // let wc = KMHeaderFooterManagerWindowController(baseFile: filePath, headerFooter: obj, password: password, type: .KMBatchModifyTemplateType_Edit)
  385. // wc?.isBates = self.isBates
  386. // let blockSelf = self
  387. // wc?.operateCallBack = { obj in
  388. // blockSelf.currentObject = obj
  389. // blockSelf.loadData()
  390. // blockSelf.reloadTable()
  391. // blockSelf.postNotification()
  392. // }
  393. // wc?.beginSheetModalForWindow(NSApp.keyWindow, completionHandler: nil)
  394. }
  395. func delete(obj: KMHeaderFooterModel) {
  396. KMHeaderFooterManager.defaultManager.removeHeaderFooter(obj)
  397. loadData()
  398. reloadTable()
  399. postNotification()
  400. }
  401. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  402. let action = menuItem.action
  403. if action == #selector(buttonItemClick_CleanAll(_:)) {
  404. if (self.isBates && KMHeaderFooterManager.defaultManager.onlyBatesObjects.count < 1) || (!self.isBates && KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects.count < 1){
  405. return false
  406. }
  407. return true
  408. }
  409. return true
  410. }
  411. func headerFooterInterfaceSelectHeaderFooter(headerFooter: KMHeaderFooterModel) {
  412. self.tableView.reloadData()
  413. if let index = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects.index(of: headerFooter) {
  414. let indexSet = IndexSet(integer: index)
  415. self.tableView.selectRowIndexes(indexSet, byExtendingSelection: false)
  416. }
  417. }
  418. func batesInterfaceSelectBates(headerFooter: KMHeaderFooterModel) {
  419. self.tableView.reloadData()
  420. if let index = KMHeaderFooterManager.defaultManager.onlyBatesObjects.index(of: headerFooter) {
  421. let indexSet = IndexSet(integer: index)
  422. self.tableView.selectRowIndexes(indexSet, byExtendingSelection: false)
  423. }
  424. }
  425. func numberOfRows(in tableView: NSTableView) -> Int {
  426. var count = 0
  427. if self.isBates {
  428. count = KMHeaderFooterManager.defaultManager.onlyBatesObjects.count
  429. } else {
  430. count = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects.count
  431. }
  432. self.blankView.isHidden = count != 0
  433. return count
  434. }
  435. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  436. var obj: KMHeaderFooterModel? = nil
  437. if self.isBates {
  438. obj = KMHeaderFooterManager.defaultManager.onlyBatesObjects[row]
  439. } else {
  440. obj = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects[row]
  441. }
  442. guard let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "mainCell"), owner: self) as? KMHeaderFooterTableCellView else {
  443. return nil
  444. }
  445. cellView.updateInterface(obj!)
  446. cellView.headerFooterTableCellViewCallback = { type in
  447. if type == .Edit {
  448. let indexSet = IndexSet(integer: row)
  449. self.tableView.selectRowIndexes(indexSet, byExtendingSelection: false)
  450. self.currentObject = obj
  451. self.modify(obj: obj!)
  452. } else {
  453. self.delete(obj: obj!)
  454. }
  455. }
  456. return cellView
  457. }
  458. func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
  459. let rowView = KMTableRowView()
  460. return rowView
  461. }
  462. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  463. if self.isBates {
  464. return KMHeaderFooterManager.defaultManager.onlyBatesObjects[row].cellHeight
  465. } else {
  466. return KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects[row].cellHeight
  467. }
  468. }
  469. func tableViewSelectionDidChange(_ notification: Notification) {
  470. let row = self.tableView.selectedRow
  471. updateActionButtonbackgroundColor()
  472. if row == -1 { return }
  473. if self.isBates {
  474. let bates = KMHeaderFooterManager.defaultManager.onlyBatesObjects[row]
  475. self.currentObject = bates
  476. for i in 0..<(self.files?.count ?? 0) {
  477. let file = self.files?[i]
  478. file?.addBatesInfo.pageChoice = KMBatchOperatePageChoice(rawValue: bates.pageRangeType.rawValue) ?? .All
  479. if file?.addBatesInfo.pageChoice == .Input {
  480. let arr = allPageNumbers(bates.pageRangeString)
  481. let sortedArray: NSArray = file!.pagesArrayIntersect(with: arr) as NSArray
  482. if sortedArray.count < 1 {
  483. file?.addBatesInfo.pageChoice = .All
  484. } else {
  485. file!.addBatesInfo.pageRangeString = sortedArray.componentsJoined(by: ",")
  486. }
  487. }
  488. }
  489. } else {
  490. let headerFooter = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects[row]
  491. self.currentObject = headerFooter
  492. for i in 0..<(self.files?.count ?? 0) {
  493. let file = self.files?[i]
  494. file?.addHeaderFooterInfo.pageChoice = KMBatchOperatePageChoice(rawValue: headerFooter.pageRangeType.rawValue) ?? .All
  495. if file?.addHeaderFooterInfo.pageChoice == .Input {
  496. let arr = allPageNumbers(headerFooter.pageRangeString)
  497. let sortedArray: NSArray = file!.pagesArrayIntersect(with: arr) as NSArray
  498. if sortedArray.count < 1 {
  499. file?.addHeaderFooterInfo.pageChoice = .All
  500. } else {
  501. file!.addHeaderFooterInfo.pageRangeString = sortedArray.componentsJoined(by: ",")
  502. }
  503. }
  504. }
  505. }
  506. reloadTable()
  507. NotificationCenter.default.post(name: NSNotification.Name(rawValue: kNeedChangePageRangeNotification), object: nil)
  508. }
  509. }