KMPageEditSplitWindowController.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // KMPageEditSplitWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/1/12.
  6. //
  7. import Cocoa
  8. class KMPageEditSplitWindowController: KMPageEditSettingBaseWindowController {
  9. var hasPreView: Bool = false
  10. override var model: KMPageEditSettingBaseModel? {
  11. get {
  12. return super.model
  13. }
  14. set {
  15. super.model = newValue
  16. }
  17. }
  18. override func windowDidLoad() {
  19. super.windowDidLoad()
  20. if (hasPreView) {
  21. setWindowSize(NSSize(width: 583, height: 481))
  22. self.titleLabel.stringValue = NSLocalizedString("Split", comment: "")
  23. } else {
  24. setWindowSize(NSSize(width: 480, height: 481))
  25. self.titleLabel.stringValue = NSLocalizedString("Split Page", comment: "")
  26. }
  27. funcButton.title = NSLocalizedString("Split", comment: "")
  28. funcButton.layer?.backgroundColor = NSColor.black.cgColor
  29. funcButton.attributedTitle = NSMutableAttributedString(string: funcButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white])
  30. if (hasPreView) {
  31. let controller = KMPDFInsertPreviewViewController(nibName: "KMPDFInsertPreviewViewController", bundle: nil)
  32. controller.pdfDocument = CPDFDocument(url: self.model?.documentURL)
  33. self.contentBox.contentView?.addSubview(controller.view)
  34. controller.view.frame = NSMakeRect(0, 40, 176+16*2, 300)
  35. controller.view.autoresizingMask = [.maxYMargin]
  36. let settingView: KMPageEditSplitSettingView = KMPageEditSplitSettingView.createFromNib()!
  37. self.contentBox.contentView?.addSubview(settingView)
  38. let settingViewLeft: CGFloat = 176+16+8
  39. settingView.frame = NSRect(x: settingViewLeft, y: 0, width: NSWidth(self.contentBox.frame)-settingViewLeft, height: NSHeight(self.contentBox.frame))
  40. settingView.autoresizingMask = [.width, .height]
  41. self.settingView = settingView
  42. settingView.oneFileForOnePageStepper.maxValue = Double(self.model!.pageCount)
  43. settingView.splitMuitiFileStepper.maxValue = Double(self.model!.pageCount)
  44. settingView.type = (self.model as! KMPageEditSplitSettingModel).type
  45. if ((self.model as! KMPageEditSplitSettingModel).type == 2) {
  46. settingView.setPageRangeString((self.model as! KMPageEditSplitSettingModel).pageRangeString)
  47. }
  48. settingView.updateName(self.model!.outputFileName)
  49. } else {
  50. let settingView: KMPageEditSplitSettingView = KMPageEditSplitSettingView.createFromNib()!
  51. self.contentBox.contentView?.addSubview(settingView)
  52. settingView.frame = self.contentBox.contentView!.bounds
  53. settingView.autoresizingMask = [.width, .height]
  54. self.settingView = settingView
  55. settingView.oneFileForOnePageStepper.maxValue = Double(self.model!.pageCount)
  56. settingView.splitMuitiFileStepper.maxValue = Double(self.model!.pageCount)
  57. settingView.type = (self.model as! KMPageEditSplitSettingModel).type
  58. if ((self.model as! KMPageEditSplitSettingModel).type == 2) {
  59. settingView.setPageRangeString((self.model as! KMPageEditSplitSettingModel).pageRangeString)
  60. }
  61. settingView.updateName(self.model!.outputFileName)
  62. }
  63. self.settingView!.itemClick = { [weak self] index, value in
  64. if (index == 1) { /// 类型切换
  65. (self?.model as! KMPageEditSplitSettingModel).type = value as! Int
  66. return
  67. }
  68. if (index == 2) { /// 平均每几页拆分
  69. (self?.model as! KMPageEditSplitSettingModel).avgNumberForOneFile = value as! Int
  70. return
  71. }
  72. if (index == 3) { /// 平均拆分几个文件
  73. (self?.model as! KMPageEditSplitSettingModel).avgSplitNumberFile = value as! Int
  74. return
  75. }
  76. if (index == 4) { /// 页面范围切换
  77. (self?.model as! KMPageEditSplitSettingModel).pageRangeType = value as! Int
  78. return
  79. }
  80. if (index == 5) { /// 页面范围输入
  81. (self?.model as! KMPageEditSplitSettingModel).pageRangeString = value as! String
  82. return
  83. }
  84. if (index == 6) { /// 将原始文档名前置
  85. (self?.model as! KMPageEditSplitSettingModel).origFileNameIsPrefix = value as! Bool
  86. (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
  87. return
  88. }
  89. if (index == 7) { /// 标签
  90. (self?.model as! KMPageEditSplitSettingModel).hasTag = value as! Bool
  91. (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
  92. return
  93. }
  94. if (index == 8) { /// 分隔符
  95. (self?.model as! KMPageEditSplitSettingModel).hasSep = value as! Bool
  96. (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
  97. return
  98. }
  99. if (index == 9) { /// 分隔符
  100. (self?.model as! KMPageEditSplitSettingModel).tagString = value as! String
  101. (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
  102. return
  103. }
  104. if (index == 10) { /// 分隔符
  105. (self?.model as! KMPageEditSplitSettingModel).sepString = value as! String
  106. (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
  107. return
  108. }
  109. }
  110. }
  111. }