KMBatchOperateAddWatermarkViewController.swift 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. //
  2. // KMBatchOperateAddWatermarkViewController.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/11/3.
  6. //
  7. import Cocoa
  8. enum KMWatermarkType: Int {
  9. case txt = 0
  10. case file
  11. }
  12. class KMCollectionViewFlowLayout: NSCollectionViewFlowLayout {
  13. override func shouldInvalidateLayout(forBoundsChange newBounds: NSRect) -> Bool {
  14. self.collectionView?.reloadSections(IndexSet(integer: 0))
  15. return true
  16. }
  17. }
  18. class KMBatchOperateAddWatermarkViewController: KMBatchOperateBaseViewController {
  19. var isBackground = false
  20. var onlyManagerTemplate = false
  21. weak var pdfView: CPDFView?
  22. var isBatchOperation = false //是否在批量界面
  23. @IBOutlet var topBaseView: NSView!
  24. @IBOutlet var titleLabel: NSTextField!
  25. @IBOutlet var addButton: NSButton!
  26. @IBOutlet var textButton: NSButton!
  27. @IBOutlet var fileButton: NSButton!
  28. @IBOutlet var textBox: NSBox!
  29. @IBOutlet var fileBox: NSBox!
  30. @IBOutlet var actionButton: NSButton!
  31. @IBOutlet var collectionView: NSCollectionView!
  32. @IBOutlet var bottomBaseView: NSView!
  33. @IBOutlet var managerTemplateTitleLabel: NSTextField!
  34. @IBOutlet var blankView: KMBlankView!
  35. @IBOutlet var managerTemplateButtonTopConstraint: NSLayoutConstraint!
  36. @IBOutlet var managerTemplateButtonHeightConstraint: NSLayoutConstraint!
  37. @IBOutlet var topHeightConstraint: NSLayoutConstraint!
  38. @IBOutlet var addButtonHeightConstraint: NSLayoutConstraint!
  39. @IBOutlet var addButtonBottomConstraint: NSLayoutConstraint!
  40. private var _textTemplateArray: [NSObject]?
  41. private var _fileTemplateArray: [NSObject]?
  42. private var _currentTextData: KMPDFWatermarkData?
  43. private var _currentFileData: KMPDFWatermarkData?
  44. private var _currentColorData: KMBackgroundObject?
  45. private var _currentImageData: KMBackgroundObject?
  46. private var _currentBackgroundType: KMBackgroundType = .color
  47. var currentBackgroundType: KMBackgroundType {
  48. get {
  49. return self._currentBackgroundType
  50. }
  51. set {
  52. if (self._currentBackgroundType != newValue) {
  53. self._currentBackgroundType = newValue
  54. if (self._currentBackgroundType == .color) {
  55. // self.textButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
  56. // self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
  57. self.textBox.fillColor = KMAppearance.Interactive.a0Color()
  58. self.fileBox.fillColor = KMAppearance.Layout.l_1Color()
  59. self.textButton.setTitleColor(KMAppearance.Layout.w0Color())
  60. self.fileButton.setTitleColor(KMAppearance.Layout.h1Color())
  61. } else {
  62. // self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
  63. // self.textButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
  64. self.textBox.fillColor = KMAppearance.Layout.l_1Color()
  65. self.fileBox.fillColor = KMAppearance.Interactive.a0Color()
  66. self.fileButton.setTitleColor(KMAppearance.Layout.w0Color())
  67. self.textButton.setTitleColor(KMAppearance.Layout.h1Color())
  68. }
  69. self.collectionView.reloadData()
  70. }
  71. }
  72. }
  73. private var _currentType: KMWatermarkType = .txt
  74. var currentType: KMWatermarkType {
  75. set {
  76. if self.currentType != newValue {
  77. self._currentType = newValue
  78. if (currentType == .txt) {
  79. // self.textButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
  80. // self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
  81. self.textBox.fillColor = KMAppearance.Interactive.a0Color()
  82. self.fileBox.fillColor = KMAppearance.Layout.l_1Color()
  83. self.textButton.setTitleColor(KMAppearance.Layout.w0Color())
  84. self.fileButton.setTitleColor(KMAppearance.Layout.h1Color())
  85. } else {
  86. // self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
  87. // self.textButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
  88. self.textBox.fillColor = KMAppearance.Layout.l_1Color()
  89. self.fileBox.fillColor = KMAppearance.Interactive.a0Color()
  90. self.fileButton.setTitleColor(KMAppearance.Layout.w0Color())
  91. self.textButton.setTitleColor(KMAppearance.Layout.h1Color())
  92. }
  93. self.collectionView.reloadData()
  94. }
  95. }
  96. get {
  97. return self._currentType
  98. }
  99. }
  100. private var _haveFiles = false
  101. deinit {
  102. KMPrint("KMBatchOperateAddWatermarkViewController deinit.")
  103. NotificationCenter.default.removeObserver(self)
  104. }
  105. override func viewDidLoad() {
  106. super.viewDidLoad()
  107. self._localizedlanguage()
  108. self._configuiUI()
  109. self._loadData()
  110. NotificationCenter.default.addObserver(self, selector: #selector(_watermarksNotification), name: NSNotification.Name("KMBatchOperateWatermarksNotification"), object: nil)
  111. }
  112. func watermarkInterfaceSelectWatermark(_ watermark: KMPDFWatermarkData) {
  113. if(watermark.image != nil) {
  114. self._currentFileData = watermark
  115. }else {
  116. self._currentTextData = watermark
  117. }
  118. self._loadData()
  119. self.currentType = watermark.image != nil ? .file : .txt
  120. let arr = self.currentType == .file ? self._fileTemplateArray : self._textTemplateArray
  121. let index = arr?.index(of: watermark)
  122. if (index != NSNotFound) {
  123. let indexpath = IndexPath(item: index!, section: 0)
  124. var set = Set<IndexPath>()
  125. set.insert(indexpath)
  126. self.collectionView.selectItems(at: set, scrollPosition: .bottom)
  127. }
  128. }
  129. func backgroundInterfaceSelectBackGround(_ background: KMBackgroundObject) {
  130. if(background.type == .file) {
  131. self._currentImageData = background
  132. }else {
  133. self._currentColorData = background
  134. }
  135. self._loadData()
  136. self.currentBackgroundType = background.type
  137. let arr = self.currentBackgroundType == .file ? self._fileTemplateArray : self._textTemplateArray
  138. let index = arr?.index(of: background)
  139. if (index != NSNotFound) {
  140. let indexpath = IndexPath(item: index!, section: 0)
  141. var set = Set<IndexPath>()
  142. set.insert(indexpath)
  143. self.collectionView.selectItems(at: set, scrollPosition: .bottom)
  144. }
  145. }
  146. override var interfaceStatus: KMBatchOperateInterfaceStatus? {
  147. didSet {
  148. if (self.interfaceStatus == .PrepareProcess) {
  149. DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
  150. var files: [URL] = []
  151. for url in self.successFilePathURLArray ?? [] {
  152. if FileManager.default.fileExists(atPath: url.path) {
  153. files.append(url)
  154. }
  155. }
  156. if (files.count > 0) {
  157. let workspace = NSWorkspace.shared
  158. workspace.activateFileViewerSelecting(files)
  159. }
  160. }
  161. self.collectionView.isSelectable = true
  162. self.actionButton.tag = 1
  163. // if (self.isBackground) {
  164. // self.actionButton.title = NSLocalizedString(@"Add Background", nil);
  165. // } else {
  166. // self.actionButton.title = NSLocalizedString(@"Add Watermark", nil);
  167. // }
  168. self.actionButton.title = KMLocalizedString("Apply", nil)
  169. self.addButton.isEnabled = true
  170. // if (self.onlyManagerTemplate) {
  171. // self.actionButton.title = NSLocalizedString(@"Add Template", nil);
  172. // }
  173. } else {
  174. self.collectionView.isSelectable = false
  175. self.addButton.isEnabled = false
  176. self.actionButton.tag = 0
  177. self.actionButton.title = KMLocalizedString("Cancel", nil);
  178. }
  179. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  180. }
  181. }
  182. //button Actions,切换水印类型
  183. @IBAction func buttonClicked_SwitchWaterMarkType(_ sender: NSButton) {
  184. if (self.isBackground) {
  185. self.currentBackgroundType = KMBackgroundType(rawValue: sender.tag) ?? .color
  186. } else {
  187. self.currentType = KMWatermarkType(rawValue: sender.tag) ?? .txt
  188. }
  189. self._updateActionButtonbackgroundColor()
  190. }
  191. @IBAction func buttonClicked_addWaterMark(_ sender: NSButton) {
  192. if (!self.onlyManagerTemplate) {
  193. if (!self._haveFiles) {
  194. return
  195. }
  196. }
  197. self.view.window?.makeFirstResponder(nil)
  198. // if (self.onlyManagerTemplate) {
  199. // [self buttonClicked_addtemplate:sender];
  200. // return;
  201. // }
  202. // //点击开始
  203. // if (sender.tag == 1) {
  204. // if (![self checkAndResetTask]) {
  205. // NSBeep();
  206. // return;
  207. // }
  208. // KMPDFWatermark *watermark = nil;
  209. // KMBackgroundObject *background = nil;
  210. // NSIndexSet *indexSet = self.collectionView.selectionIndexes;
  211. // if (indexSet.firstIndex == NSNotFound || self.files.count < 1) {
  212. // NSBeep();
  213. // return;
  214. // } else {
  215. // NSUInteger index = indexSet.firstIndex;
  216. //
  217. // if (!self.isBackground) {
  218. // if (self.currentType == KMWatermarkType_Txt) {
  219. // watermark = [self.textTemplateArray objectAtIndex:index];
  220. // } else {
  221. // watermark = [self.fileTemplateArray objectAtIndex:index];
  222. // }
  223. // } else {
  224. // if (self.currentBackgroundType == KMBackgroundType_Color) {
  225. // background = [self.textTemplateArray objectAtIndex:index];
  226. // } else {
  227. // background = [self.fileTemplateArray objectAtIndex:index];
  228. // }
  229. // }
  230. //
  231. // }
  232. //
  233. // if (self.isBackground) {
  234. // [self choosePathAndBeginOperation:background];
  235. // } else {
  236. // [self choosePathAndBeginOperation:watermark];
  237. // }
  238. // } else if (sender.tag == 0) {
  239. // if (self.queue.operations.count > 0) {
  240. // [self.queue cancelAllOperations];
  241. // }
  242. // [self setInterfaceStatus:KMBatchOperateInterfaceStatus_PrepareProcess];
  243. // }
  244. if (self.onlyManagerTemplate) {
  245. if (sender.tag == 1) {
  246. var watermark: KMPDFWatermarkData?
  247. var background: KMBackgroundObject?
  248. let indexSet = self._isSelectIndex()
  249. if (!indexSet) {
  250. return
  251. } else {
  252. if (!self.isBackground) {
  253. if (self.currentType == .txt) {
  254. watermark = self._currentTextData
  255. } else {
  256. watermark = self._currentFileData
  257. }
  258. } else {
  259. if (self.currentBackgroundType == .color) {
  260. background = self._currentColorData
  261. } else {
  262. background = self._currentImageData
  263. }
  264. }
  265. }
  266. let openPanel = NSOpenPanel()
  267. openPanel.canChooseFiles = false
  268. openPanel.canChooseDirectories = true
  269. openPanel.canCreateDirectories = true
  270. openPanel.beginSheetModal(for: self.view.window!) { result in
  271. if (result == .OK) {
  272. for fileURL in openPanel.urls {
  273. self.hiddenWindowCloseButtonIfNeeded()
  274. // [self.successFilePathURLArray removeAllObjects];
  275. if (!self.isBackground) {
  276. let file = KMBatchOperateFile(filePath: self.pdfView?.document.documentURL.path ?? "")
  277. file.addWatermarkInfo.savePath = fileURL.path
  278. // file.addWatermarkInfo.pageChoice = watermark.pageRangeType
  279. file.addWatermarkInfo.pageRangeString = watermark?.pagesString ?? ""
  280. // KMBatchAddWatermarkOperation *operation = [[[KMBatchAddWatermarkOperation alloc] initWithFile:file waterMark:watermark] autorelease];
  281. // operation.delegate = self;
  282. // [self.queue addOperation:operation];
  283. } else {
  284. let file = KMBatchOperateFile(filePath: self.pdfView?.document.documentURL.path ?? "")
  285. file.addBackgroundInfo.savePath = fileURL.path
  286. // file.addBackgroundInfo.pageChoice = background.pageRangeType
  287. file.addBackgroundInfo.pageRangeString = background?.pagesString ?? ""
  288. // KMBatchAddBackgroundOperation *operation = [[[KMBatchAddBackgroundOperation alloc] initWithFile:file background:background] autorelease];
  289. // operation.delegate = self;
  290. // [self.queue addOperation:operation];
  291. }
  292. if let cnt = self.queue?.operations.count, cnt > 0 {
  293. self.interfaceStatus = .Processing
  294. }
  295. }
  296. }
  297. }
  298. } else if (sender.tag == 0) {
  299. if let cnt = self.queue?.operations.count, cnt > 0 {
  300. self.queue?.cancelAllOperations()
  301. }
  302. self.interfaceStatus = .PrepareProcess
  303. }
  304. } else {
  305. //点击开始
  306. if (sender.tag == 1) {
  307. if (!self._checkAndResetTask()) {
  308. return;
  309. }
  310. var watermark: KMPDFWatermarkData?
  311. var background: KMBackgroundObject?
  312. let indexSet = self._isSelectIndex()
  313. if (!indexSet || self.files!.count < 1) {
  314. return;
  315. } else {
  316. if (!self.isBackground) {
  317. if (self.currentType == .txt) {
  318. watermark = self._currentTextData
  319. } else {
  320. watermark = self._currentFileData
  321. }
  322. } else {
  323. if (self.currentBackgroundType == .color) {
  324. background = self._currentColorData
  325. } else {
  326. background = self._currentImageData
  327. }
  328. }
  329. }
  330. if (self.isBackground) {
  331. self._choosePathAndBeginOperation(background)
  332. } else {
  333. self._choosePathAndBeginOperation(watermark)
  334. }
  335. } else if (sender.tag == 0) {
  336. if let cnt = self.queue?.operations.count, cnt > 0 {
  337. self.queue?.cancelAllOperations()
  338. }
  339. self.interfaceStatus = .PrepareProcess
  340. }
  341. }
  342. }
  343. /*
  344. //添加水印模版
  345. - (IBAction)buttonClicked_addtemplate:(id)sender {
  346. NSWindowController *windowController = self.view.window.windowController;
  347. NSString *filePath = nil;
  348. NSString *password = nil;
  349. // if ([self.view.window.windowController isKindOfClass:[SKMainWindowController class]]) {
  350. // filePath = [[(SKMainWindowController *)windowController pdfView].document.documentURL path];
  351. // SKPDFDocument *document = (SKPDFDocument *)[(SKMainWindowController *)windowController pdfView].document;
  352. // password = document.password;
  353. // }
  354. if (!self.isBackground) {
  355. // KMWatermarkManagerWindowController *watermarWindowController = [[[KMWatermarkManagerWindowController alloc] initWithBaseFile:filePath watermark:nil password:password type:KMWatermarkManagerType_Add fileType:self.currentType] autorelease];
  356. // __block typeof(self) blockSelf = self;
  357. // watermarWindowController.operateCallBack = ^(KMPDFWatermarkData *watermark, NSInteger currentType) {
  358. // blockSelf.currentType = currentType;
  359. //
  360. // [blockSelf loadData];
  361. //// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  362. //// if ([self checkAndResetTask]) {
  363. //// [self choosePathAndBeginOperation:watermark];
  364. //// }
  365. //// });
  366. //
  367. // BOOL haveWaters = NO;
  368. // if (blockSelf.currentType == KMWatermarkType_Txt) {
  369. // blockSelf.currentTextData = watermark;;
  370. // if (blockSelf.textTemplateArray.count > 0) {
  371. // haveWaters = YES;
  372. // }
  373. // } else if (blockSelf.currentType == KMWatermarkType_File) {
  374. // blockSelf.currentFileData = watermark;;
  375. // if (blockSelf.fileTemplateArray.count > 0) {
  376. // haveWaters = YES;
  377. // }
  378. // }
  379. // if (haveWaters) {
  380. // NSIndexPath *indexpath = [NSIndexPath indexPathForItem:0 inSection:0];
  381. // NSMutableSet *set = [NSMutableSet set];
  382. // [set addObject:indexpath];
  383. // [blockSelf.collectionView selectItemsAtIndexPaths:set scrollPosition:NSCollectionViewScrollPositionBottom];
  384. // }
  385. //
  386. // [blockSelf postNotification];
  387. // };
  388. // [watermarWindowController beginSheetModalForWindow:[NSApp keyWindow] completionHandler:nil];
  389. } else {
  390. // KMBackgroundManagerWindowController *backgroundWindowController = [[[KMBackgroundManagerWindowController alloc] initWithBaseFile:filePath background:nil password:password type:KMBackgroundManagerType_Add fileType:self.currentBackgroundType] autorelease];
  391. // __block typeof(self) blockSelf = self;
  392. // backgroundWindowController.operateCallBack = ^(KMBackgroundObject *background, NSInteger currentType) {
  393. // blockSelf.currentBackgroundType = currentType;
  394. //
  395. // [blockSelf loadData];
  396. //// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  397. //// if ([self checkAndResetTask]) {
  398. //// [self choosePathAndBeginOperation:background];
  399. //// }
  400. //// });
  401. //
  402. // BOOL haveBackgrounds = NO;
  403. // if (blockSelf.currentBackgroundType == KMBackgroundType_Color) {
  404. // blockSelf.currentColorData = background;
  405. // if (blockSelf.textTemplateArray.count > 0) {
  406. // haveBackgrounds = YES;
  407. // }
  408. // } else if (blockSelf.currentBackgroundType == KMBackgroundType_File) {
  409. // blockSelf.currentImageData = background;
  410. // if (blockSelf.fileTemplateArray.count > 0) {
  411. // haveBackgrounds = YES;
  412. // }
  413. // }
  414. // if (haveBackgrounds) {
  415. // NSIndexPath *indexpath = [NSIndexPath indexPathForItem:0 inSection:0];
  416. // NSMutableSet *set = [NSMutableSet set];
  417. // [set addObject:indexpath];
  418. // [blockSelf.collectionView selectItemsAtIndexPaths:set scrollPosition:NSCollectionViewScrollPositionBottom];
  419. // }
  420. //
  421. // [blockSelf postNotification];
  422. // };
  423. // [backgroundWindowController beginSheetModalForWindow:[NSApp keyWindow] completionHandler:nil];
  424. }
  425. }
  426. - (void)editWatermark:(KMPDFWatermarkData *)waterMark {
  427. if (!self.isBackground) {
  428. NSString *filePath = nil;
  429. NSString *password = nil;
  430. NSWindowController *windowController = self.view.window.windowController;
  431. // if ([self.view.window.windowController isKindOfClass:[SKMainWindowController class]]) {
  432. // filePath = [[(SKMainWindowController *)windowController pdfView].document.documentURL path];
  433. // SKPDFDocument *document = (SKPDFDocument *)[(SKMainWindowController *)windowController pdfView].document;
  434. // password = document.password;
  435. // }
  436. // KMWatermarkManagerWindowController *watermarWindowController = [[[KMWatermarkManagerWindowController alloc] initWithBaseFile:filePath watermark:waterMark password:password type:KMWatermarkManagerType_Edit fileType:self.currentType] autorelease];
  437. // __block typeof(self) blockSelf = self;
  438. // watermarWindowController.operateCallBack = ^(KMPDFWatermarkData *watermark, NSInteger currentType) {
  439. // blockSelf.currentType = currentType;
  440. // if (currentType == 0) {
  441. // blockSelf.currentTextData = watermark;
  442. // } else {
  443. // blockSelf.currentFileData = watermark;
  444. // }
  445. // [blockSelf loadData];
  446. //
  447. // [blockSelf postNotification];
  448. // };
  449. // [watermarWindowController beginSheetModalForWindow:[NSApp keyWindow] completionHandler:nil];
  450. } else {
  451. }
  452. }
  453. - (void)editBackground:(KMBackgroundObject *)background {
  454. NSWindowController *windowController = self.view.window.windowController;
  455. NSString *filePath = nil;
  456. NSString *password = nil;
  457. // if ([self.view.window.windowController isKindOfClass:[SKMainWindowController class]]) {
  458. // filePath = [[(SKMainWindowController *)windowController pdfView].document.documentURL path];
  459. // SKPDFDocument *document = (SKPDFDocument *)[(SKMainWindowController *)windowController pdfView].document;
  460. // password = document.password;
  461. // }
  462. //
  463. // KMBackgroundManagerWindowController *backgroundWindowController = [[[KMBackgroundManagerWindowController alloc] initWithBaseFile:filePath background:background password:password type:KMBackgroundManagerType_Edit fileType:self.currentBackgroundType] autorelease];
  464. // __block typeof(self) blockSelf = self;
  465. // backgroundWindowController.operateCallBack = ^(KMBackgroundObject *background, NSInteger currentType) {
  466. // blockSelf.currentBackgroundType = currentType;
  467. // if (currentType == 0) {
  468. // blockSelf.currentColorData = background;
  469. // } else {
  470. // blockSelf.currentImageData = background;
  471. // }
  472. // [blockSelf loadData];
  473. //
  474. // [blockSelf postNotification];
  475. // };
  476. // [backgroundWindowController beginSheetModalForWindow:[NSApp keyWindow] completionHandler:nil];
  477. }
  478. - (void)deleteBackground:(KMBackgroundObject *)background {
  479. // [[KMBackgroundManager defaultManager] removeBackground:background];
  480. [self loadData];
  481. [self postNotification];
  482. }
  483. */
  484. }
  485. // MARK: - Private Methods
  486. extension KMBatchOperateAddWatermarkViewController {
  487. private func _localizedlanguage() {
  488. self.addButton.title = KMLocalizedString("Add Template", nil)
  489. self.fileButton.title = KMLocalizedString("File", nil)
  490. self.actionButton.title = KMLocalizedString("Apply", nil)
  491. if (!self.isBackground) {
  492. self.titleLabel.stringValue = KMLocalizedString("Watermark", nil)
  493. self.textButton.title = KMLocalizedString("Text", nil)
  494. // self.actionButton.title = NSLocalizedString(@"Add Watermark", nil);
  495. } else {
  496. self.titleLabel.stringValue = KMLocalizedString("Background", nil)
  497. self.textButton.title = KMLocalizedString("Color", nil)
  498. // self.actionButton.title = NSLocalizedString(@"Add Background", nil);
  499. }
  500. // if (self.onlyManagerTemplate) {
  501. // self.actionButton.title = NSLocalizedString(@"Add Template", nil);
  502. // }
  503. if (self.onlyManagerTemplate) {
  504. // self.titleLabel.hidden = self.addButton.hidden = YES;
  505. // self.managerTemplateTitleLabel.hidden = NO;
  506. // self.addButtonHeightConstraint.constant = 0;
  507. // self.addButtonBottomConstraint.constant = 0;
  508. self.titleLabel.isHidden = false
  509. self.addButton.isHidden = false
  510. self.managerTemplateTitleLabel.isHidden = true
  511. } else {
  512. self.titleLabel.isHidden = false
  513. self.addButton.isHidden = false
  514. self.managerTemplateTitleLabel.isHidden = true
  515. }
  516. self.managerTemplateTitleLabel.stringValue = KMLocalizedString("Manage Templates", nil)
  517. }
  518. private func _configuiUI() {
  519. self.topBaseView.wantsLayer = true
  520. self.topBaseView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  521. self.collectionView.wantsLayer = true
  522. self.collectionView.isSelectable = true
  523. self.collectionView.allowsMultipleSelection = false
  524. self.collectionView.allowsEmptySelection = false
  525. self.collectionView.enclosingScrollView?.borderType = .noBorder
  526. self.collectionView.enclosingScrollView?.drawsBackground = false
  527. let v = NSView(frame: CGRectMake(0, 0, 100, 100))
  528. v.wantsLayer = true
  529. v.layer?.backgroundColor = .clear
  530. self.collectionView.backgroundView = v;
  531. self.collectionView.enclosingScrollView?.horizontalScrollElasticity = .none
  532. self.collectionView.enclosingScrollView?.verticalScrollElasticity = .none
  533. self.titleLabel.font = .boldSystemFont(ofSize: 14)
  534. self.titleLabel.textColor = KMAppearance.Layout.h0Color()
  535. self.actionButton.font = .systemFont(ofSize: 13)
  536. self.fileButton.font = .systemFont(ofSize: 13)
  537. self.textButton.font = .systemFont(ofSize: 13)
  538. self.actionButton.wantsLayer = true
  539. self.addButton.wantsLayer = true
  540. if (self.onlyManagerTemplate) {
  541. // [self.actionButton setImage:[NSImage imageNamed:KMImageNameUXIconBtnAddWhite]];
  542. // self.actionButton.imagePosition = NSImageLeft;
  543. // [self.actionButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  544. self.topHeightConstraint.constant = 0
  545. self.addButton.imagePosition = .imageLeft
  546. self.addButton.image = NSImage(named: "KMImageNameHeaderFooterAddBtn")
  547. // self.addButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_S0].CGColor;
  548. self.addButton.setTitleColor(KMAppearance.Layout.h0Color())
  549. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  550. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  551. self.actionButton.imagePosition = .noImage
  552. } else {
  553. self.topHeightConstraint.constant = 0
  554. self.addButton.imagePosition = .imageLeft
  555. self.addButton.image = NSImage(named: "KMImageNameHeaderFooterAddBtn")
  556. // self.addButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_S0].CGColor;
  557. self.addButton.setTitleColor(KMAppearance.Layout.h0Color())
  558. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color().withAlphaComponent(0.6))
  559. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.6).cgColor
  560. self.actionButton.imagePosition = .noImage
  561. }
  562. if (!self.onlyManagerTemplate) {
  563. if let cnt = self.files?.count, cnt > 0 {
  564. self._haveFiles = true
  565. } else {
  566. self._haveFiles = false
  567. }
  568. self._updateActionButtonbackgroundColor()
  569. }
  570. self.addButton.layer?.cornerRadius = 1.0
  571. self.actionButton.layer?.cornerRadius = 1.0
  572. self.actionButton.layer?.cornerRadius = 1.0
  573. // self.bottomBaseView.wantsLayer = YES;
  574. // self.bottomBaseView.layer.backgroundColor = [KMAppearance KMColor_Layout_L0].CGColor;
  575. self.textButton.wantsLayer = true
  576. self.fileButton.wantsLayer = true
  577. // self.textButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
  578. // self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
  579. self.textBox.fillColor = KMAppearance.Interactive.a0Color()
  580. self.fileBox.fillColor = KMAppearance.Layout.l_1Color()
  581. self.textButton.setTitleColor(KMAppearance.Layout.w0Color())
  582. self.fileButton.setTitleColor(KMAppearance.Layout.h0Color())
  583. self.managerTemplateTitleLabel.font = .systemFont(ofSize: 14)
  584. self.managerTemplateTitleLabel.textColor = KMAppearance.Layout.h0Color()
  585. self.view.addSubview(self.blankView)
  586. self.blankView.mas_makeConstraints { make in
  587. make?.top.equalTo()(self.topBaseView.mas_bottom)
  588. make?.left.right().equalTo()(self.view)
  589. make?.bottom.equalTo()(self.bottomBaseView.mas_top)
  590. make?.height.greaterThanOrEqualTo()(200)
  591. }
  592. self.blankView.titleLabel.stringValue = KMLocalizedString("No Templates", nil)
  593. if (self.isBackground) {
  594. self.blankView.imageView.image = NSImage(named: KMImageNameEmptyBackground)
  595. }
  596. self.blankView.wantsLayer = true
  597. // self.blankView.layer.backgroundColor = [KMAppearance KMColor_Layout_L0].CGColor;
  598. // NSMenu * = [[NSMenu alloc]initWithTitle:@""];
  599. let menu = NSMenu()
  600. if(!self.isBackground) {
  601. if(!self.isBatchOperation) {
  602. _ = menu.addItem(title: KMLocalizedString("Batch Add Watermarks", nil), action: #selector(_buttonItemClick_addBatch), target: self)
  603. }
  604. _ = menu.addItem(title: KMLocalizedString("Remove All Watermark Templates", nil), action: #selector(_buttonItemClick_CleanAll), target: self)
  605. } else {
  606. if(!self.isBatchOperation) {
  607. _ = menu.addItem(title: KMLocalizedString("Batch Add Background", nil), action: #selector(_buttonItemClick_addBatch), target: self)
  608. }
  609. _ = menu.addItem(title: KMLocalizedString("Remove All Background Templates", nil), action: #selector(_buttonItemClick_CleanAll), target: self)
  610. }
  611. self.view.menu = menu;
  612. }
  613. private func _loadData() {
  614. self._textTemplateArray = []
  615. self._fileTemplateArray = []
  616. if (!self.isBackground) {
  617. // NSArray *watermarkArr = [KMWatermarkManager defaultManager].watermarks;
  618. // for (NSUInteger i = 0 ; i < watermarkArr.count; i++) {
  619. // KMPDFWatermarkData *watermark = [watermarkArr objectAtIndex:i];
  620. // if (watermark.image) {
  621. // [self.fileTemplateArray addObject:watermark];
  622. // } else {
  623. // [self.textTemplateArray addObject:watermark];
  624. // }
  625. // }
  626. } else {
  627. // for (NSUInteger i = 0; i < [KMBackgroundManager defaultManager].datas.count; i++) {
  628. // KMBackgroundObject *obj = [[KMBackgroundManager defaultManager].datas objectAtIndex:i];
  629. // if (obj.type == KMBackgroundTypeColor) {
  630. // [self.textTemplateArray addObject:obj];
  631. // } else {
  632. // [self.fileTemplateArray addObject:obj];
  633. // }
  634. // }
  635. }
  636. self.collectionView.reloadData()
  637. self._updateActionButtonbackgroundColor()
  638. NotificationCenter.default.addObserver(self, selector: #selector(_batchFilesCountNotification), name: NSNotification.Name("KMBatchFilesCountNotification"), object: nil)
  639. }
  640. private func _isSelectIndex() -> Bool {
  641. var indexSet = false
  642. if (!self.isBackground) {
  643. if(self.currentType == .txt) {
  644. if let data = self._currentTextData {
  645. indexSet = (self._textTemplateArray ?? []).contains(data)
  646. }
  647. }else {
  648. if let data = self._currentFileData {
  649. indexSet = (self._fileTemplateArray ?? []).contains(data)
  650. }
  651. }
  652. } else {
  653. if(self.currentBackgroundType == .color) {
  654. if let data = self._currentColorData {
  655. indexSet = (self._textTemplateArray ?? []).contains(data)
  656. }
  657. }else {
  658. if let data = self._currentImageData {
  659. indexSet = (self._fileTemplateArray ?? []).contains(data)
  660. }
  661. }
  662. }
  663. return indexSet;
  664. }
  665. private func _updateActionButtonbackgroundColor() {
  666. let indexSet = self._isSelectIndex()
  667. if let cnt = self.files?.count, cnt > 0 {
  668. if self.pdfView != nil && indexSet {
  669. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color())
  670. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  671. }
  672. } else {
  673. self.actionButton.setTitleColor(KMAppearance.Layout.w0Color().withAlphaComponent(0.6))
  674. self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.6).cgColor
  675. }
  676. }
  677. @objc private func _buttonItemClick_addBatch(_ sender: Any?) {
  678. let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
  679. baseWindowController.window?.makeKeyAndOrderFront(nil)
  680. // NSMutableArray *arr = [NSMutableArray array];
  681. // KMBatchOperateFile *file = [[KMBatchOperateFile alloc] initWithFilePath:self.pdfView.document.documentURL.path type:self.isBackground ? KMBatchOperationTypeAddBackground : KMBatchOperationTypeAddWatermark];
  682. // [arr addObject:file];
  683. // [baseWindowController checkNeedPasswordSwitchToOperateType:self.isBackground ? KMBatchOperationTypeAddBackground : KMBatchOperationTypeAddWatermark files:arr];
  684. }
  685. @objc private func _buttonItemClick_CleanAll(_ sender: Any?) {
  686. let alert = NSAlert()
  687. alert.alertStyle = .warning
  688. alert.messageText = ""
  689. alert.informativeText = KMLocalizedString("Are you sure to delete all templates?", nil)
  690. alert.addButton(withTitle: KMLocalizedString("Delete", nil))
  691. alert.addButton(withTitle: KMLocalizedString("Cancel", nil))
  692. alert.beginSheetModal(for: NSApp.mainWindow!) { returnCode in
  693. if returnCode == .alertFirstButtonReturn {
  694. self._deleteAllWatermark()
  695. }
  696. }
  697. }
  698. private func _deleteAllWatermark() {
  699. if(!self.isBackground) {
  700. for waterMark in self._textTemplateArray ?? [] {
  701. // [[KMWatermarkManager defaultManager] removeWatermarkWithData:waterMark];
  702. }
  703. for waterMark in self._fileTemplateArray ?? [] {
  704. // [[KMWatermarkManager defaultManager] removeWatermarkWithData:waterMark];
  705. }
  706. } else {
  707. for background in self._textTemplateArray ?? [] {
  708. // [[KMBackgroundManager defaultManager] removeBackground:background];
  709. }
  710. for background in self._fileTemplateArray ?? [] {
  711. // [[KMBackgroundManager defaultManager] removeBackground:background];
  712. }
  713. }
  714. self._loadData()
  715. self._postNotification()
  716. }
  717. private func _deleteWatermark(_ waterMark: KMPDFWatermarkData) {
  718. // [[KMWatermarkManager defaultManager] removeWatermarkWithData:waterMark];
  719. self._loadData()
  720. self._postNotification()
  721. }
  722. private func _postNotification() {
  723. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMBatchOperateWatermarksNotification"), object: self)
  724. }
  725. @objc private func _watermarksNotification(_ notification: NSNotification) {
  726. let addWatermark = notification.object as? KMBatchOperateAddWatermarkViewController
  727. if self.isEqual(to: addWatermark) == false {
  728. self._loadData()
  729. var haveWaters = false
  730. if (self.currentType == .txt) {
  731. if let cnt = self._textTemplateArray?.count, cnt > 0 {
  732. haveWaters = true
  733. }
  734. } else if (self.currentType == .file) {
  735. if let cnt = self._fileTemplateArray?.count, cnt > 0 {
  736. haveWaters = true
  737. }
  738. }
  739. if (haveWaters) {
  740. let indexpath = IndexPath(item: 0, section: 0)
  741. var set = Set<IndexPath>()
  742. set.insert(indexpath)
  743. self.collectionView.selectItems(at: set, scrollPosition: .bottom)
  744. }
  745. }
  746. }
  747. //检查是否有任务文件要加载,如果有,重置任务。如果返回YES,表示有任务并且任务已经重置,否则表示没有任务,需要中断操作
  748. private func _checkAndResetTask() -> Bool {
  749. if let cnt = self.files?.count, cnt < 1 {
  750. return false
  751. }
  752. for i in 0 ..< self.files!.count {
  753. let file = self.files![i]
  754. if (self.isBackground) {
  755. // [file.addBackgroundInfo resetState];
  756. } else {
  757. // [file.addWatermarkInfo resetState];
  758. }
  759. }
  760. return true
  761. }
  762. private func _choosePathAndBeginOperation(_ obj: Any?) {
  763. let openPanel = NSOpenPanel()
  764. openPanel.canChooseFiles = false
  765. openPanel.canChooseDirectories = true
  766. openPanel.canCreateDirectories = true
  767. openPanel.beginSheetModal(for: self.view.window!) { result in
  768. if (result == .OK) {
  769. for fileURL in openPanel.urls {
  770. self.choosePath = fileURL.path
  771. if (!self.isBackground) {
  772. self._beginAddWatermark(obj as! KMPDFWatermarkData)
  773. } else {
  774. self._beginAddBackground(obj as! KMBackgroundObject)
  775. }
  776. }
  777. }
  778. }
  779. }
  780. private func _beginAddWatermark(_ watermark: KMPDFWatermarkData) {
  781. self.hiddenWindowCloseButtonIfNeeded()
  782. // [self.successFilePathURLArray removeAllObjects];
  783. for i in 0 ..< self.files!.count {
  784. let file = self.files![i]
  785. file.addWatermarkInfo.savePath = self.choosePath
  786. // KMBatchAddWatermarkOperation *operation = [[[KMBatchAddWatermarkOperation alloc] initWithFile:file waterMark:watermark] autorelease];
  787. // operation.delegate = self;
  788. // [self.queue addOperation:operation];
  789. }
  790. if let cnt = self.queue?.operations.count, cnt > 0 {
  791. self.interfaceStatus = .Processing
  792. }
  793. }
  794. private func _beginAddBackground(_ background: KMBackgroundObject) {
  795. self.hiddenWindowCloseButtonIfNeeded()
  796. // [self.successFilePathURLArray removeAllObjects];
  797. for i in 0 ..< self.files!.count {
  798. let file = self.files![i]
  799. file.addBackgroundInfo.savePath = self.choosePath
  800. // KMBatchAddBackgroundOperation *operation = [[[KMBatchAddBackgroundOperation alloc] initWithFile:file background:background] autorelease];
  801. // operation.delegate = self;
  802. // [self.queue addOperation:operation];
  803. }
  804. if let cnt = self.queue?.operations.count, cnt > 0 {
  805. self.interfaceStatus = .Processing
  806. }
  807. }
  808. @objc private func _batchFilesCountNotification(_ notification: NSNotification) {
  809. if (!self.onlyManagerTemplate) {
  810. let files = notification.object as? [AnyObject] ?? []
  811. if (files.count > 0) {
  812. self._haveFiles = true
  813. } else {
  814. self._haveFiles = false
  815. }
  816. self._updateActionButtonbackgroundColor()
  817. }
  818. }
  819. }
  820. extension KMBatchOperateAddWatermarkViewController: NSMenuItemValidation {
  821. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  822. let action = menuItem.action
  823. if (action == #selector(_buttonItemClick_CleanAll)) {
  824. if (self._textTemplateArray!.count == 0 && self._fileTemplateArray!.count == 0) {
  825. return false
  826. }
  827. return true
  828. }
  829. return true
  830. }
  831. }
  832. extension KMBatchOperateAddWatermarkViewController: NSCollectionViewDelegate, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout {
  833. func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
  834. var count = 0
  835. if (!self.isBackground) {
  836. if (self.currentType == .txt) {
  837. count = self._textTemplateArray?.count ?? 0
  838. } else {
  839. count = self._fileTemplateArray?.count ?? 0
  840. }
  841. } else {
  842. if (self.currentBackgroundType == .color) {
  843. count = self._textTemplateArray?.count ?? 0
  844. } else {
  845. count = self._fileTemplateArray?.count ?? 0
  846. }
  847. }
  848. self.blankView.isHidden = count != 0
  849. return count
  850. }
  851. func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
  852. let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMWatermarkCollectionViewItem"), for: indexPath)
  853. if (!self.isBackground) {
  854. var waterMark: KMPDFWatermarkData?
  855. if (self.currentType == .txt) {
  856. waterMark = self._textTemplateArray![indexPath.item] as! KMPDFWatermarkData
  857. if(self._currentTextData == waterMark) {
  858. item.isSelected = true
  859. }else {
  860. item.isSelected = false
  861. }
  862. } else {
  863. waterMark = self._fileTemplateArray![indexPath.item] as! KMPDFWatermarkData
  864. if(self._currentFileData == waterMark) {
  865. item.isSelected = true
  866. }else{
  867. item.isSelected = false
  868. }
  869. }
  870. // __block typeof(self) blockSelf = self;
  871. let _item = item as? KMWatermarkCollectionViewItem
  872. _item?.updateInterface(waterMark!)
  873. _item?.waterMarkOprateCallback = { [unowned self] type, wm in
  874. if (wm != nil) {
  875. if (type == .Edit) {
  876. if (self.currentType == .txt) {
  877. self._currentTextData = waterMark
  878. } else {
  879. self._currentFileData = waterMark
  880. }
  881. collectionView.reloadData()
  882. // [blockSelf editWatermark:watermark];
  883. } else {
  884. // [blockSelf deleteWatermark:watermark];
  885. }
  886. }
  887. };
  888. } else {
  889. var background: KMBackgroundObject?
  890. if (self.currentBackgroundType == .color) {
  891. background = self._textTemplateArray![indexPath.item] as! KMBackgroundObject
  892. if(self._currentColorData == background) {
  893. item.isSelected = true
  894. }else {
  895. item.isSelected = false
  896. }
  897. } else {
  898. background = self._fileTemplateArray![indexPath.item] as! KMBackgroundObject
  899. if(self._currentImageData == background) {
  900. item.isSelected = true
  901. }else {
  902. item.isSelected = false
  903. }
  904. }
  905. let _item = item as? KMWatermarkCollectionViewItem
  906. _item?.updateBackgroundInterface(background!)
  907. // __block typeof(self) blockSelf = self;
  908. _item?.backgroundOperateCallback = { [unowned self] type, bg in
  909. if (type == .Edit) {
  910. if (self.currentBackgroundType == .color) {
  911. self._currentColorData = background
  912. } else {
  913. self._currentImageData = background
  914. }
  915. collectionView.reloadData()
  916. // [blockSelf editBackground:background];
  917. } else {
  918. // [blockSelf deleteBackground:background];
  919. }
  920. } ;
  921. }
  922. self._updateActionButtonbackgroundColor()
  923. return item
  924. }
  925. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
  926. if (collectionView.frame.size.width < 240) {
  927. return CGSizeMake(0, 0)
  928. } else {
  929. return CGSizeMake(104, 167)
  930. }
  931. }
  932. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
  933. if (collectionView.frame.size.width < 32) {
  934. return NSEdgeInsetsMake(0, 0, 0, 0)
  935. }
  936. return NSEdgeInsetsMake(0, 16, 0, 16)
  937. }
  938. func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
  939. let indexPath = indexPaths.first
  940. guard let _indexPath = indexPath else {
  941. return
  942. }
  943. if (indexPath!.item < 0) {
  944. return
  945. }
  946. if (self.isBackground) {
  947. var background: KMBackgroundObject?
  948. if (self.currentBackgroundType == .color) {
  949. background = self._textTemplateArray![_indexPath.item] as? KMBackgroundObject
  950. self._currentColorData = background
  951. } else {
  952. background = self._fileTemplateArray![_indexPath.item] as? KMBackgroundObject
  953. self._currentImageData = background
  954. }
  955. for i in 0 ..< self.files!.count {
  956. let file = self.files![i]
  957. // file.addBackgroundInfo.pageChoice = background.pageRangeType;
  958. // if (file.addBackgroundInfo.pageChoice == KMBatchOperatePageChoice_Input) {
  959. // NSArray *arr = [self allPageNumbers:background.pagesString];
  960. // NSArray *sortedArray = [file pagesArrayIntersectWithArray:arr];
  961. // if (sortedArray.count < 1) {
  962. // file.addBackgroundInfo.pageChoice = KMBatchOperatePageChoice_All;
  963. // } else {
  964. // file.addBackgroundInfo.pageRangeString = [sortedArray componentsJoinedByString:@","];
  965. // }
  966. // }
  967. }
  968. } else {
  969. var waterMark: KMPDFWatermarkData?
  970. if (self.currentType == .txt) {
  971. waterMark = self._textTemplateArray![_indexPath.item] as? KMPDFWatermarkData
  972. self._currentTextData = waterMark
  973. } else {
  974. waterMark = self._fileTemplateArray![_indexPath.item] as? KMPDFWatermarkData
  975. self._currentFileData = waterMark
  976. }
  977. for i in 0 ..< self.files!.count {
  978. let file = self.files![i]
  979. // file.addWatermarkInfo.pageChoice = waterMark.pageRangeType;
  980. // if (file.addWatermarkInfo.pageChoice == KMBatchOperatePageChoice_Input) {
  981. // NSArray *arr = [self allPageNumbers:waterMark.pagesString];
  982. // NSArray *sortedArray = [file pagesArrayIntersectWithArray:arr];
  983. // if (sortedArray.count < 1) {
  984. // file.addWatermarkInfo.pageChoice = KMBatchOperatePageChoice_All;
  985. // } else {
  986. // file.addWatermarkInfo.pageRangeString = [sortedArray componentsJoinedByString:@","];
  987. // }
  988. // }
  989. }
  990. }
  991. NotificationCenter.default.post(name: NSNotification.Name("kNeedChangePageRangeNotification"), object: nil)
  992. collectionView.reloadData()
  993. self._updateActionButtonbackgroundColor()
  994. }
  995. }