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 pathViewControllerProgressProcess.swift
97 lines (86 loc) · 3.29 KB
/
ViewControllerProgressProcess.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
//
// ViewControllerProgressProcess.swift
// RsyncOSXver30
//
// Created by Thomas Evensen on 24/08/2016.
// Copyright © 2016 Thomas Evensen. All rights reserved.
//
import Cocoa
// Protocol for progress indicator
protocol Count: AnyObject {
func maxCount() -> Int
func inprogressCount() -> Int
}
class ViewControllerProgressProcess: NSViewController, SetConfigurations, SetDismisser, Abort {
var count: Double = 0
var maxcount: Double = 0
weak var countDelegate: Count?
@IBOutlet var abort: NSButton!
@IBOutlet var progress: NSProgressIndicator!
@IBAction func abort(_: NSButton) {
switch countDelegate {
case is ViewControllerSnapshots:
dismissview(viewcontroller: self, vcontroller: .vcsnapshot)
case is ViewControllerRestore:
dismissview(viewcontroller: self, vcontroller: .vcrestore)
default:
dismissview(viewcontroller: self, vcontroller: .vctabmain)
}
abort()
}
override func viewDidAppear() {
super.viewDidAppear()
SharedReference.shared.setvcref(viewcontroller: .vcprogressview, nsviewcontroller: self)
if (presentingViewController as? ViewControllerMain) != nil {
if let pvc = (presentingViewController as? ViewControllerMain)?.singletask {
countDelegate = pvc
}
} else if (presentingViewController as? ViewControllerRestore) != nil {
countDelegate = SharedReference.shared.getvcref(viewcontroller: .vcrestore) as? ViewControllerRestore
} else if (presentingViewController as? ViewControllerSnapshots) != nil {
countDelegate = SharedReference.shared.getvcref(viewcontroller: .vcsnapshot) as? ViewControllerSnapshots
}
initiateProgressbar()
abort.isEnabled = true
}
override func viewWillDisappear() {
super.viewWillDisappear()
stopProgressbar()
SharedReference.shared.setvcref(viewcontroller: .vcprogressview, nsviewcontroller: nil)
}
private func stopProgressbar() {
progress.stopAnimation(self)
}
// Progress bars
private func initiateProgressbar() {
if (presentingViewController as? ViewControllerSnapshots) != nil {
progress.maxValue = Double(countDelegate?.maxCount() ?? 0)
} else {
progress.maxValue = Double((countDelegate?.maxCount() ?? 0) + SharedReference.shared.extralines)
}
progress.minValue = 0
progress.doubleValue = 0
progress.startAnimation(self)
}
private func updateProgressbar(_ value: Double) {
progress.doubleValue = value
}
}
extension ViewControllerProgressProcess: UpdateProgress {
func processTermination() {
stopProgressbar()
switch countDelegate {
case is ViewControllerMain:
dismissview(viewcontroller: self, vcontroller: .vctabmain)
case is ViewControllerSnapshots:
dismissview(viewcontroller: self, vcontroller: .vcsnapshot)
case is ViewControllerRestore:
dismissview(viewcontroller: self, vcontroller: .vcrestore)
default:
dismissview(viewcontroller: self, vcontroller: .vctabmain)
}
}
func fileHandler() {
updateProgressbar(Double(countDelegate?.inprogressCount() ?? 0))
}
}