Skip to content

Commit 7fe93d4

Browse files
committed
Adds save dirty checking event
This provides a cleaner UI experience. You are now only requested to save when an event dirties the save file. The deployer now also ensures that you have not dirtied the save.
1 parent 1b4e055 commit 7fe93d4

File tree

12 files changed

+64
-13
lines changed

12 files changed

+64
-13
lines changed

core/src/main/java/edu/wpi/grip/core/events/ConnectionAddedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* An event that occurs when a new connection is added to the pipeline. This is triggered by the user adding a
88
* connection with the GUI.
99
*/
10-
public class ConnectionAddedEvent {
10+
public class ConnectionAddedEvent implements DirtiesSaveEvent {
1111
private final Connection connection;
1212

1313
/**

core/src/main/java/edu/wpi/grip/core/events/ConnectionRemovedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* An event that occurs when a connection is removed from the pipeline. This is triggered by the user deleting a
88
* connection with the GUI.
99
*/
10-
public class ConnectionRemovedEvent {
10+
public class ConnectionRemovedEvent implements DirtiesSaveEvent {
1111
private final Connection connection;
1212

1313
/**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package edu.wpi.grip.core.events;
2+
3+
/**
4+
* An event that can potentially dirty the save file.
5+
* These events ensure that anything that changes causes the save file to be flagged as dirty and in need of being
6+
* saved for the project to be deemed "clean" again.
7+
*/
8+
public interface DirtiesSaveEvent {
9+
10+
/**
11+
* Some events may have more logic regarding whether they make the save dirty or not.
12+
*
13+
* @return True if this event should dirty the project save
14+
*/
15+
default boolean doesDirtySave() {
16+
return true;
17+
}
18+
}

core/src/main/java/edu/wpi/grip/core/events/SocketChangedEvent.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* An event that occurs when the value stored in a socket changes. This can happen, for example, as the result of an
88
* operation completing, or as a response to user input.
99
*/
10-
public class SocketChangedEvent {
10+
public class SocketChangedEvent implements DirtiesSaveEvent {
1111
private Socket socket;
1212

1313
/**
@@ -24,6 +24,18 @@ public Socket getSocket() {
2424
return this.socket;
2525
}
2626

27+
/**
28+
* This event will only dirty the save if the InputSocket does not have connections.
29+
* Thus the value can only have been changed by a UI component.
30+
* If the socket has connections then the value change is triggered by another socket's change.
31+
*
32+
* @return True if this should dirty the save.
33+
*/
34+
@Override
35+
public boolean doesDirtySave() {
36+
return socket.getDirection() == Socket.Direction.INPUT && socket.getConnections().isEmpty();
37+
}
38+
2739
@Override
2840
public String toString() {
2941
return MoreObjects.toStringHelper(this)

core/src/main/java/edu/wpi/grip/core/events/SocketPreviewChangedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* An event that occurs when a {@link OutputSocket} is set to be either previewed or not previewed. The GUI listens for these events
88
* so it knows which sockets to show previews for.
99
*/
10-
public class SocketPreviewChangedEvent {
10+
public class SocketPreviewChangedEvent implements DirtiesSaveEvent {
1111
private OutputSocket socket;
1212

1313
/**

core/src/main/java/edu/wpi/grip/core/events/SourceAddedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @see Source
1212
*/
13-
public class SourceAddedEvent {
13+
public class SourceAddedEvent implements DirtiesSaveEvent {
1414
private final Source source;
1515

1616
/**

core/src/main/java/edu/wpi/grip/core/events/SourceRemovedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @see Source
1212
*/
13-
public class SourceRemovedEvent {
13+
public class SourceRemovedEvent implements DirtiesSaveEvent {
1414
private final Source source;
1515

1616
/**

core/src/main/java/edu/wpi/grip/core/events/StepAddedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* An event that occurs when a new step is added to the pipeline. This is triggered by the user adding a step with the
1010
* GUI.
1111
*/
12-
public class StepAddedEvent {
12+
public class StepAddedEvent implements DirtiesSaveEvent {
1313
private final Step step;
1414
private final Optional<Integer> index;
1515

core/src/main/java/edu/wpi/grip/core/events/StepMovedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* An event that occurs when a new step is moved from one position to another in the pipeline
88
*/
9-
public class StepMovedEvent {
9+
public class StepMovedEvent implements DirtiesSaveEvent {
1010
private final Step step;
1111
private final int distance;
1212

core/src/main/java/edu/wpi/grip/core/events/StepRemovedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* An event that occurs when a new step is removed from the pipeline. This is triggered by the user deleting a step
88
* from the GUI.
99
*/
10-
public class StepRemovedEvent {
10+
public class StepRemovedEvent implements DirtiesSaveEvent {
1111
private final Step step;
1212

1313
/**

0 commit comments

Comments
 (0)