// // 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!) } }