KMBatchOperateRightViewController.swift 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //
  2. // KMBatchOperateRightViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by kdanmobile on 2023/10/26.
  6. //
  7. import Cocoa
  8. class KMBatchOperateRightViewController: NSViewController{
  9. lazy var compressViewController: KMBatchOperateCompressViewController? = {
  10. let vc = KMBatchOperateCompressViewController(files: self.files)
  11. vc.operateType = .Compress
  12. return vc
  13. }()
  14. lazy var convertViewController: KMBatchOperateConvertViewController? = {
  15. let vc = KMBatchOperateConvertViewController(files: self.files)
  16. vc.operateType = .Convert
  17. return vc
  18. }()
  19. lazy var addWatermarkViewController: KMBatchOperateAddWatermarkViewController? = {
  20. let vc = KMBatchOperateAddWatermarkViewController(files: self.files)
  21. vc.operateType = .AddWatermark
  22. vc.isBatchOperation = true
  23. return vc
  24. }()
  25. lazy var removeWatermarkViewController: KMBatchOperateRemoveWatermarkViewController? = {
  26. let vc = KMBatchOperateRemoveWatermarkViewController(files: self.files)
  27. vc.operateType = .RemoveWatermark
  28. return vc
  29. }()
  30. lazy var addBackgroundViewController: KMBatchOperateAddWatermarkViewController? = {
  31. let vc = KMBatchOperateAddWatermarkViewController(files: self.files)
  32. vc.operateType = .AddBackground
  33. vc.isBatchOperation = true
  34. vc.isBackground = true
  35. return vc
  36. }()
  37. lazy var removeBackgroundViewController: KMBatchOperateRemoveWatermarkViewController? = {
  38. let vc = KMBatchOperateRemoveWatermarkViewController(files: self.files)
  39. vc.operateType = .RemoveBackground
  40. vc.isBackground = true
  41. return vc
  42. }()
  43. lazy var addHeaderFooterViewController: KMBatchOperateAddHeaderFooterViewController? = {
  44. let vc = KMBatchOperateAddHeaderFooterViewController(files: self.files)
  45. vc.operateType = .AddHeaderFooter
  46. vc.isBatchOperation = true
  47. return vc
  48. }()
  49. lazy var addBatesViewController: KMBatchOperateAddHeaderFooterViewController? = {
  50. let vc = KMBatchOperateAddHeaderFooterViewController(files: self.files)
  51. vc.operateType = .AddBates
  52. vc.isBates = true
  53. vc.isBatchOperation = true
  54. return vc
  55. }()
  56. lazy var removeHeaderFooterViewController: KMBatchOperateRemoveHeaderFooterViewController? = {
  57. let vc = KMBatchOperateRemoveHeaderFooterViewController(files: self.files)
  58. vc.operateType = .RemoveHeaderFooter
  59. vc.isBates = false
  60. return vc
  61. }()
  62. lazy var removeBatesViewController: KMBatchOperateRemoveHeaderFooterViewController? = {
  63. let vc = KMBatchOperateRemoveHeaderFooterViewController(files: self.files)
  64. vc.operateType = .RemoveBates
  65. vc.isBates = true
  66. return vc
  67. }()
  68. lazy var addPasswordViewController: KMBatchOperateAddPasswordViewController? = {
  69. let vc = KMBatchOperateAddPasswordViewController(files: self.files)
  70. vc.operateType = .AddPassword
  71. return vc
  72. }()
  73. lazy var removePasswordViewController: KMBatchOperateRemovePasswordViewController? = {
  74. let vc = KMBatchOperateRemovePasswordViewController(files: self.files)
  75. vc.operateType = .RemovePassword
  76. return vc
  77. }()
  78. lazy var imageToPDFViewController: KMBatchOperateImageToPDFViewController? = {
  79. let vc = KMBatchOperateImageToPDFViewController(files: self.files)
  80. vc.operateType = .CreatePDF
  81. return vc
  82. }()
  83. var _currentType: KMBatchOperationType?
  84. var currentType: KMBatchOperationType?{
  85. get{
  86. return _currentType
  87. }
  88. set{
  89. if _currentType != newValue{
  90. _currentType = newValue
  91. for i in 0..<self.view.subviews.count {
  92. let v = self.view.subviews[i]
  93. v.removeFromSuperview()
  94. }
  95. if newValue == .Convert {
  96. self.view.addSubview(self.convertViewController!.view)
  97. self.convertViewController?.view.mas_makeConstraints({ make in
  98. make?.edges.equalTo()(self.view)
  99. })
  100. } else if _currentType == .AddWatermark {
  101. self.view.addSubview(self.addWatermarkViewController!.view)
  102. self.addWatermarkViewController?.view.mas_makeConstraints({ make in
  103. make?.edges.equalTo()(self.view)
  104. })
  105. } else if _currentType == .RemoveWatermark {
  106. self.view.addSubview(self.removeWatermarkViewController!.view)
  107. self.removeWatermarkViewController?.view.mas_makeConstraints({ make in
  108. make?.edges.equalTo()(self.view)
  109. })
  110. } else if _currentType == .AddBackground {
  111. self.view.addSubview(self.addBackgroundViewController!.view)
  112. self.addBackgroundViewController?.view.mas_makeConstraints({ make in
  113. make?.edges.equalTo()(self.view)
  114. })
  115. } else if _currentType == .RemoveBackground {
  116. self.view.addSubview(self.removeBackgroundViewController!.view)
  117. self.removeBackgroundViewController?.view.mas_makeConstraints({ make in
  118. make?.edges.equalTo()(self.view)
  119. })
  120. } else if _currentType == .AddHeaderFooter {
  121. self.view.addSubview(self.addHeaderFooterViewController!.view)
  122. self.addHeaderFooterViewController?.view.mas_makeConstraints({ make in
  123. make?.edges.equalTo()(self.view)
  124. })
  125. } else if _currentType == .RemoveHeaderFooter {
  126. self.view.addSubview(self.removeHeaderFooterViewController!.view)
  127. self.removeHeaderFooterViewController?.view.mas_makeConstraints({ make in
  128. make?.edges.equalTo()(self.view)
  129. })
  130. } else if _currentType == .AddBates {
  131. self.view.addSubview(self.addBatesViewController!.view)
  132. self.addBatesViewController?.view.mas_makeConstraints({ make in
  133. make?.edges.equalTo()(self.view)
  134. })
  135. } else if _currentType == .RemoveBates {
  136. self.view.addSubview(self.removeBatesViewController!.view)
  137. self.removeBatesViewController?.view.mas_makeConstraints({ make in
  138. make?.edges.equalTo()(self.view)
  139. })
  140. } else if _currentType == .AddPassword {
  141. self.view.addSubview(self.addPasswordViewController!.view)
  142. self.addPasswordViewController?.view.mas_makeConstraints({ make in
  143. make?.edges.equalTo()(self.view)
  144. })
  145. } else if _currentType == .RemovePassword {
  146. self.view.addSubview(self.removePasswordViewController!.view)
  147. self.removePasswordViewController?.view.mas_makeConstraints({ make in
  148. make?.edges.equalTo()(self.view)
  149. })
  150. } else if _currentType == .Compress {
  151. self.view.addSubview(self.compressViewController!.view)
  152. self.compressViewController?.view.mas_makeConstraints({ make in
  153. make?.edges.equalTo()(self.view)
  154. })
  155. } else if _currentType == .CreatePDF {
  156. self.view.addSubview(self.imageToPDFViewController!.view)
  157. self.imageToPDFViewController?.view.mas_makeConstraints({ make in
  158. make?.edges.equalTo()(self.view)
  159. })
  160. }
  161. }
  162. }
  163. }
  164. var files: [KMBatchOperateFile] = []
  165. override func viewDidLoad() {
  166. super.viewDidLoad()
  167. }
  168. func switchToOperateType(operateType: KMBatchOperationType, files: [KMBatchOperateFile]) {
  169. self.files = files
  170. self.imageToPDFViewController?.files = self.files
  171. self.currentType = operateType
  172. }
  173. func switchToOperateType(operateType: KMBatchOperationType) {
  174. self.currentType = operateType
  175. }
  176. func switchToConvertType(_ convertType: KMConvertWithPDFType) {
  177. if self.currentType == .Convert {
  178. self.convertViewController?.switchToConvertType(convertType)
  179. }
  180. }
  181. func watermarkInterfaceSelectWatermark(_ watermark: KMWatermarkModel) {
  182. if self.currentType == .AddWatermark {
  183. self.addWatermarkViewController?.watermarkInterfaceSelectWatermark(watermark)
  184. }
  185. }
  186. func backgroundInterfaceSelectBackground(_ background: KMBackgroundModel) {
  187. if self.currentType == .AddBackground {
  188. self.addBackgroundViewController?.backgroundInterfaceSelectBackGround(background)
  189. }
  190. }
  191. func headerFooterInterfaceSelectHeaderFooter(_ headerFooter: KMHeaderFooterObject) {
  192. if self.currentType == .AddHeaderFooter {
  193. self.addHeaderFooterViewController?.headerFooterInterfaceSelectHeaderFooter(headerFooter: headerFooter)
  194. }
  195. }
  196. func batesInterfaceSelectBates(_ headerFooter: KMHeaderFooterObject) {
  197. if self.currentType == .AddBates {
  198. self.addHeaderFooterViewController?.headerFooterInterfaceSelectHeaderFooter(headerFooter: headerFooter)
  199. }
  200. }
  201. }