KMWatermarkPropertyCreateController.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // KMWatermarkPropertyCreateController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/16.
  6. //
  7. import Cocoa
  8. class KMWatermarkPropertyCreateController: KMWatermarkAdjectivePropertyBaseController {
  9. var isEdit: Bool = false
  10. var editType: Int = 0
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. self.backButtton.title = NSLocalizedString("", comment: "")
  14. self.showBack(show: true)
  15. self.titleLabel.stringValue = NSLocalizedString("Add Watermark", comment: "")
  16. self.addButton.attributedTitle = NSAttributedString(string: NSLocalizedString("", comment: ""), attributes: [NSAttributedString.Key.foregroundColor : NSColor(red: 24.0/255.0, green: 160.0/255.0, blue: 251.0/255.0, alpha: 1.0),NSAttributedString.Key.font : NSFont.systemFont(ofSize: 12), NSAttributedString.Key.underlineStyle : true])
  17. self.segementControl.items = [NSLocalizedString("Text", comment: ""),NSLocalizedString("File", comment: "")]
  18. self.segementControl.itemClick = {
  19. [self] (index: Int) in
  20. if (self.isEdit) {
  21. self.segementControl.selectItemIndex = self.editType
  22. } else {
  23. self.tabView.selectTabViewItem(at: index)
  24. }
  25. }
  26. if (self.isEdit) {
  27. self.titleLabel.stringValue = NSLocalizedString("Edit Watermark", comment: "")
  28. self.addButton.attributedTitle = NSAttributedString(string: NSLocalizedString("", comment: ""), attributes: [NSAttributedString.Key.foregroundColor : NSColor(red: 24.0/255.0, green: 160.0/255.0, blue: 251.0/255.0, alpha: 1.0),NSAttributedString.Key.font : NSFont.systemFont(ofSize: 12), NSAttributedString.Key.underlineStyle : true])
  29. } else {
  30. self.addButton.attributedTitle = NSAttributedString(string: NSLocalizedString("", comment: ""), attributes: [NSAttributedString.Key.foregroundColor : NSColor(red: 24.0/255.0, green: 160.0/255.0, blue: 251.0/255.0, alpha: 1.0),NSAttributedString.Key.font : NSFont.systemFont(ofSize: 12), NSAttributedString.Key.underlineStyle : true])
  31. }
  32. let item = NSTabViewItem(identifier: "tabID")
  33. item.label = "tab1";
  34. let controller = KMWatermarkPropertyInfoController(nibName: "KMWatermarkPropertyInfoController", bundle: nil)
  35. controller.type = .text
  36. item.viewController = controller
  37. controller.model = self.model as! KMWatermarkModel
  38. controller.delegate = self
  39. let item2 = NSTabViewItem(identifier: "tablID2")
  40. item2.label = "tab2";
  41. let controller2 = KMWatermarkPropertyInfoController(nibName: "KMWatermarkPropertyInfoController", bundle: nil)
  42. controller2.type = .file
  43. item2.viewController = controller2
  44. controller2.model = self.model as! KMWatermarkModel
  45. controller2.delegate = self
  46. self.tabView.addTabViewItem(item)
  47. self.tabView.addTabViewItem(item2)
  48. childViewController.append(controller)
  49. childViewController.append(controller2)
  50. if (self.isEdit) {
  51. self.segementControl.isHidden = true
  52. self.segementControlHeightConst.constant = 0
  53. }
  54. }
  55. func updateModel(model: KMWatermarkModel, type: Int) {
  56. self.editType = type
  57. self.selectTabIndex(index: type)
  58. self.model = model
  59. var count: Int = 0
  60. for controller in childViewController {
  61. let infoController: KMWatermarkPropertyInfoController = controller as! KMWatermarkPropertyInfoController
  62. if (count == type) {
  63. infoController.updateModel(model: model)
  64. }
  65. count += 1
  66. }
  67. }
  68. override func resume() {
  69. if (self.flagModel == nil) {
  70. return
  71. }
  72. if (childViewController.count <= 0) {
  73. return
  74. }
  75. let controller: KMWatermarkPropertyInfoController = childViewController[0] as! KMWatermarkPropertyInfoController
  76. controller.updateModel(model: self.flagModel!.copy() as! KMWatermarkModel)
  77. }
  78. }
  79. extension KMWatermarkPropertyCreateController: KMWatermarkAdjectivePropertyDelegate {
  80. func propertyInfoDidChange(model: AnyObject) {
  81. if (self.delegate != nil) {
  82. self.delegate!.propertyInfoDidChange(model: model)
  83. }
  84. }
  85. }