KMHeaderFooterPropertyMainController.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // KMHeaderFooterController.swift
  3. // PDF Master
  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: KMHeaderFooterModel = KMHeaderFooterModel()
  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: KMHeaderFooterModel = createController.model as! KMHeaderFooterModel
  51. if (!model.hasVaild) {
  52. let alert = NSAlert()
  53. alert.alertStyle = .warning
  54. alert.messageText = NSLocalizedString("未找到内容", comment: "")
  55. alert.runModal()
  56. return
  57. }
  58. let result = KMHeaderFooterManager.defaultManager.addTemplate(createController.model as! KMHeaderFooterModel)
  59. if (result) {
  60. guard let callback = self!.modelDidChange else {
  61. return
  62. }
  63. self?.model = model
  64. callback(self!.model)
  65. self!.gotoHomeController(model.id)
  66. }
  67. }
  68. }
  69. controller.modelDidChange = { [weak self] model in
  70. /// 模型已经修改,可以再这里刷新预览视图
  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 = KMCreateHeaderFooterController()
  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: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
  87. if (editController.isEdited) {
  88. /// 更新模板
  89. let result = KMHeaderFooterManager.defaultManager.updateTemplate(editController.model as! KMHeaderFooterModel)
  90. // if (result) {
  91. self!.gotoHomeController("")
  92. // }
  93. } else {
  94. self!.gotoHomeController("")
  95. }
  96. }
  97. controller.rightButtonClick = { [weak self] index in
  98. let editController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
  99. editController.resume()
  100. }
  101. }
  102. }