KMBackgroundPropertyHomeController.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // KMBackgroundPropertyHomeController.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/1/5.
  6. //
  7. import Cocoa
  8. /// 背景 属性主控制器
  9. class KMBackgroundPropertyHomeController: KMWatermarkAdjectivePropertyMainController {
  10. var preView: CPDFView!
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. }
  14. override func gotoHomeController(_ selectedModelID: String) {
  15. let propertyController = KMBackgroundPropertyController()
  16. propertyController.preView = self.preView
  17. self.showController(propertyController)
  18. propertyController.rightButtonClick = { [weak self] index in
  19. /// 创建背景
  20. self!.gotoCreateController()
  21. }
  22. propertyController.menuItemClick = { [weak self] index, model in
  23. self?.gotoEditController(model)
  24. }
  25. propertyController.templateDidSelected = { [weak self] model, isSelected in
  26. if (isSelected) {
  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 createController = KMCreateBackgroundController()
  39. createController.delegate = self
  40. createController.preView = self.preView
  41. self.showController(createController)
  42. createController.backClick = { [weak self] in
  43. self?.gotoHomeController("")
  44. }
  45. createController.rightButtonClick = { [weak self] index in
  46. /// 保存到模板
  47. let templateModel = (self!.currentController as! KMCreateBackgroundController).fetchTemplate()
  48. let result = KMBackgroundManager.defaultManager.addTemplate(model: templateModel as! KMBackgroundModel)
  49. if (result) {
  50. /// 返回模板列表
  51. self?.gotoHomeController("")
  52. let propertyConroller: KMBackgroundPropertyController = self!.currentController as! KMBackgroundPropertyController
  53. if (index == 0) { /// 颜色
  54. propertyConroller.selectTabIndex(index: 0)
  55. } else if (index == 1) { /// 文件
  56. propertyConroller.selectTabIndex(index: 1)
  57. }
  58. }
  59. }
  60. self.model = createController.fetchTemplate() as! KMBackgroundModel
  61. guard let callback = self.modelDidChange else {
  62. return
  63. }
  64. callback(self.model)
  65. }
  66. override func gotoEditController(_ model: KMWatermarkAdjectiveBaseModel) {
  67. let editController = KMEditBackgroundController()
  68. editController.editModel = model as! KMBackgroundModel
  69. editController.flagModel = model.copy() as AnyObject
  70. self.showController(editController)
  71. editController.backClick = { [weak self] in
  72. let editController: KMEditBackgroundController = self!.currentController as! KMEditBackgroundController
  73. if (editController.isEdited) {
  74. KMBackgroundManager.defaultManager.updateTemplate(model: editController.editModel)
  75. }
  76. self?.gotoHomeController("")
  77. }
  78. editController.rightButtonClick = { [weak self] index in
  79. let editController: KMEditBackgroundController = self!.currentController as! KMEditBackgroundController
  80. editController.resume()
  81. }
  82. }
  83. }
  84. extension KMBackgroundPropertyHomeController: KMWatermarkAdjectivePropertyDelegate {
  85. func propertyInfoDidChange(model: AnyObject) {
  86. self.model = (model as! KMBackgroundModel)
  87. guard let callback = self.modelDidChange else {
  88. return
  89. }
  90. callback(self.model!)
  91. }
  92. }