123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- //
- // TeseCaseCell.swift
- // KdanAuto
- //
- // Created by 朱东勇 on 2022/11/21.
- //
- import Foundation
- import AppKit
- protocol TestFileCellViewDelegate : NSObjectProtocol {
- func fileCellNeedReplace(_ cell:TestFileCellView, fileName:String)
-
- func fileCellNeedShowReport(_ cell:TestFileCellView, fileName:String, sender:NSButton)
-
- func fileCellNeedShowInFinder(_ cell:TestFileCellView, fileName:String)
-
- func fileCellNeedDelete(_ 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 _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: "")
- let item = NSMenuItem.init(title: "在访达中显示", action:#selector(self.showInFinder(_:)), keyEquivalent: "")
- item.target = self;
- _menu.addItem(item)
- 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);
- }else {
- _progressView.stopAnimation(nil);
- }
- _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%%", _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 {
- _delegate?.fileCellNeedShowInFinder(self, fileName: _title)
- }
- }
-
- @IBAction func deleteActions(_ sender:NSMenuItem) {
- if _delegate != nil {
- _delegate?.fileCellNeedDelete(self, fileName: _title)
- }
- }
- }
|