KMBatchOperateRightViewController.swift 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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: KMBatchOperateNewCompressViewController? = {
  10. let vc = KMBatchOperateNewCompressViewController(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. lazy var ocrViewController: KMBatchOperateOCRFViewController? = {
  84. let vc = KMBatchOperateOCRFViewController(files: self.files)
  85. vc.operateType = .OCR
  86. return vc
  87. }()
  88. var _currentType: KMBatchOperationType?
  89. var currentType: KMBatchOperationType?{
  90. get{
  91. return _currentType
  92. }
  93. set{
  94. if _currentType != newValue{
  95. _currentType = newValue
  96. for i in 0..<self.view.subviews.count {
  97. let v = self.view.subviews[i]
  98. v.removeFromSuperview()
  99. }
  100. if newValue == .Convert {
  101. self.view.addSubview(self.convertViewController!.view)
  102. self.convertViewController?.view.mas_makeConstraints({ make in
  103. make?.edges.equalTo()(self.view)
  104. })
  105. } else if _currentType == .AddWatermark {
  106. self.view.addSubview(self.addWatermarkViewController!.view)
  107. self.addWatermarkViewController?.view.mas_makeConstraints({ make in
  108. make?.edges.equalTo()(self.view)
  109. })
  110. } else if _currentType == .RemoveWatermark {
  111. self.view.addSubview(self.removeWatermarkViewController!.view)
  112. self.removeWatermarkViewController?.view.mas_makeConstraints({ make in
  113. make?.edges.equalTo()(self.view)
  114. })
  115. } else if _currentType == .AddBackground {
  116. self.view.addSubview(self.addBackgroundViewController!.view)
  117. self.addBackgroundViewController?.view.mas_makeConstraints({ make in
  118. make?.edges.equalTo()(self.view)
  119. })
  120. } else if _currentType == .RemoveBackground {
  121. self.view.addSubview(self.removeBackgroundViewController!.view)
  122. self.removeBackgroundViewController?.view.mas_makeConstraints({ make in
  123. make?.edges.equalTo()(self.view)
  124. })
  125. } else if _currentType == .AddHeaderFooter {
  126. self.view.addSubview(self.addHeaderFooterViewController!.view)
  127. self.addHeaderFooterViewController?.view.mas_makeConstraints({ make in
  128. make?.edges.equalTo()(self.view)
  129. })
  130. } else if _currentType == .RemoveHeaderFooter {
  131. self.view.addSubview(self.removeHeaderFooterViewController!.view)
  132. self.removeHeaderFooterViewController?.view.mas_makeConstraints({ make in
  133. make?.edges.equalTo()(self.view)
  134. })
  135. } else if _currentType == .AddBates {
  136. self.view.addSubview(self.addBatesViewController!.view)
  137. self.addBatesViewController?.view.mas_makeConstraints({ make in
  138. make?.edges.equalTo()(self.view)
  139. })
  140. } else if _currentType == .RemoveBates {
  141. self.view.addSubview(self.removeBatesViewController!.view)
  142. self.removeBatesViewController?.view.mas_makeConstraints({ make in
  143. make?.edges.equalTo()(self.view)
  144. })
  145. } else if _currentType == .AddPassword {
  146. self.view.addSubview(self.addPasswordViewController!.view)
  147. self.addPasswordViewController?.view.mas_makeConstraints({ make in
  148. make?.edges.equalTo()(self.view)
  149. })
  150. } else if _currentType == .RemovePassword {
  151. self.view.addSubview(self.removePasswordViewController!.view)
  152. self.removePasswordViewController?.view.mas_makeConstraints({ make in
  153. make?.edges.equalTo()(self.view)
  154. })
  155. } else if _currentType == .Compress {
  156. self.view.addSubview(self.compressViewController!.view)
  157. self.compressViewController?.view.mas_makeConstraints({ make in
  158. make?.edges.equalTo()(self.view)
  159. })
  160. } else if _currentType == .CreatePDF {
  161. self.view.addSubview(self.imageToPDFViewController!.view)
  162. self.imageToPDFViewController?.view.mas_makeConstraints({ make in
  163. make?.edges.equalTo()(self.view)
  164. })
  165. } else if _currentType == .OCR {
  166. self.view.addSubview(self.ocrViewController!.view)
  167. self.ocrViewController?.view.mas_makeConstraints({ make in
  168. make?.edges.equalTo()(self.view)
  169. })
  170. }
  171. }
  172. }
  173. }
  174. var files: [KMBatchOperateFile] = []
  175. override func viewDidLoad() {
  176. super.viewDidLoad()
  177. }
  178. func switchToOperateType(operateType: KMBatchOperationType, files: [KMBatchOperateFile]) {
  179. self.files = files
  180. self.imageToPDFViewController?.files = self.files
  181. self.currentType = operateType
  182. }
  183. func switchToOperateType(operateType: KMBatchOperationType) {
  184. self.currentType = operateType
  185. }
  186. func switchToConvertType(_ convertType: KMConvertWithPDFType) {
  187. if self.currentType == .Convert {
  188. self.convertViewController?.switchToConvertType(convertType)
  189. }
  190. }
  191. func watermarkInterfaceSelectWatermark(_ watermark: KMWatermarkModel) {
  192. if self.currentType == .AddWatermark {
  193. self.addWatermarkViewController?.watermarkInterfaceSelectWatermark(watermark)
  194. }
  195. }
  196. func backgroundInterfaceSelectBackground(_ background: KMBackgroundModel) {
  197. if self.currentType == .AddBackground {
  198. self.addBackgroundViewController?.backgroundInterfaceSelectBackGround(background)
  199. }
  200. }
  201. func headerFooterInterfaceSelectHeaderFooter(_ headerFooter: KMHeaderFooterObject) {
  202. if self.currentType == .AddHeaderFooter {
  203. self.addHeaderFooterViewController?.headerFooterInterfaceSelectHeaderFooter(headerFooter: headerFooter)
  204. }
  205. }
  206. func batesInterfaceSelectBates(_ headerFooter: KMHeaderFooterObject) {
  207. if self.currentType == .AddBates {
  208. self.addHeaderFooterViewController?.headerFooterInterfaceSelectHeaderFooter(headerFooter: headerFooter)
  209. }
  210. }
  211. }