Skip to content

Commit

Permalink
Minor fix for Undo command
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathanael Seen committed Mar 19, 2020
1 parent 4af197b commit d53b489
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
16 changes: 8 additions & 8 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<!--
This configuration file enforces rules for a modified version of the module's code standard at
Expand Down Expand Up @@ -55,11 +55,11 @@
4. THIRD_PARTY_PACKAGE: defined as com imports
-->
<module name="CustomImportOrder">
<property name="customImportOrderRules"
value="STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE"/>
<property name="specialImportsRegExp" value="^org\."/>
<property name="thirdPartyPackageRegExp" value="^com\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="customImportOrderRules"
value="STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE"/>
<property name="specialImportsRegExp" value="^org\."/>
<property name="thirdPartyPackageRegExp" value="^com\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
</module>

<!-- Checks for redundant import statements.
Expand Down Expand Up @@ -220,7 +220,7 @@
some other variants which we don't publicized to promote consistency).
-->
<property name="reliefPattern"
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
</module>

<module name="MissingSwitchDefault"/>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/igrad/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public CommandResult execute(String commandText) throws CommandException,
CommandResult commandResult;
Command command = courseBookParser.parseCommand(commandText);

if (command.getClass() != UndoCommand.class) {
if (!(command instanceof UndoCommand)) {
try {
// First, load current state into backup
storage.saveBackupCourseBook(model.getCourseBook());
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/igrad/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class UndoCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Undoes latest action.\n"
+ "Example: " + COMMAND_WORD;

public static final String SHOWING_UNDO_MESSAGE = "Undid last command.";
public static final String UNDO_ERROR_MESSAGE = "Unable to undo the last comamand.";
public static final String MESSAGE_SUCCESS = "Undid last command.";
public static final String MESSAGE_ERROR = "Unable to undo the last comamand.";

@Override
public CommandResult execute(Model model) throws CommandException {
Expand All @@ -35,13 +35,13 @@ public CommandResult execute(Model model) throws CommandException {
if (backupCourseBook.isPresent()) {
model.setCourseBook(backupCourseBook.get());
} else {
throw new CommandException(UNDO_ERROR_MESSAGE);
throw new CommandException(MESSAGE_ERROR);
}

} catch (DataConversionException e) {
throw new CommandException(UNDO_ERROR_MESSAGE);
throw new CommandException(MESSAGE_ERROR);
}

return new CommandResult(SHOWING_UNDO_MESSAGE, false, false, false);
return new CommandResult(MESSAGE_SUCCESS, false, false, false);
}
}
8 changes: 8 additions & 0 deletions src/main/java/igrad/model/UserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void resetData(ReadOnlyUserPrefs newUserPrefs) {
requireNonNull(newUserPrefs);
setGuiSettings(newUserPrefs.getGuiSettings());
setCourseBookFilePath(newUserPrefs.getCourseBookFilePath());
setBackupCourseBookFilePath(newUserPrefs.getBackupCourseBookFilePath());
setAvatar(newUserPrefs.getAvatar());
}

Expand All @@ -66,6 +67,11 @@ public void setCourseBookFilePath(Path courseBookFilePath) {
this.courseBookFilePath = courseBookFilePath;
}

public void setBackupCourseBookFilePath(Path backupCourseBookFilePath) {
requireNonNull(backupCourseBookFilePath);
this.backupCourseBookFilePath = backupCourseBookFilePath;
}

public Avatar getAvatar() {
return avatar;
}
Expand All @@ -88,6 +94,7 @@ public boolean equals(Object other) {

return guiSettings.equals(o.guiSettings)
&& courseBookFilePath.equals(o.courseBookFilePath)
&& backupCourseBookFilePath.equals(o.backupCourseBookFilePath)
&& avatar.equals(o.avatar);
}

Expand All @@ -101,6 +108,7 @@ public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Gui Settings : " + guiSettings);
sb.append("\nLocal data file location : " + courseBookFilePath);
sb.append("\nBackup Local data file location : " + backupCourseBookFilePath);
sb.append("\nAvatar : " + avatar);
return sb.toString();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/igrad/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static Path getSampleCourseBookFilePath() {
return Paths.get("data", "coursebook.json");
}

public static Path getSampleBackupCourseBookFilePath() {
return Paths.get("data", "backup_coursebook.json");
}

public static ReadOnlyCourseBook getSampleCourseBook() {
CourseBook sampleCourseBook = new CourseBook();
for (Module sampleModule : getSamplePersons()) {
Expand All @@ -71,6 +75,7 @@ public static UserPrefs getSampleUserPrefs() {

sampleUserPrefs.setGuiSettings(new GuiSettings());
sampleUserPrefs.setCourseBookFilePath(getSampleCourseBookFilePath());
sampleUserPrefs.setBackupCourseBookFilePath(getSampleBackupCourseBookFilePath());
sampleUserPrefs.setAvatar(getSampleAvatar());

return sampleUserPrefs;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.stage.Stage?>

<fx:root minHeight="870.0" minWidth="800.0" onCloseRequest="#handleExit" title="iGrad" type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<fx:root minHeight="800.0" minWidth="800.0" onCloseRequest="#handleExit" title="iGrad" type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<icons>
<Image url="@/images/iGrad_Shibu.png" />
</icons>
Expand Down

0 comments on commit d53b489

Please sign in to comment.