123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // KMBackgroundPropertyHomeController.swift
- // PDF Master
- //
- // Created by tangchao on 2023/1/5.
- //
- import Cocoa
- /// 背景 属性主控制器
- class KMBackgroundPropertyHomeController: KMWatermarkAdjectivePropertyMainController {
- var preView: CPDFView!
-
- override func viewDidLoad() {
- super.viewDidLoad()
- }
-
- override func gotoHomeController(_ selectedModelID: String) {
- let propertyController = KMBackgroundPropertyController()
- propertyController.preView = self.preView
-
- self.showController(propertyController)
-
- propertyController.rightButtonClick = { [weak self] index in
-
- /// 创建背景
- self!.gotoCreateController()
- }
-
- propertyController.menuItemClick = { [weak self] index, model in
- self?.gotoEditController(model)
- }
-
- propertyController.templateDidSelected = { [weak self] model, isSelected in
- if (isSelected) {
- self?.model = model
- } else {
- self?.model = nil
- }
-
- guard let callback = self?.modelDidChange else {
- return
- }
- callback(self?.model)
- }
- }
-
- override func gotoCreateController() {
- let createController = KMCreateBackgroundController()
- createController.delegate = self
-
- createController.preView = self.preView
-
- self.showController(createController)
-
- createController.backClick = { [weak self] in
- self?.gotoHomeController("")
- }
-
- createController.rightButtonClick = { [weak self] index in
- /// 保存到模板
- let templateModel = (self!.currentController as! KMCreateBackgroundController).fetchTemplate()
-
- let result = KMBackgroundManager.defaultManager.addTemplate(model: templateModel as! KMBackgroundModel)
- if (result) {
- /// 返回模板列表
- self?.gotoHomeController("")
- let propertyConroller: KMBackgroundPropertyController = self!.currentController as! KMBackgroundPropertyController
- if (index == 0) { /// 颜色
- propertyConroller.selectTabIndex(index: 0)
- } else if (index == 1) { /// 文件
- propertyConroller.selectTabIndex(index: 1)
- }
- }
- }
-
- self.model = createController.fetchTemplate() as! KMBackgroundModel
- guard let callback = self.modelDidChange else {
- return
- }
- callback(self.model)
- }
-
- override func gotoEditController(_ model: KMWatermarkAdjectiveBaseModel) {
- let editController = KMEditBackgroundController()
- editController.editModel = model as! KMBackgroundModel
- editController.flagModel = model.copy() as AnyObject
-
- self.showController(editController)
-
- editController.backClick = { [weak self] in
- let editController: KMEditBackgroundController = self!.currentController as! KMEditBackgroundController
- if (editController.isEdited) {
- KMBackgroundManager.defaultManager.updateTemplate(model: editController.editModel)
- }
-
- self?.gotoHomeController("")
- }
-
- editController.rightButtonClick = { [weak self] index in
- let editController: KMEditBackgroundController = self!.currentController as! KMEditBackgroundController
- editController.resume()
- }
- }
- }
- extension KMBackgroundPropertyHomeController: KMWatermarkAdjectivePropertyDelegate {
- func propertyInfoDidChange(model: AnyObject) {
- self.model = (model as! KMBackgroundModel)
- guard let callback = self.modelDidChange else {
- return
- }
- callback(self.model!)
- }
- }
|