123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- //
- // TeseCaseCell.swift
- // KdanAuto
- //
- // Created by 朱东勇 on 2022/11/21.
- //
- import Foundation
- import AppKit
- enum TestFileType {
- case Origin
- case Result
- case Compare
- }
- protocol TestFileCellViewDelegate : NSObjectProtocol {
- func fileCellNeedReplace(_ cell:TestFileCellView, fileName:String)
-
- func fileCellNeedShowReport(_ cell:TestFileCellView, fileName:String, sender:NSButton)
-
- func fileCellNeedShowInFinder(_ cell:TestFileCellView, fileName:String, type:TestFileType)
-
- func fileCellNeedDelete(_ cell:TestFileCellView, fileName:String)
-
- func fileCellNeedCancelConvertTask(_ cell:TestFileCellView, fileName:String)
- }
- class TestFileCellView : NSTableCellView, NSMenuDelegate {
- @IBOutlet var _titleLbl : NSTextField!
- @IBOutlet var _sepLine : NSView!
- @IBOutlet var _progressView : NSProgressIndicator!
-
- @IBOutlet var _replaceBtn : NSButton!
- @IBOutlet var _testReportBtn : NSButton!
-
- var _title : String!
- var _isExpad: Bool!
- var _typeInfo : NSDictionary!
-
-
- var _showOriginMenuItem : NSMenuItem!
- var _showResultMenuItem : NSMenuItem!
- var _showCompareMenuItem : NSMenuItem!
-
- var _cancelMenuItem : NSMenuItem!
-
- var _isActivting : Bool = false;
-
- var _degree : Double = 0
-
- weak public var _delegate : (TestFileCellViewDelegate)?
-
- class func shared() -> TestFileCellView? {
- var objects : NSArray!
-
- Bundle.main.loadNibNamed("TestFileCellView", owner: nil, topLevelObjects: &objects)
-
- for tView in objects {
- if let tv = tView as? TestFileCellView {
- return tv
- }
- }
-
- return nil
- }
-
- override func awakeFromNib() {
- _sepLine.wantsLayer = true;
- _sepLine.layer?.backgroundColor = NSColor.lightGray.cgColor
-
- let _menu = NSMenu(title: "")
- // Show In Finder
- _showOriginMenuItem = NSMenuItem.init(title: "在访达中显示[原文件]", action:#selector(self.showInFinder(_:)), keyEquivalent: "")
- _showOriginMenuItem.target = self;
- _menu.addItem(_showOriginMenuItem)
- _showResultMenuItem = NSMenuItem.init(title: "在访达中显示[结果文件]", action:#selector(self.showInFinder(_:)), keyEquivalent: "")
- _showResultMenuItem.target = self;
- _menu.addItem(_showResultMenuItem)
- _showCompareMenuItem = NSMenuItem.init(title: "在访达中显示[对照文件]", action:#selector(self.showInFinder(_:)), keyEquivalent: "")
- _showCompareMenuItem.target = self;
- _menu.addItem(_showCompareMenuItem)
-
- _menu.addItem(NSMenuItem.separator());
-
- // Cancel Convert Task
- _cancelMenuItem = NSMenuItem.init(title: "取消转档任务", action: #selector(self.cancelAction(_:)), keyEquivalent: "")
- _cancelMenuItem.isEnabled = false;
- _menu.addItem(_cancelMenuItem)
- _cancelMenuItem.target = self;
-
- _menu.addItem(NSMenuItem.separator());
-
- // Delete Origin Files
- let item1 = NSMenuItem.init(title: "删除", action: #selector(self.deleteActions(_:)), keyEquivalent: "")
- _menu.addItem(item1)
- item1.target = self;
-
- self.menu = _menu
- self.menu?.delegate = self;
-
- NSEvent.addLocalMonitorForEvents(matching: NSEvent.EventTypeMask.rightMouseUp) { event in
- var point = event.locationInWindow;
- if (nil != self.window?.contentView) {
- point = self.window!.contentView!.convert(point, to: self)
-
- if (event.type == .rightMouseUp && CGRectContainsPoint(self.bounds, point)) {
- NSMenu.popUpContextMenu(self.menu!, with: event, for: self)
- return nil;
- }
- }
-
- return event
- }
- }
-
- // Setter & Getter
- public func setTitle(_ title:String) {
- _title = title;
-
- _titleLbl.stringValue = _title ?? ""
- }
-
- public func title() -> String? {
- return _title
- }
-
- public func set(_ activiting:Bool) {
- _isActivting = activiting;
-
- if (_isActivting) {
- _progressView.startAnimation(nil);
- _cancelMenuItem.isEnabled = true;
- }else {
- _progressView.stopAnimation(nil);
- _cancelMenuItem.isEnabled = false;
- }
- _progressView.isHidden = !_isActivting
- }
-
- public func fileType() -> String? {
- return _title
- }
-
- public func setNeedReplaceBtn(_ needReplace:Bool) {
- _replaceBtn.isHidden = !needReplace
- }
-
- public func setTypeInfo(_ typeInfo:NSDictionary) {
- _typeInfo = typeInfo
-
- self.setTitle(_typeInfo["Type"] as! String)
- }
-
- public func typeInfo() -> NSDictionary? {
- return _typeInfo
- }
-
- public func setNeedDegreeBtn(_ needDegree:Bool) {
- _testReportBtn.isHidden = !needDegree
-
- if (needDegree) {
- self.set(!needDegree)
- }
- }
-
- public func setDegree(_ degree:Double) {
- _degree = degree
-
- if fabs(_degree - 100) > 0.01 {
- _testReportBtn.contentTintColor = NSColor.red
- }else {
- _testReportBtn.contentTintColor = NSColor.gray
- }
-
- _testReportBtn.title = NSString(format: "%.0f%%", floor(_degree)) as String
- }
-
- // IBActionn
- @IBAction func replaceAction(_ sender:NSButton) {
- if _delegate != nil {
- _delegate?.fileCellNeedReplace(self, fileName: _title)
- }
- }
-
- @IBAction func showReportAction(_ sender:NSButton) {
- if _delegate != nil {
- _delegate?.fileCellNeedShowReport(self, fileName: _title, sender: sender)
- }
- }
-
- @IBAction func showInFinder(_ sender:NSMenuItem) {
- if _delegate != nil {
- var type = TestFileType.Origin;
- if (sender == _showResultMenuItem) {
- type = TestFileType.Result
- }else if (sender == _showCompareMenuItem) {
- type = TestFileType.Compare
- }
-
- _delegate?.fileCellNeedShowInFinder(self, fileName: _title, type: type)
- }
- }
-
- @IBAction func deleteActions(_ sender:NSMenuItem) {
- if _delegate != nil {
- _delegate?.fileCellNeedDelete(self, fileName: _title)
- }
- }
-
- @IBAction func cancelAction(_ sender:NSMenuItem) {
- if (_delegate != nil) {
- _cancelMenuItem.isEnabled = false;
- _delegate?.fileCellNeedCancelConvertTask(self, fileName: _title);
- }
- }
- }
|