KMPageEditInsertCustomPageWindowController.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // KMPageEditInsertCustomPageWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/1/11.
  6. //
  7. import Cocoa
  8. typealias KMPageEditInsertCustomPageItemClick = (_ index: Int) -> ()
  9. class KMPageEditInsertCustomPageWindowController: NSWindowController {
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var typeBox: NSBox!
  12. @IBOutlet weak var pageSizeBox: NSBox!
  13. @IBOutlet weak var directionBox: NSBox!
  14. var typeView = KMPageEditInsertTypeItemView()
  15. var pageSizeView = KMPageEditInsertPageSizeItemView()
  16. var directionView = KMPageEditInsertDirectionItemView()
  17. @IBOutlet weak var cancelButton: NSButton!
  18. @IBOutlet weak var insertButton: NSButton!
  19. var selectedPageSize: NSSize = NSZeroSize
  20. var itemClick: KMPageEditInsertCustomPageItemClick!
  21. var typeIndex: Int {
  22. get {
  23. self.typeView.selectedIndex
  24. }
  25. }
  26. var pageSize: NSSize {
  27. get {
  28. self.pageSizeView.getPageSize
  29. }
  30. }
  31. var direction: Int {
  32. get {
  33. return self.directionView.getDirection()
  34. }
  35. }
  36. override func windowDidLoad() {
  37. super.windowDidLoad()
  38. self.titleLabel.stringValue = NSLocalizedString("Insert Custom Page", comment: "")
  39. self.typeBox.contentView?.addSubview(self.typeView)
  40. self.typeView.frame = self.typeBox.contentView!.bounds
  41. self.typeView.autoresizingMask = [.width, .height]
  42. self.typeView.items = [(NSLocalizedString("Blank page", comment: ""), ""),
  43. (NSLocalizedString("Line page", comment: ""), "horizontal_line"),
  44. (NSLocalizedString("Five line score", comment: ""), "five_line_score"),
  45. (NSLocalizedString("Plaid page", comment: ""), "plaid")]
  46. self.pageSizeBox.contentView?.addSubview(self.pageSizeView)
  47. self.pageSizeView.frame = self.pageSizeBox.contentView!.bounds
  48. self.pageSizeView.autoresizingMask = [.width, .height]
  49. self.pageSizeView.selectedPageSize = self.selectedPageSize
  50. self.pageSizeView.itemClick = { [weak self] (index: Int, value: Any) in
  51. if (index == 1) { /// 当前页
  52. let radioIndex: Int = value as! Int
  53. if (radioIndex == 1) { // 当前页
  54. } else if (radioIndex == 2) { /// 标准
  55. } else if (radioIndex == 3) { /// 自定义
  56. }
  57. } else if (index == 2) { /// 标准[下拉框]
  58. } else if (index == 3) { /// 自定义[宽度]
  59. let size = self?.pageSizeView.getCustomSize
  60. if (size!.width > size!.height) {
  61. self?.directionView.switchDirection(isHor: true)
  62. } else {
  63. self?.directionView.switchDirection(isHor: false)
  64. }
  65. } else if (index == 4) { /// 自定义[高度]
  66. let size = self?.pageSizeView.getCustomSize
  67. if (size!.height > size!.width) {
  68. self?.directionView.switchDirection(isHor: false)
  69. } else {
  70. self?.directionView.switchDirection(isHor: true)
  71. }
  72. } else if (index == 5) { /// 自定义[下拉框]
  73. }
  74. }
  75. self.directionBox.contentView?.addSubview(self.directionView)
  76. self.directionView.frame = self.directionBox.contentView!.bounds
  77. self.directionView.autoresizingMask = [.width, .height]
  78. self.directionView.itemClick = { [weak self] (index: Int, value: Any) in
  79. if (index == 1) { /// 横向页面
  80. self?.pageSizeView.changeDirection(isHor: true)
  81. } else if (index == 2) { /// 纵向页面
  82. self?.pageSizeView.changeDirection(isHor: false)
  83. }
  84. }
  85. cancelButton.title = NSLocalizedString("Cancel", comment: "")
  86. cancelButton.isBordered = false
  87. cancelButton.wantsLayer = true
  88. cancelButton.layer?.borderWidth = 1
  89. cancelButton.layer?.borderColor = NSColor.black.cgColor
  90. cancelButton.layer?.cornerRadius = 4
  91. cancelButton.target = self
  92. cancelButton.action = #selector(cancelButtonAction)
  93. insertButton.title = NSLocalizedString("Insert", comment: "")
  94. insertButton.isBordered = false
  95. insertButton.wantsLayer = true
  96. insertButton.layer?.cornerRadius = 4
  97. insertButton.target = self
  98. insertButton.action = #selector(insertButtonAction)
  99. insertButton.layer?.backgroundColor = NSColor.black.cgColor
  100. insertButton.attributedTitle = NSMutableAttributedString(string: insertButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white])
  101. }
  102. @objc func cancelButtonAction() {
  103. guard let callback = self.itemClick else {
  104. return
  105. }
  106. callback(1)
  107. }
  108. @objc func insertButtonAction() {
  109. guard let callback = self.itemClick else {
  110. return
  111. }
  112. callback(2)
  113. }
  114. }