KMHeaderFooterPropertyMainController.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // KMHeaderFooterController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/26.
  6. //
  7. import Cocoa
  8. /// 页眉页脚 属性主控制器
  9. class KMHeaderFooterPropertyMainController: KMWatermarkAdjectivePropertyMainController {
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. }
  13. override func gotoHomeController(_ selectedModelID: String) {
  14. let controller = KMHeaderFooterPropertyController()
  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 = KMCreateHeaderFooterController()
  39. let model: KMHeaderFooterObject = KMHeaderFooterObject()
  40. model.pageCount = self.pageCount
  41. controller.model = model
  42. self.showController(controller)
  43. controller.backClick = { [weak self] in
  44. self!.gotoHomeController("")
  45. }
  46. controller.rightButtonClick = { [weak self] index in
  47. /// 保存到模板
  48. let createController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
  49. if (createController.model != nil) {
  50. let model: KMHeaderFooterObject = createController.model as! KMHeaderFooterObject
  51. if (!model.hasVaild) {
  52. let alert = NSAlert()
  53. alert.alertStyle = .warning
  54. alert.messageText = NSLocalizedString("未找到内容", comment: "")
  55. alert.runModal()
  56. return
  57. }
  58. KMHeaderFooterManager.defaultManager.addHeaderFooter(createController.model as! KMHeaderFooterObject)
  59. guard let callback = self!.modelDidChange else {
  60. return
  61. }
  62. self?.model = model
  63. callback(self!.model)
  64. self!.gotoHomeController(model.id)
  65. }
  66. }
  67. controller.modelDidChange = { [weak self] model in
  68. /// 模型已经修改,可以再这里刷新预览视图
  69. self?.model = model
  70. guard let callback = self!.modelDidChange else {
  71. return
  72. }
  73. callback(self?.model)
  74. }
  75. }
  76. override func gotoEditController(_ model: KMWatermarkAdjectiveBaseModel) {
  77. let controller = KMCreateHeaderFooterController()
  78. controller.isEdit = true
  79. model.pageCount = self.pageCount
  80. controller.model = model
  81. controller.flagModel = model.copy() as AnyObject
  82. self.showController(controller)
  83. controller.backClick = { [weak self] in
  84. let editController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
  85. if (editController.isEdited) {
  86. /// 更新模板
  87. let result = KMHeaderFooterManager.defaultManager.store()
  88. // if (result) {
  89. self!.gotoHomeController("")
  90. // }
  91. } else {
  92. self!.gotoHomeController("")
  93. }
  94. }
  95. controller.rightButtonClick = { [weak self] index in
  96. let editController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
  97. editController.resume()
  98. }
  99. }
  100. }