Просмотр исходного кода

综合 - 添加删除全部功能;删除文件时,会对照删除 对照文档及结果文件

zhudongyong 1 год назад
Родитель
Сommit
432bfe2e6a

+ 32 - 0
KdanAutoTest/KdanAuto/Class/Norrmal/AutoTestAdvanceSettingView.swift

@@ -471,10 +471,19 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
     
     func fileCellNeedDelete(_ cell:TestFileCellView, fileName:String) {
         let originDirectory = _autoTestObj?.originFileDirectory()
+        let resultDirectory = _autoTestObj?.resultFileDirectory()
+        let compareDirectory = _autoTestObj?.checkFileDirectory()
+        
+        let nFileName = NSString(string: NSString(string: fileName).deletingPathExtension).appendingPathExtension(_autoTestObj?.extention() ?? "")! as String
+        
         let path = NSString(string: originDirectory!).appendingPathComponent(fileName);
+        let resultPath = NSString(string: resultDirectory!).appendingPathComponent(nFileName);
+        let comparePath = NSString(string: compareDirectory!).appendingPathComponent(nFileName);
         
         FileConverter.shared().cancelTaskForSrcPath(path);
         try? FileManager.default.removeItem(atPath: path);
+        try? FileManager.default.removeItem(atPath: resultPath);
+        try? FileManager.default.removeItem(atPath: comparePath);
         
         let index = _files.firstIndex(of: fileName)
         
@@ -484,6 +493,29 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
         }
     }
     
+    func fileCellNeedDeleteAll(_ cell:TestFileCellView) {
+        let originDirectory = _autoTestObj?.originFileDirectory()
+        let resultDirectory = _autoTestObj?.resultFileDirectory()
+        let compareDirectory = _autoTestObj?.checkFileDirectory()
+        
+        for fn in _files {
+            let nFileName = NSString(string: NSString(string: fn).deletingPathExtension).appendingPathExtension(_autoTestObj?.extention() ?? "")! as String
+            
+            let path = NSString(string: originDirectory!).appendingPathComponent(fn);
+            let resultPath = NSString(string: resultDirectory!).appendingPathComponent(nFileName);
+            let comparePath = NSString(string: compareDirectory!).appendingPathComponent(nFileName);
+            
+            FileConverter.shared().cancelTaskForSrcPath(path);
+            try? FileManager.default.removeItem(atPath: path);
+            
+            try? FileManager.default.removeItem(atPath: resultPath);
+            try? FileManager.default.removeItem(atPath: comparePath);
+        }
+        
+        _files = [];
+        _fileList.reloadData()
+    }
+    
     func fileCellNeedCancelConvertTask(_ cell:TestFileCellView, fileName:String) {
         let originDirectory = _autoTestObj?.originFileDirectory()
         let path = NSString(string: originDirectory!).appendingPathComponent(fileName);

+ 11 - 0
KdanAutoTest/KdanAuto/Class/Norrmal/Cell/TestFileCellView.swift

@@ -23,6 +23,8 @@ protocol TestFileCellViewDelegate : NSObjectProtocol {
     
     func fileCellNeedDelete(_ cell:TestFileCellView, fileName:String)
     
+    func fileCellNeedDeleteAll(_ cell:TestFileCellView)
+    
     func fileCellNeedCancelConvertTask(_ cell:TestFileCellView, fileName:String)
 }
 
@@ -95,6 +97,9 @@ class TestFileCellView : NSTableCellView, NSMenuDelegate {
         let item1 = NSMenuItem.init(title: "删除", action: #selector(self.deleteActions(_:)), keyEquivalent: "")
         _menu.addItem(item1)
         item1.target = self;
+        let deleteAll = NSMenuItem.init(title: "删除全部", action: #selector(self.deleteAllActions(_:)), keyEquivalent: "")
+        _menu.addItem(deleteAll)
+        deleteAll.target = self;
         
         self.menu = _menu
         self.menu?.delegate = self;
@@ -208,6 +213,12 @@ class TestFileCellView : NSTableCellView, NSMenuDelegate {
         }
     }
     
+    @IBAction func deleteAllActions(_ sender:NSMenuItem) {
+        if _delegate != nil {
+            _delegate?.fileCellNeedDeleteAll(self)
+        }
+    }
+    
     @IBAction func cancelAction(_ sender:NSMenuItem) {
         if (_delegate != nil) {
             _cancelMenuItem.isEnabled = false;