Skip to content

Commit 2ab3774

Browse files
AustinShalitJLLeitschuh
authored andcommitted
Adds save dirty checking event (#647)
* Appends "Edited" to the stage title on edit
1 parent a317e4e commit 2ab3774

13 files changed

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

1616
/**

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

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

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

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

1616
/**
@@ -31,19 +31,26 @@ public boolean isRegarding(Socket socket) {
3131
return socket.equals(this.socket);
3232
}
3333

34+
/**
35+
* This event will only dirty the save if the InputSocket does not have connections.
36+
* Thus the value can only have been changed by a UI component.
37+
* If the socket has connections then the value change is triggered by another socket's change.
38+
*
39+
* @return True if this should dirty the save.
40+
*/
41+
@Override
42+
public boolean doesDirtySave() {
43+
return pipelineShouldRun();
44+
}
45+
3446
@Override
3547
public boolean pipelineShouldRun() {
3648
/*
3749
* The pipeline should only flag an update when it is an input changing. A changed output
38-
* doesn't mean
39-
* the pipeline is dirty.
40-
* If the socket is connected to another socket then then the input will only change
41-
* because of the
42-
* pipeline thread.
43-
* In that case we don't want the pipeline to be releasing itself.
44-
* If the connections are empty then the change must have come from the UI so we need to
45-
* run the pipeline
46-
* with the new values.
50+
* doesn't mean the pipeline is dirty. If the socket is connected to another socket then then
51+
* the input will only change because of the pipeline thread. In that case we don't want the
52+
* pipeline to be releasing itself. If the connections are empty then the change must have come
53+
* from the UI so we need to run the pipeline with the new values.
4754
*/
4855
return socket.getDirection().equals(Socket.Direction.INPUT) && socket.getConnections()
4956
.isEmpty();

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

1616
/**

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
@@ -13,7 +13,7 @@
1313
*
1414
* @see Source
1515
*/
16-
public class SourceAddedEvent {
16+
public class SourceAddedEvent implements DirtiesSaveEvent {
1717
private final Source source;
1818

1919
/**

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
@@ -13,7 +13,7 @@
1313
*
1414
* @see Source
1515
*/
16-
public class SourceRemovedEvent {
16+
public class SourceRemovedEvent implements DirtiesSaveEvent {
1717
private final Source source;
1818

1919
/**

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

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

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

1616
/**

0 commit comments

Comments
 (0)