Browse Source

【综合】水印模板管理调整

niehaoyu 8 months ago
parent
commit
876cde1364

+ 49 - 110
PDF Office/PDF Master/Class/PDFTools/Watermark/Controller/KMBatchOperateAddWatermarkViewController.swift

@@ -65,16 +65,12 @@ class KMBatchOperateAddWatermarkViewController: KMBatchOperateBaseViewController
                 self._currentBackgroundType = newValue
                 
                 if (self._currentBackgroundType == .color) {
-        //            self.textButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
-        //            self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
                     self.textBox.fillColor = KMAppearance.Interactive.a0Color()
                     self.fileBox.fillColor = KMAppearance.Layout.l_1Color()
                     
                     self.textButton.setTitleColor(KMAppearance.Layout.w0Color())
                     self.fileButton.setTitleColor(KMAppearance.Layout.h1Color())
                 } else {
-        //            self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
-        //            self.textButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
                     self.textBox.fillColor = KMAppearance.Layout.l_1Color()
                     self.fileBox.fillColor = KMAppearance.Interactive.a0Color()
                     
@@ -93,15 +89,11 @@ class KMBatchOperateAddWatermarkViewController: KMBatchOperateBaseViewController
                 self._currentType = newValue
                 
                 if (currentType == .txt) {
-        //            self.textButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
-        //            self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
                     self.textBox.fillColor = KMAppearance.Interactive.a0Color()
                     self.fileBox.fillColor = KMAppearance.Layout.l_1Color()
                     self.textButton.setTitleColor(KMAppearance.Layout.w0Color())
                     self.fileButton.setTitleColor(KMAppearance.Layout.h1Color())
                 } else {
-        //            self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
-        //            self.textButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
                     self.textBox.fillColor = KMAppearance.Layout.l_1Color()
                     self.fileBox.fillColor = KMAppearance.Interactive.a0Color()
                     self.fileButton.setTitleColor(KMAppearance.Layout.w0Color())
@@ -132,6 +124,8 @@ class KMBatchOperateAddWatermarkViewController: KMBatchOperateBaseViewController
         self.interfaceStatus = .PrepareProcess
         
         NotificationCenter.default.addObserver(self, selector: #selector(_watermarksNotification), name: NSNotification.Name("KMBatchOperateWatermarksNotification"), object: nil)
+        
+        self.collectionView.reloadData()
     }
      
     func watermarkInterfaceSelectWatermark(_ watermark: KMWatermarkModel) {
@@ -190,16 +184,8 @@ class KMBatchOperateAddWatermarkViewController: KMBatchOperateBaseViewController
 
                 self.collectionView.isSelectable = true
                 self.actionButton.tag = 1
-        //        if (self.isBackground) {
-        //            self.actionButton.title = NSLocalizedString(@"Add Background", nil);
-        //        } else {
-        //            self.actionButton.title = NSLocalizedString(@"Add Watermark", nil);
-        //        }
                 self.actionButton.title = KMLocalizedString("Apply", nil)
                 self.addButton.isEnabled = true
-        //        if (self.onlyManagerTemplate) {
-        //            self.actionButton.title = NSLocalizedString(@"Add Template", nil);
-        //        }
             } else {
                 self.collectionView.isSelectable = false
                 self.addButton.isEnabled = false
@@ -421,22 +407,12 @@ extension KMBatchOperateAddWatermarkViewController {
         if (!self.isBackground) {
             self.titleLabel.stringValue = KMLocalizedString("Watermark", nil)
             self.textButton.title = KMLocalizedString("Text", nil)
-    //        self.actionButton.title = NSLocalizedString(@"Add Watermark", nil);
         } else {
             self.titleLabel.stringValue = KMLocalizedString("Background", nil)
             self.textButton.title = KMLocalizedString("Color", nil)
-    //        self.actionButton.title = NSLocalizedString(@"Add Background", nil);
         }
-    //    if (self.onlyManagerTemplate) {
-    //        self.actionButton.title = NSLocalizedString(@"Add Template", nil);
-    //    }
 
         if (self.onlyManagerTemplate) {
-    //        self.titleLabel.hidden = self.addButton.hidden = YES;
-    //        self.managerTemplateTitleLabel.hidden = NO;
-    //        self.addButtonHeightConstraint.constant = 0;
-    //        self.addButtonBottomConstraint.constant = 0;
-            
             self.titleLabel.isHidden = true
             self.addButton.isHidden = false
             self.managerTemplateTitleLabel.isHidden = false
@@ -479,14 +455,10 @@ extension KMBatchOperateAddWatermarkViewController {
         self.actionButton.wantsLayer = true
         self.addButton.wantsLayer = true
         if (self.onlyManagerTemplate) {
-    //        [self.actionButton setImage:[NSImage imageNamed:KMImageNameUXIconBtnAddWhite]];
-    //        self.actionButton.imagePosition = NSImageLeft;
-    //        [self.actionButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
-            
+ 
             self.topHeightConstraint.constant = 40
             self.addButton.imagePosition = .imageLeft
             self.addButton.image = NSImage(named: "KMImageNameHeaderFooterAddBtn")
-    //        self.addButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_S0].CGColor;
             self.addButton.setTitleColor(KMAppearance.Layout.h0Color())
             
             self.actionButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
@@ -496,7 +468,6 @@ extension KMBatchOperateAddWatermarkViewController {
             self.topHeightConstraint.constant = 0
             self.addButton.imagePosition = .imageLeft
             self.addButton.image = NSImage(named: "KMImageNameHeaderFooterAddBtn")
-    //        self.addButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_S0].CGColor;
             self.addButton.setTitleColor(KMAppearance.Layout.h0Color())
             
             self.actionButton.setTitleColor(KMAppearance.Layout.w0Color().withAlphaComponent(0.6))
@@ -518,16 +489,11 @@ extension KMBatchOperateAddWatermarkViewController {
         
         self.actionButton.layer?.cornerRadius = 1.0
         
-        //    self.bottomBaseView.wantsLayer = YES;
-        //    self.bottomBaseView.layer.backgroundColor =  [KMAppearance KMColor_Layout_L0].CGColor;
-            
-            self.textButton.wantsLayer = true
-            self.fileButton.wantsLayer = true
-        //    self.textButton.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
-        //    self.fileButton.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
+        self.textButton.wantsLayer = true
+        self.fileButton.wantsLayer = true
         self.textBox.fillColor = KMAppearance.Interactive.a0Color()
         self.fileBox.fillColor = KMAppearance.Layout.l_1Color()
-            
+        
         self.textButton.setTitleColor(KMAppearance.Layout.w0Color())
         self.fileButton.setTitleColor(KMAppearance.Layout.h0Color())
         self.managerTemplateTitleLabel.font = .systemFont(ofSize: 14)
@@ -540,28 +506,25 @@ extension KMBatchOperateAddWatermarkViewController {
             make?.bottom.equalTo()(self.bottomBaseView.mas_top)
             make?.height.greaterThanOrEqualTo()(200)
         }
-            self.blankView.titleLabel.stringValue = KMLocalizedString("No Templates", nil)
-            
-            if (self.isBackground) {
-                self.blankView.imageView.image = NSImage(named: KMImageNameEmptyBackground)
-            }
-            self.blankView.wantsLayer = true
-        //    self.blankView.layer.backgroundColor = [KMAppearance KMColor_Layout_L0].CGColor;
-            
-//            NSMenu * = [[NSMenu alloc]initWithTitle:@""];
+        self.blankView.titleLabel.stringValue = KMLocalizedString("No Templates", nil)
+        
+        if (self.isBackground) {
+            self.blankView.imageView.image = NSImage(named: KMImageNameEmptyBackground)
+        }
+        self.blankView.wantsLayer = true
         let menu = NSMenu()
-            if(!self.isBackground) {
-                    if(!self.isBatchOperation) {
-                        _ = menu.addItem(title: KMLocalizedString("Batch Add Watermarks", nil), action: #selector(_buttonItemClick_addBatch), target: self)
-                    }
-                _ = menu.addItem(title: KMLocalizedString("Remove All Watermark Templates", nil), action: #selector(_buttonItemClick_CleanAll), target: self)
-            } else {
-                if(!self.isBatchOperation) {
-                    _ = menu.addItem(title: KMLocalizedString("Batch Add Background", nil), action: #selector(_buttonItemClick_addBatch), target: self)
-                }
-                _ = menu.addItem(title: KMLocalizedString("Remove All Background Templates", nil), action: #selector(_buttonItemClick_CleanAll), target: self)
+        if(!self.isBackground) {
+            if(!self.isBatchOperation) {
+                _ = menu.addItem(title: KMLocalizedString("Batch Add Watermarks", nil), action: #selector(_buttonItemClick_addBatch), target: self)
+            }
+            _ = menu.addItem(title: KMLocalizedString("Remove All Watermark Templates", nil), action: #selector(_buttonItemClick_CleanAll), target: self)
+        } else {
+            if(!self.isBatchOperation) {
+                _ = menu.addItem(title: KMLocalizedString("Batch Add Background", nil), action: #selector(_buttonItemClick_addBatch), target: self)
             }
-            self.view.menu = menu;
+            _ = menu.addItem(title: KMLocalizedString("Remove All Background Templates", nil), action: #selector(_buttonItemClick_CleanAll), target: self)
+        }
+        self.view.menu = menu;
     }
     
     private func _loadData() {
@@ -632,9 +595,7 @@ extension KMBatchOperateAddWatermarkViewController {
     
     @objc private func _buttonItemClick_addBatch(_ sender: Any?) {
         let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
-       
-//        NSMutableArray *arr = [NSMutableArray array];
-        
+               
         let file = KMBatchOperateFile(filePath: self.pdfView!.document.documentURL.path, type: self.isBackground ? .AddBackground : .AddWatermark)
         
         baseWindowController.window?.makeKeyAndOrderFront(nil)
@@ -667,22 +628,22 @@ extension KMBatchOperateAddWatermarkViewController {
         controller.background = background
         controller.currentType = self.currentBackgroundType.rawValue
         controller.pdfDocument = cdocument
-        controller.cancelAction = { [unowned self] controller in
-            self.km_endSheet()
+        controller.cancelAction = { [weak self] controller in
+            self?.km_endSheet()
         }
         self.km_beginSheet(windowC: controller)
-        controller.operateCallBack = { controller, background, countType in
-            self.currentBackgroundType = KMBackgroundType(rawValue: countType) ?? .color
-            self._loadData()
+        controller.operateCallBack = {[weak self] controller, background, countType in
+            self?.currentBackgroundType = KMBackgroundType(rawValue: countType) ?? .color
+            self?._loadData()
             var haveBackgrounds = false
-            if self.currentBackgroundType == .color {
-                self._currentColorData = background
-                if self._textTemplateArray?.count ?? 0 > 0 {
+            if self?.currentBackgroundType == .color {
+                self?._currentColorData = background
+                if self?._textTemplateArray?.count ?? 0 > 0 {
                     haveBackgrounds = true
                 }
-            } else if self.currentBackgroundType == .file {
-                self._currentImageData = background
-                if self._fileTemplateArray?.count ?? 0 > 0 {
+            } else if self?.currentBackgroundType == .file {
+                self?._currentImageData = background
+                if self?._fileTemplateArray?.count ?? 0 > 0 {
                     haveBackgrounds = true
                 }
             }
@@ -690,9 +651,9 @@ extension KMBatchOperateAddWatermarkViewController {
                 let indexPath = IndexPath(item: 0, section: 0)
                 var set = Set<IndexPath>()
                 set.insert(indexPath)
-                self.collectionView.selectItems(at: set, scrollPosition: .bottom)
+                self?.collectionView.selectItems(at: set, scrollPosition: .bottom)
             }
-            self._postNotification()
+            self?._postNotification()
         }
     }
 
@@ -716,20 +677,20 @@ extension KMBatchOperateAddWatermarkViewController {
             controller.type = .edit
             controller.pdfDocument = cdocument
             controller.currentType = self.currentType.rawValue
-            controller.cancelAction = { [unowned self] wmWindowC in
-                self.km_endSheet()
+            controller.cancelAction = { [weak self] wmWindowC in
+                self?.km_endSheet()
             }
-            controller.operateCallBack = { controller, watermark, countType in
-                self._loadData()
+            controller.operateCallBack = {[weak self] controller, watermark, countType in
+                self?._loadData()
                 var haveWaters = false
-                if self.currentType == .txt {
-                    self._currentTextData = watermark
-                    if self._textTemplateArray?.count ?? 0 > 0 {
+                if self?.currentType == .txt {
+                    self?._currentTextData = watermark
+                    if self?._textTemplateArray?.count ?? 0 > 0 {
                         haveWaters = true
                     }
-                } else if self.currentType == .file {
-                    self._currentFileData = watermark
-                    if self._fileTemplateArray?.count ?? 0 > 0 {
+                } else if self?.currentType == .file {
+                    self?._currentFileData = watermark
+                    if self?._fileTemplateArray?.count ?? 0 > 0 {
                         haveWaters = true
                     }
                 }
@@ -737,9 +698,9 @@ extension KMBatchOperateAddWatermarkViewController {
                     let indexPath = IndexPath(item: 0, section: 0)
                     var set = Set<IndexPath>()
                     set.insert(indexPath)
-                    self.collectionView.selectItems(at: set, scrollPosition: .bottom)
+                    self?.collectionView.selectItems(at: set, scrollPosition: .bottom)
                 }
-                self._postNotification()
+                self?._postNotification()
             }
             self.km_beginSheet(windowC: controller)
         } else {
@@ -753,19 +714,9 @@ extension KMBatchOperateAddWatermarkViewController {
                 _ = KMWatermarkManager.defaultManager.removeWatermark(watermark: waterMark as! KMWatermarkModel)
             }
             for waterMark in self._fileTemplateArray ?? [] {
-//                [[KMWatermarkManager defaultManager] removeWatermarkWithData:waterMark];
                 _ = KMWatermarkManager.defaultManager.removeWatermark(watermark: waterMark as! KMWatermarkModel)
             }
         } else {
-//            for background in self._textTemplateArray ?? [] {
-////                [[KMBackgroundManager defaultManager] removeBackground:background];
-//                _ = KMBackgroundManager.defaultManager.deleteTemplate(model: background as! KMBackgroundModel)
-//            }
-//
-//            for background in self._fileTemplateArray ?? [] {
-////                [[KMBackgroundManager defaultManager] removeBackground:background];
-//                _ = KMBackgroundManager.defaultManager.deleteTemplate(model: background as! KMBackgroundModel)
-//            }
             _ = KMBackgroundManager.defaultManager.deleteAllTemplates()
         }
         
@@ -865,9 +816,6 @@ extension KMBatchOperateAddWatermarkViewController {
         for i in 0 ..< self.files!.count {
             let file = self.files![i]
             file.addBackgroundInfo.savePath = self.choosePath
-    //        KMBatchAddBackgroundOperation *operation = [[[KMBatchAddBackgroundOperation alloc] initWithFile:file background:background] autorelease];
-    //        operation.delegate = self;
-    //        [self.queue addOperation:operation];
             let operation = KMBatchAddBackgroundOperation(file: file, backgroundM: background)
             operation.delegate = self
             self.queue?.addOperation(operation)
@@ -1056,15 +1004,6 @@ extension KMBatchOperateAddWatermarkViewController: NSCollectionViewDelegate, NS
                 let file = self.files![i]
                 file.addWatermarkInfo.pageChoice = KMBatchOperatePageChoice.init(rawValue: (waterMark?.pageRangeType.rawValue)!)!
                 file.addWatermarkInfo.pageRangeString = waterMark?.pageRangeString
-//                if (file.addWatermarkInfo.pageChoice == KMBatchOperatePageChoice_Input) {
-//                    NSArray *arr = [self allPageNumbers:waterMark.pagesString];
-//                    NSArray *sortedArray = [file pagesArrayIntersectWithArray:arr];
-//                    if (sortedArray.count < 1) {
-//                        file.addWatermarkInfo.pageChoice = KMBatchOperatePageChoice_All;
-//                    } else {
-//                        file.addWatermarkInfo.pageRangeString = [sortedArray componentsJoinedByString:@","];
-//                    }
-//                }
             }
         }
         NotificationCenter.default.post(name: NSNotification.Name("kNeedChangePageRangeNotification"), object: nil)