KMPageEditInsertCustomPageWindowController.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // KMPageEditInsertCustomPageWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/1/11.
  6. //
  7. typealias KMPageEditInsertCustomPageItemClick = (_ index: Int) -> ()
  8. class KMPageEditInsertCustomPageWindowController: KMBaseWindowController {
  9. @IBOutlet weak var titleLabel: NSTextField!
  10. @IBOutlet weak var typeBox: NSBox!
  11. @IBOutlet weak var pageSizeBox: NSBox!
  12. @IBOutlet weak var directionBox: NSBox!
  13. var typeView = KMPageEditInsertTypeItemView()
  14. var pageSizeView = KMPageEditInsertPageSizeItemView()
  15. var directionView = KMPageEditInsertDirectionItemView()
  16. @IBOutlet weak var cancelButton: NSButton!
  17. @IBOutlet weak var insertButton: NSButton!
  18. var cancelVC: KMDesignButton?
  19. var insertVC: KMDesignButton?
  20. var selectedPageSize: NSSize = NSZeroSize
  21. var itemClick: KMPageEditInsertCustomPageItemClick!
  22. convenience init() {
  23. self.init(windowNibName: "KMPageEditInsertCustomPageWindowController")
  24. }
  25. var typeIndex: Int {
  26. get {
  27. // self.typeView.selectedIndex
  28. return 1
  29. }
  30. }
  31. var pageSize: NSSize {
  32. get {
  33. self.pageSizeView.getPageSize
  34. }
  35. }
  36. var direction: Int {
  37. get {
  38. return self.directionView.getDirection()
  39. }
  40. }
  41. override func windowDidLoad() {
  42. super.windowDidLoad()
  43. // self.typeBox.contentView?.addSubview(self.typeView)
  44. // self.typeView.frame = self.typeBox.contentView!.bounds
  45. // self.typeView.autoresizingMask = [.width, .height]
  46. // self.typeView.items = [(NSLocalizedString("Blank page", comment: ""), ""),
  47. // (NSLocalizedString("Line page", comment: ""), "horizontal_line"),
  48. // (NSLocalizedString("Five line score", comment: ""), "five_line_score"),
  49. // (NSLocalizedString("Plaid page", comment: ""), "plaid")]
  50. }
  51. override func initDefaultValue() {
  52. super.initDefaultValue()
  53. self.titleLabel.stringValue = NSLocalizedString("Insert Custom Page", comment: "")
  54. self.titleLabel.font = .SFProTextSemiboldFont(16)
  55. self.titleLabel.textColor = KMAppearance.titleColor()
  56. self.cancelVC?.target = self
  57. self.cancelVC?.action = #selector(cancelButtonAction)
  58. self.cancelVC?.stringValue = NSLocalizedString("Cancel", comment: "")
  59. self.cancelVC?.button(type: .Sec, size: .m)
  60. self.cancelVC?.button.keyEquivalent = KMKeyEquivalent.esc.string()
  61. self.insertVC?.target = self
  62. self.insertVC?.action = #selector(insertButtonAction)
  63. self.insertVC?.stringValue = NSLocalizedString("Insert", comment: "")
  64. self.insertVC?.button(type: .Cta, size: .m)
  65. self.insertVC?.button.keyEquivalent = KMKeyEquivalent.enter
  66. }
  67. override func initSubViews() {
  68. super.initSubViews()
  69. self.pageSizeBox.contentView = self.pageSizeView
  70. self.pageSizeView.selectedPageSize = self.selectedPageSize
  71. self.pageSizeView.itemClick = { [unowned self] index, params in
  72. if (index == 1) { /// 当前页
  73. var radioIndex: Int = 0
  74. if let value = params.first as? Int {
  75. radioIndex = value
  76. }
  77. if (radioIndex == 1) { // 当前页
  78. } else if (radioIndex == 2) { /// 标准
  79. } else if (radioIndex == 3) { /// 自定义
  80. }
  81. } else if (index == 2) { /// 标准[下拉框]
  82. let size = self.pageSizeView.getPageSize
  83. if (size.width > size.height) {
  84. self.directionView.switchDirection(isHor: true)
  85. } else {
  86. self.directionView.switchDirection(isHor: false)
  87. }
  88. } else if (index == 3) { /// 自定义[宽度]
  89. let size = self.pageSizeView.getCustomSize
  90. if (size.width > size.height) {
  91. self.directionView.switchDirection(isHor: true)
  92. } else {
  93. self.directionView.switchDirection(isHor: false)
  94. }
  95. } else if (index == 4) { /// 自定义[高度]
  96. let size = self.pageSizeView.getCustomSize
  97. if (size.height > size.width) {
  98. self.directionView.switchDirection(isHor: false)
  99. } else {
  100. self.directionView.switchDirection(isHor: true)
  101. }
  102. } else if (index == 5) { /// 自定义[下拉框]
  103. }
  104. }
  105. self.directionBox.contentView = self.directionView
  106. self.directionView.itemClick = { [unowned self] index, value in
  107. if (index == 1) { /// 横向页面
  108. self.pageSizeView.changeDirection(isHor: true)
  109. } else if (index == 2) { /// 纵向页面
  110. self.pageSizeView.changeDirection(isHor: false)
  111. }
  112. }
  113. self.cancelVC = KMDesignButton(withType: .Text)
  114. self.cancelButton.addSubview(self.cancelVC!.view)
  115. self.cancelVC?.view.frame = self.cancelButton.bounds
  116. self.cancelVC?.view.autoresizingMask = [.width, .height]
  117. self.insertVC = KMDesignButton(withType: .Text)
  118. self.insertButton.addSubview(self.insertVC!.view)
  119. self.insertVC?.view.frame = self.insertButton.bounds
  120. self.insertVC?.view.autoresizingMask = [.width, .height]
  121. }
  122. @objc func cancelButtonAction() {
  123. guard let callback = self.itemClick else {
  124. return
  125. }
  126. callback(1)
  127. }
  128. @objc func insertButtonAction() {
  129. guard let callback = self.itemClick else {
  130. return
  131. }
  132. callback(2)
  133. }
  134. }