Skip to content

Commit e9c6b59

Browse files
committed
Ported redesigned Snapshot panel from VirtualC64
1 parent 04acf8e commit e9c6b59

File tree

14 files changed

+255
-197
lines changed

14 files changed

+255
-197
lines changed

Emulator/Misc/RetroShell/DebugConsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ DebugConsole::initCommands(Command &root)
11951195
});
11961196
}
11971197

1198-
root.add({"?"}, { Arg::value },
1198+
root.add({"%"}, { Arg::value },
11991199
"Convert a value into different formats",
12001200
[this](Arguments& argv, long value) {
12011201

File renamed without changes.

GUI/Dialogs/SnapshotDialog.swift renamed to GUI/Dialogs/Captures/SnapshotDialog.swift

Lines changed: 51 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ class SnapshotDialog: DialogController {
1414
@IBOutlet weak var carousel: iCarousel!
1515
@IBOutlet weak var moveUp: NSButton!
1616
@IBOutlet weak var moveDown: NSButton!
17-
@IBOutlet weak var restore: NSButton!
17+
@IBOutlet weak var trash: NSButton!
1818
@IBOutlet weak var nr: NSTextField!
1919
@IBOutlet weak var text1: NSTextField!
2020
@IBOutlet weak var text2: NSTextField!
21+
@IBOutlet weak var text3: NSTextField!
22+
@IBOutlet weak var message: NSTextField!
2123
@IBOutlet weak var indicator: NSLevelIndicator!
2224
@IBOutlet weak var indicatorText: NSTextField!
23-
@IBOutlet weak var indicatorPercentage: NSTextField!
24-
25+
@IBOutlet weak var revert: NSButton!
26+
2527
// Computed variables
2628
var myDocument: MyDocument { return parent.mydocument! }
2729
var numItems: Int { return carousel.numberOfItems }
@@ -30,6 +32,9 @@ class SnapshotDialog: DialogController {
3032
var lastItem: Int { return numItems - 1 }
3133
var empty: Bool { return numItems == 0 }
3234

35+
// Remembers the auto-snapshot setting
36+
var takeSnapshots = false
37+
3338
override func windowWillLoad() {
3439

3540
}
@@ -40,51 +45,52 @@ class SnapshotDialog: DialogController {
4045

4146
now = Date()
4247

48+
// Don't let the emulator take snapshots while the dialog is open
49+
takeSnapshots = emu?.get(.AMIGA_SNAPSHOTS) != 0
50+
emu?.set(.AMIGA_SNAPSHOTS, enable: false)
51+
4352
updateLabels()
44-
updateCapacity()
4553

4654
self.carousel.type = iCarouselType.timeMachine
4755
self.carousel.isHidden = false
48-
self.updateCarousel(goto: Int.max, animated: false)
56+
self.updateCarousel(goto: myDocument.snapshots.count - 1, animated: false)
4957
}
5058

5159
func updateLabels() {
5260

5361
moveUp.isEnabled = currentItem >= 0 && currentItem < lastItem
5462
moveDown.isEnabled = currentItem > 0
55-
nr.stringValue = "\(currentItem + 1) / \(numItems)"
56-
57-
moveUp.isHidden = empty
58-
moveDown.isHidden = empty
59-
nr.isHidden = empty
60-
restore.isHidden = empty
61-
63+
nr.stringValue = "Snapshot \(currentItem + 1) / \(numItems)"
64+
6265
if let snapshot = myDocument.snapshots.element(at: currentItem) {
6366
let takenAt = snapshot.timeStamp
64-
text1.stringValue = "Taken at " + timeInfo(time: takenAt)
65-
text2.stringValue = timeDiffInfo(time: takenAt)
67+
let compressed = "" // snapshot.compressed ? "(Compressed)" : ""
68+
text1.stringValue = "\(snapshot.size / 1024) KB " + compressed
69+
text2.stringValue = "Taken at " + timeInfo(time: takenAt)
70+
text3.stringValue = Date.elapsed(time: takenAt)
71+
message.stringValue = ""
6672
} else {
67-
text1.stringValue = "No snapshots available"
68-
text2.stringValue = ""
73+
nr.stringValue = "No snapshots taken"
74+
message.stringValue = ""
6975
}
70-
text1.isHidden = false
71-
text2.isHidden = false
72-
}
73-
74-
func updateCapacity() {
7576

7677
let MB = 1024 * 1024
77-
let fill = Int(myDocument.snapshots.fill.rounded())
78+
let fill = myDocument.snapshots.fill
7879
let size = myDocument.snapshots.used / MB
7980
let max = myDocument.snapshots.maxSize / MB
81+
indicator.doubleValue = fill
82+
indicatorText.stringValue = "\(size) MB / \(max) MB"
8083

81-
indicator.integerValue = fill
82-
indicatorText.stringValue = "\(size) MB out of \(max) MB used"
83-
indicatorText.isHidden = false
84-
indicatorPercentage.stringValue = "\(fill)%"
85-
indicatorPercentage.isHidden = false
84+
text1.isHidden = empty
85+
text2.isHidden = empty
86+
text3.isHidden = empty
87+
moveUp.isHidden = empty
88+
moveDown.isHidden = empty
89+
nr.isHidden = false
90+
trash.isHidden = empty
91+
revert.isHidden = empty
8692
}
87-
93+
8894
func updateCarousel(goto item: Int, animated: Bool) {
8995

9096
carousel.reloadData()
@@ -107,7 +113,7 @@ class SnapshotDialog: DialogController {
107113

108114
let formatter = DateFormatter()
109115
formatter.timeZone = TimeZone.current
110-
formatter.dateFormat = "HH:mm:ss" // "yyyy-MM-dd HH:mm"
116+
formatter.dateFormat = "HH:mm:ss"
111117

112118
return formatter.string(from: date)
113119
}
@@ -117,70 +123,6 @@ class SnapshotDialog: DialogController {
117123
return timeInfo(date: Date(timeIntervalSince1970: TimeInterval(time)))
118124
}
119125

120-
func timeDiffInfo(seconds: Int) -> String {
121-
122-
let secPerMin = 60
123-
let secPerHour = secPerMin * 60
124-
let secPerDay = secPerHour * 24
125-
let secPerWeek = secPerDay * 7
126-
let secPerMonth = secPerWeek * 4
127-
let secPerYear = secPerWeek * 52
128-
129-
if seconds == 0 {
130-
return "Now"
131-
}
132-
if seconds < secPerMin {
133-
return "\(seconds) second" + (seconds == 1 ? "" : "s") + " ago"
134-
}
135-
if seconds < secPerHour {
136-
let m = seconds / secPerMin
137-
return "\(m) minute" + (m == 1 ? "" : "s") + " ago"
138-
}
139-
if seconds < secPerDay {
140-
let h = seconds / secPerHour
141-
return "\(h) hour" + (h == 1 ? "" : "s") + " ago"
142-
}
143-
if seconds < secPerWeek {
144-
let d = seconds / secPerDay
145-
return "\(d) day" + (d == 1 ? "" : "s") + " ago"
146-
}
147-
if seconds < secPerMonth {
148-
let w = seconds / secPerWeek
149-
return "\(w) week" + (w == 1 ? "" : "s") + " ago"
150-
}
151-
if seconds < secPerYear {
152-
let m = seconds / secPerMonth
153-
return "\(m) month" + (m == 1 ? "" : "s") + " ago"
154-
} else {
155-
let y = seconds / secPerYear
156-
return "\(y) year" + (y == 1 ? "" : "s") + " ago"
157-
}
158-
}
159-
160-
func timeDiffInfo(interval: TimeInterval?) -> String {
161-
162-
return interval == nil ? "" : timeDiffInfo(seconds: Int(interval!))
163-
}
164-
165-
func timeDiffInfo(date: Date?) -> String {
166-
167-
guard let date else {
168-
return ""
169-
}
170-
return timeDiffInfo(interval: -date.timeIntervalSince(now))
171-
}
172-
173-
func timeDiffInfo(time: time_t) -> String {
174-
175-
let date = Date(timeIntervalSince1970: TimeInterval(time))
176-
return timeDiffInfo(date: date)
177-
}
178-
179-
func timeDiffInfo(url: URL) -> String {
180-
181-
return timeDiffInfo(date: url.modificationDate)
182-
}
183-
184126
@IBAction func selectorAction(_ sender: NSSegmentedControl!) {
185127

186128
updateCarousel(goto: Int.max, animated: false)
@@ -200,6 +142,12 @@ class SnapshotDialog: DialogController {
200142
}
201143
}
202144

145+
@IBAction func trashAction(_ sender: NSButton!) {
146+
147+
myDocument.snapshots.remove(at: currentItem)
148+
updateCarousel()
149+
}
150+
203151
@IBAction func revertAction(_ sender: NSButton!) {
204152

205153
do {
@@ -211,21 +159,26 @@ class SnapshotDialog: DialogController {
211159
}
212160

213161
@IBAction override func cancelAction(_ sender: Any!) {
214-
162+
163+
hide()
164+
165+
emu?.set(.AMIGA_SNAPSHOTS, enable: takeSnapshots)
166+
167+
// Hide some controls
215168
let items: [NSView] = [
216169

217170
nr,
218171
moveUp,
219172
moveDown,
220-
restore,
173+
trash,
221174
text1,
222175
text2,
176+
text3,
223177
carousel
224178
]
225-
226-
hide()
179+
227180
for item in items { item.isHidden = true }
228-
}
181+
}
229182
}
230183

231184
//
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)