blob: 6417284daeca77af9c6864638c71abbd7d04ecfc (
plain) (
blame)
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
|
package design.controller.userinput;
import design.model.undo.UndoManager;
import design.persistence.PersonalDatabase;
import design.runtime.Session;
import java.io.IOException;
public final class UndoActions {
private UndoActions() {
}
public static void undoWithSave() {
UndoManager um = UndoManager.instance();
if (!um.canUndo()) {
System.out.println("Nothing to undo.");
return;
}
String label = um.peekUndoLabel();
um.undo();
System.out.println("Undo: " + label);
saveCurrentGolfer();
}
public static void redoWithSave() {
UndoManager um = UndoManager.instance();
if (!um.canRedo()) {
System.out.println("Nothing to redo.");
return;
}
String label = um.peekRedoLabel();
um.redo();
System.out.println("Redo: " + label);
saveCurrentGolfer();
}
private static void saveCurrentGolfer() {
try {
var g = Session.getCurrentGolfer();
if (g != null) {
PersonalDatabase.instance().updateGolfer(g);
}
} catch (IOException e) {
System.err.println("Failed to save after undo/redo: " + e.getMessage());
}
}
}
|