KMBatesPropertyHomeController.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // KMBatesPropertyHomeController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/28.
  6. //
  7. import Cocoa
  8. /// Bates 属性主控制器
  9. class KMBatesPropertyHomeController: KMWatermarkAdjectivePropertyMainController {
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. }
  13. override func gotoHomeController(_ selectedModelID: String) {
  14. let controller = KMBatesPropertyController()
  15. controller.controller.selectedTemplateID = selectedModelID
  16. self.showController(controller)
  17. controller.rightButtonClick = { [weak self] index in
  18. self!.gotoCreateController()
  19. }
  20. controller.menuItemClick = { [weak self] index, model in
  21. if (index == 2) { /// 编辑
  22. self!.gotoEditController(model)
  23. }
  24. }
  25. controller.templateDidSelected = { [weak self] model, selected in
  26. if (selected) { /// 模板已选中,
  27. self!.model = model
  28. } else { /// 模板取消选中
  29. self!.model = nil
  30. }
  31. guard let callback = self!.modelDidChange else {
  32. return
  33. }
  34. callback(self?.model)
  35. }
  36. }
  37. override func gotoCreateController() {
  38. let controller = KMCreateBatesController()
  39. let model: KMHeaderFooterObject = KMHeaderFooterObject()
  40. model.type = .bates
  41. model.pageCount = self.pageCount
  42. controller.model = model
  43. self.showController(controller)
  44. controller.backClick = { [weak self] in
  45. self?.gotoHomeController("")
  46. }
  47. controller.rightButtonClick = { [weak self] index in
  48. /// 保存到模板
  49. let createController: KMCreateBatesController = self!.currentController as! KMCreateBatesController
  50. if (createController.model != nil) {
  51. let model: KMHeaderFooterObject = createController.model as! KMHeaderFooterObject
  52. if (!model.hasVaild) {
  53. let alert = NSAlert()
  54. alert.alertStyle = .warning
  55. alert.messageText = NSLocalizedString("Failure", comment: "")
  56. alert.runModal()
  57. return
  58. }
  59. let result = KMHeaderFooterManager.defaultManager.addHeaderFooter(model)
  60. if (result) {
  61. guard let callback = self!.modelDidChange else {
  62. return
  63. }
  64. self?.model = model
  65. callback(self?.model)
  66. self?.gotoHomeController(model.id)
  67. }
  68. }
  69. }
  70. controller.modelDidChange = { [weak self] model in
  71. self?.model = model
  72. guard let callback = self!.modelDidChange else {
  73. return
  74. }
  75. callback(self?.model)
  76. }
  77. }
  78. override func gotoEditController(_ model: KMWatermarkAdjectiveBaseModel) {
  79. let controller = KMCreateBatesController()
  80. controller.isEdit = true
  81. model.pageCount = self.pageCount
  82. controller.model = model
  83. controller.flagModel = model.copy() as AnyObject
  84. self.showController(controller)
  85. controller.backClick = { [weak self] in
  86. let editController: KMCreateBatesController = self!.currentController as! KMCreateBatesController
  87. if (editController.isEdited) {
  88. /// 更新模板
  89. let result = KMHeaderFooterManager.defaultManager.store()
  90. // if (result) {
  91. self!.gotoHomeController("")
  92. // }
  93. } else {
  94. self!.gotoHomeController("")
  95. }
  96. }
  97. controller.rightButtonClick = { [weak self] index in
  98. let editController: KMCreateBatesController = self!.currentController as! KMCreateBatesController
  99. editController.resume()
  100. }
  101. }
  102. }