This repository was archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathViewControllerAllOutput.swift
115 lines (102 loc) · 3.75 KB
/
ViewControllerAllOutput.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// ViewControllerAllOutput.swift
// RsyncOSX
//
// Created by Thomas Evensen on 10.08.2018.
// Copyright © 2018 Thomas Evensen. All rights reserved.
//
// swiftlint:disable line_length
import Cocoa
import Foundation
class ViewControllerAllOutput: NSViewController, Delay {
@IBOutlet var outputtable: NSTableView!
weak var getoutputDelegate: ViewOutputDetails?
var logging: Logfile?
@IBOutlet var rsyncorlog: NSSwitch!
@IBOutlet var outputrsyncorlofile: NSTextField!
@IBAction func rsyncorlogfile(_: NSButton) {
if rsyncorlog.state == .on {
outputrsyncorlofile.stringValue = "Rsync output..."
getoutputDelegate = SharedReference.shared.getvcref(viewcontroller: .vctabmain) as? ViewControllerMain
} else {
outputrsyncorlofile.stringValue = "Logfile..."
logging = Logfile(false)
getoutputDelegate = logging
}
globalMainQueue.async { () in
self.outputtable.reloadData()
}
}
@IBAction func clearoutput(_: NSButton) {
getoutputDelegate?.outputfromrsync(data: nil)
reloadtabledata()
}
override func viewDidLoad() {
super.viewDidLoad()
SharedReference.shared.setvcref(viewcontroller: .vcalloutput, nsviewcontroller: self)
outputtable.delegate = self
outputtable.dataSource = self
}
override func viewDidAppear() {
super.viewDidAppear()
getoutputDelegate = SharedReference.shared.getvcref(viewcontroller: .vctabmain) as? ViewControllerMain
globalMainQueue.async { () in
self.outputtable.reloadData()
}
}
override func viewDidDisappear() {
super.viewDidDisappear()
SharedReference.shared.setvcref(viewcontroller: .vcalloutput, nsviewcontroller: nil)
}
@IBAction func pastetabeltomacospasteboard(_: NSButton) {
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
for i in 0 ..< (getoutputDelegate?.getalloutput().count ?? 0) {
pasteboard.writeObjects([(getoutputDelegate?.getalloutput()[i])! as NSPasteboardWriting])
}
}
@IBAction func newcleanlogfile(_: NSButton) {
outputrsyncorlofile.stringValue = "Logfile..."
rsyncorlog.state = .off
logging = Logfile(true)
getoutputDelegate = logging
globalMainQueue.async { () in
self.outputtable.reloadData()
}
}
@IBAction func closeview(_: NSButton) {
view.window?.close()
}
}
extension ViewControllerAllOutput: NSTableViewDataSource {
func numberOfRows(in _: NSTableView) -> Int {
return getoutputDelegate?.getalloutput().count ?? 0
}
}
extension ViewControllerAllOutput: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? {
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "outputID"), owner: nil) as? NSTableCellView {
guard row < getoutputDelegate?.getalloutput().count ?? 0 else { return nil }
cell.textField?.stringValue = getoutputDelegate?.getalloutput()[row] ?? ""
return cell
} else {
return nil
}
}
}
extension ViewControllerAllOutput: Reloadandrefresh {
func reloadtabledata() {
if rsyncorlog.state == .on {
getoutputDelegate = SharedReference.shared.getvcref(viewcontroller: .vctabmain) as? ViewControllerMain
globalMainQueue.async { () in
self.outputtable.reloadData()
}
} else {
logging = Logfile(false)
getoutputDelegate = logging
globalMainQueue.async { () in
self.outputtable.reloadData()
}
}
}
}