123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // KMHeaderFooterController.swift
- // PDF Master
- //
- // Created by tangchao on 2022/12/26.
- //
- import Cocoa
- /// 页眉页脚 属性主控制器
- class KMHeaderFooterPropertyMainController: KMWatermarkAdjectivePropertyMainController {
- override func viewDidLoad() {
- super.viewDidLoad()
- }
-
- override func gotoHomeController(_ selectedModelID: String) {
- let controller = KMHeaderFooterPropertyController()
- controller.controller.selectedTemplateID = selectedModelID
-
- self.showController(controller)
-
- controller.rightButtonClick = { [weak self] index in
- self!.gotoCreateController()
- }
-
- controller.menuItemClick = { [weak self] index, model in
- if (index == 2) { /// 编辑
- self!.gotoEditController(model)
- }
- }
-
- controller.templateDidSelected = { [weak self] model, selected in
- if (selected) { /// 模板已选中,
- self!.model = model
- } else { /// 模板取消选中
- self!.model = nil
- }
-
- guard let callback = self!.modelDidChange else {
- return
- }
-
- callback(self!.model)
- }
- }
-
- override func gotoCreateController() {
- let controller = KMCreateHeaderFooterController()
- let model: KMHeaderFooterModel = KMHeaderFooterModel()
- model.pageCount = self.pageCount
- controller.model = model
-
- self.showController(controller)
-
- controller.backClick = { [weak self] in
- self!.gotoHomeController("")
- }
-
- controller.rightButtonClick = { [weak self] index in
- /// 保存到模板
- let createController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
- if (createController.model != nil) {
- let model: KMHeaderFooterModel = createController.model as! KMHeaderFooterModel
- if (!model.hasVaild) {
- let alert = NSAlert()
- alert.alertStyle = .warning
- alert.messageText = NSLocalizedString("未找到内容", comment: "")
- alert.runModal()
- return
- }
-
- let result = KMHeaderFooterManager.defaultManager.addTemplate(createController.model as! KMHeaderFooterModel)
- if (result) {
- guard let callback = self!.modelDidChange else {
- return
- }
- self?.model = model
- callback(self!.model)
-
- self!.gotoHomeController(model.id)
- }
- }
- }
-
- controller.modelDidChange = { [weak self] model in
- /// 模型已经修改,可以再这里刷新预览视图
- self?.model = model
- guard let callback = self!.modelDidChange else {
- return
- }
-
- callback(self?.model)
- }
- }
-
-
- override func gotoEditController(_ model: KMWatermarkAdjectiveBaseModel) {
- let controller = KMCreateHeaderFooterController()
- controller.isEdit = true
- model.pageCount = self.pageCount
- controller.model = model
- controller.flagModel = model.copy() as AnyObject
-
- self.showController(controller)
-
- controller.backClick = { [weak self] in
- let editController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
- if (editController.isEdited) {
- /// 更新模板
- let result = KMHeaderFooterManager.defaultManager.updateTemplate(editController.model as! KMHeaderFooterModel)
- // if (result) {
-
- self!.gotoHomeController("")
- // }
- } else {
- self!.gotoHomeController("")
- }
- }
- controller.rightButtonClick = { [weak self] index in
- let editController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
- editController.resume()
- }
- }
- }
|