Skip to content

Commit 2ccab9b

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 98d2a63 commit 2ccab9b

File tree

12 files changed

+62
-11
lines changed

12 files changed

+62
-11
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
@@ -9,7 +9,7 @@
99
* An event that occurs when a new connection is added to the pipeline. This is triggered by the user adding a
1010
* connection with the GUI.
1111
*/
12-
public class ConnectionAddedEvent implements RunPipelineEvent {
12+
public class ConnectionAddedEvent implements RunPipelineEvent, DirtiesSaveEvent {
1313
private final Connection connection;
1414

1515
/**

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
@@ -9,7 +9,7 @@
99
* An event that occurs when a connection is removed from the pipeline. This is triggered by the user deleting a
1010
* connection with the GUI.
1111
*/
12-
public class ConnectionRemovedEvent {
12+
public class ConnectionRemovedEvent implements DirtiesSaveEvent {
1313
private final Connection connection;
1414

1515
/**
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
@@ -9,7 +9,7 @@
99
* An event that occurs when the value stored in a socket changes. This can happen, for example, as the result of an
1010
* operation completing, or as a response to user input.
1111
*/
12-
public class SocketChangedEvent implements RunPipelineEvent {
12+
public class SocketChangedEvent implements RunPipelineEvent, DirtiesSaveEvent {
1313
private final Socket socket;
1414

1515
/**
@@ -27,6 +27,18 @@ public Socket getSocket() {
2727
return this.socket;
2828
}
2929

30+
/**
31+
* This event will only dirty the save if the InputSocket does not have connections.
32+
* Thus the value can only have been changed by a UI component.
33+
* If the socket has connections then the value change is triggered by another socket's change.
34+
*
35+
* @return True if this should dirty the save.
36+
*/
37+
@Override
38+
public boolean doesDirtySave() {
39+
return socket.getDirection() == Socket.Direction.INPUT && socket.getConnections().isEmpty();
40+
}
41+
3042
@Override
3143
public boolean pipelineShouldRun() {
3244
/*

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
@@ -9,7 +9,7 @@
99
* An event that occurs when a {@link OutputSocket} is set to be either previewed or not previewed. The GUI listens for these events
1010
* so it knows which sockets to show previews for.
1111
*/
12-
public class SocketPreviewChangedEvent {
12+
public class SocketPreviewChangedEvent implements DirtiesSaveEvent {
1313
private OutputSocket socket;
1414

1515
/**

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
@@ -12,7 +12,7 @@
1212
*
1313
* @see Source
1414
*/
15-
public class SourceAddedEvent {
15+
public class SourceAddedEvent implements DirtiesSaveEvent {
1616
private final Source source;
1717

1818
/**

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
@@ -12,7 +12,7 @@
1212
*
1313
* @see Source
1414
*/
15-
public class SourceRemovedEvent {
15+
public class SourceRemovedEvent implements DirtiesSaveEvent {
1616
private final Source source;
1717

1818
/**

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
@@ -13,7 +13,7 @@
1313
* An event that occurs when a new step is added to the pipeline. This is triggered by the user adding a step with the
1414
* GUI.
1515
*/
16-
public class StepAddedEvent {
16+
public class StepAddedEvent implements DirtiesSaveEvent {
1717
private final Step step;
1818
private final OptionalInt index;
1919

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
@@ -8,7 +8,7 @@
88
/**
99
* An event that occurs when a new step is moved from one position to another in the pipeline
1010
*/
11-
public class StepMovedEvent {
11+
public class StepMovedEvent implements DirtiesSaveEvent {
1212
private final Step step;
1313
private final int distance;
1414

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
@@ -9,7 +9,7 @@
99
* An event that occurs when a new step is removed from the pipeline. This is triggered by the user deleting a step
1010
* from the GUI.
1111
*/
12-
public class StepRemovedEvent {
12+
public class StepRemovedEvent implements DirtiesSaveEvent {
1313
private final Step step;
1414

1515
/**

0 commit comments

Comments
 (0)