-
Notifications
You must be signed in to change notification settings - Fork 109
Adds save dirty checking event #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JLLeitschuh
merged 3 commits into
WPIRoboticsProjects:master
from
AustinShalit:feat/saveDirtyCheckEvent
Aug 1, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/src/main/java/edu/wpi/grip/core/events/DirtiesSaveEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package edu.wpi.grip.core.events; | ||
|
|
||
| /** | ||
| * An event that can potentially dirty the save file. | ||
| * | ||
| * <p>These events ensure that anything that changes causes the save file to be flagged as dirty and | ||
| * in need of being saved for the project to be deemed "clean" again. | ||
| */ | ||
| public interface DirtiesSaveEvent { | ||
|
|
||
| /** | ||
| * Some events may have more logic regarding whether they make the save dirty or not. | ||
| * | ||
| * @return True if this event should dirty the project save | ||
| */ | ||
| default boolean doesDirtySave() { | ||
| return true; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,10 @@ | |
|
|
||
| import edu.wpi.grip.core.Pipeline; | ||
| import edu.wpi.grip.core.PipelineRunner; | ||
| import edu.wpi.grip.core.events.DirtiesSaveEvent; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.eventbus.Subscribe; | ||
| import com.google.common.reflect.ClassPath; | ||
| import com.thoughtworks.xstream.XStream; | ||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
|
|
@@ -20,7 +22,6 @@ | |
| import java.io.Writer; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Optional; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.inject.Singleton; | ||
|
|
||
|
|
@@ -36,6 +37,7 @@ public class Project { | |
| @Inject | ||
| private PipelineRunner pipelineRunner; | ||
| private Optional<File> file = Optional.empty(); | ||
| private boolean saveIsDirty = false; | ||
|
|
||
| @Inject | ||
| public void initialize(StepConverter stepConverter, | ||
|
|
@@ -109,6 +111,7 @@ void open(Reader reader) { | |
| this.pipeline.clear(); | ||
| this.xstream.fromXML(reader); | ||
| pipelineRunner.startAsync(); | ||
| saveIsDirty = false; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -124,5 +127,19 @@ public void save(File file) throws IOException { | |
|
|
||
| public void save(Writer writer) { | ||
| this.xstream.toXML(this.pipeline, writer); | ||
| saveIsDirty = false; | ||
| } | ||
|
|
||
| public boolean isSaveDirty() { | ||
| return saveIsDirty; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this pattern but we can't do this using |
||
|
|
||
| @Subscribe | ||
| public void onDirtiesSaveEvent(DirtiesSaveEvent dirtySaveEvent) { | ||
| // Only update the flag the save isn't already dirty | ||
| // We don't need to be redundantly checking if the event dirties the save | ||
| if (!saveIsDirty && dirtySaveEvent.doesDirtySave()) { | ||
| saveIsDirty = true; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same code as the method below it.
Can you refactor it into one method that is called by both methods?
Or just have one of these methods call the other one.