123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // KMBatesPropertyHomeController.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2022/12/28.
- //
- import Cocoa
- /// Bates 属性主控制器
- class KMBatesPropertyHomeController: KMWatermarkAdjectivePropertyMainController {
-
- override func viewDidLoad() {
- super.viewDidLoad()
- }
-
- override func gotoHomeController(_ selectedModelID: String) {
- let controller = KMBatesPropertyController()
- 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 = KMCreateBatesController()
- let model: KMHeaderFooterObject = KMHeaderFooterObject()
- model.type = .bates
- 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: KMCreateBatesController = self!.currentController as! KMCreateBatesController
- if (createController.model != nil) {
- let model: KMHeaderFooterObject = createController.model as! KMHeaderFooterObject
- if (!model.hasVaild) {
- let alert = NSAlert()
- alert.alertStyle = .warning
- alert.messageText = NSLocalizedString("Failure", comment: "")
- alert.runModal()
- return
- }
- let result = KMHeaderFooterManager.defaultManager.addHeaderFooter(model)
- 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 = KMCreateBatesController()
- 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: KMCreateBatesController = self!.currentController as! KMCreateBatesController
- if (editController.isEdited) {
- /// 更新模板
- let result = KMHeaderFooterManager.defaultManager.store()
- // if (result) {
-
- self!.gotoHomeController("")
- // }
- } else {
- self!.gotoHomeController("")
- }
- }
- controller.rightButtonClick = { [weak self] index in
- let editController: KMCreateBatesController = self!.currentController as! KMCreateBatesController
- editController.resume()
- }
- }
-
- }
|