123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- //
- // KMHeaderFooterController.swift
- // PDF Reader Pro
- //
- // 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: KMHeaderFooterObject = KMHeaderFooterObject()
- 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: KMHeaderFooterObject = createController.model as! KMHeaderFooterObject
- if (!model.hasVaild) {
- let alert = NSAlert()
- alert.alertStyle = .warning
- alert.messageText = NSLocalizedString("未找到内容", comment: "")
- alert.runModal()
- return
- }
-
- KMHeaderFooterManager.defaultManager.addHeaderFooter(createController.model as! KMHeaderFooterObject)
- 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.store()
- // if (result) {
-
- self!.gotoHomeController("")
- // }
- } else {
- self!.gotoHomeController("")
- }
- }
- controller.rightButtonClick = { [weak self] index in
- let editController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
- editController.resume()
- }
- }
- }
|