diff --git a/src/main/java/seedu/address/logic/CommandLog.java b/src/main/java/seedu/address/logic/CommandLog.java index adad4869faf..d9f7afbb0ba 100644 --- a/src/main/java/seedu/address/logic/CommandLog.java +++ b/src/main/java/seedu/address/logic/CommandLog.java @@ -5,20 +5,40 @@ import seedu.address.logic.commands.Command; /** - * Keeps track of Commands given by user + * Keeps track of Commands given by user using a stack */ public class CommandLog { private Stack log = new Stack<>(); + private Stack inputLog = new Stack<>(); + /** + * Adds a command to the stack + */ public void add(Command command) { log.push(command); } - public Command undo() { + /** + * Pops most recent command at the top of the stack + * @return null if stack is empty + */ + public Command getPreviousCommand() { return log.isEmpty() ? null : log.pop(); } - public boolean hasLog() { - return !log.isEmpty(); + /** + * Adds a user input to the stack + */ + public void addinput(String input) { + inputLog.push(input); } + + /** + * Returns most recent user input at the top of the stack + * @return empty string if stack is empty + */ + public String getPreviousInput() { + return inputLog.isEmpty() ? "" : inputLog.pop(); + } + } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index bb01951a735..59cc5ad3548 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -50,6 +50,11 @@ public CommandResult execute(String commandText) throws CommandException, ParseE CommandResult commandResult; Command command = addressBookParser.parseCommand(commandText); commandResult = command.execute(model); + if (command.canBeUndone()) { + model.addInputToLog(commandText); + model.addCommandToLog(command); + } + if (commandResult.isLoad()) { try { Optional loadedAddressBookOpt = storage.loadAddressBookManually(); diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 75c0818a551..4abac2a25a6 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -46,6 +46,7 @@ public class AddCommand extends Command { public static final String MESSAGE_SUCCESS = "New person added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; + private static final boolean IS_UNDOABLE = true; private final Person toAdd; private Predicate previousPredicate; @@ -68,7 +69,6 @@ public CommandResult execute(Model model) throws CommandException { previousPredicate = model.getCurrentPredicate(); model.addPerson(toAdd); - model.addCommandToLog(this); return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd))); } @@ -82,6 +82,11 @@ public void undo(Model model) { model.updateFilteredPersonList(previousPredicate); } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/commands/AddGameCommand.java b/src/main/java/seedu/address/logic/commands/AddGameCommand.java index 3e44ac59ddf..5362e44ba03 100644 --- a/src/main/java/seedu/address/logic/commands/AddGameCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddGameCommand.java @@ -44,6 +44,7 @@ public class AddGameCommand extends Command { public static final String MESSAGE_ADD_GAME_SUCCESS = "Added Game to Person: %1$s"; public static final String MESSAGE_GAME_EXISTS = "The game provided already exists for that person."; + private static final boolean IS_UNDOABLE = true; private final Index index; private final GameDescriptor addGameDescriptor; @@ -90,7 +91,6 @@ public CommandResult execute(Model model) throws CommandException { } gameMap.put(gameName, editedGame); model.setPerson(personToEdit, personToEdit); - model.addCommandToLog(this); return new CommandResult(String.format(MESSAGE_ADD_GAME_SUCCESS, Messages.format(editedGame))); } @@ -104,6 +104,11 @@ public void undo(Model model) { model.setPerson(personToEdit, personToEdit); } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } + /** * Creates and returns a {@code Game} with the details of {@code addGameDescriptor} */ diff --git a/src/main/java/seedu/address/logic/commands/ClearCommand.java b/src/main/java/seedu/address/logic/commands/ClearCommand.java index b4aea30098b..0302f3cf8df 100644 --- a/src/main/java/seedu/address/logic/commands/ClearCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClearCommand.java @@ -13,6 +13,7 @@ public class ClearCommand extends Command { public static final String COMMAND_WORD = "clear"; public static final String MESSAGE_SUCCESS = "Address book has been cleared!"; + private static final boolean IS_UNDOABLE = true; private ReadOnlyAddressBook previousAddressBook; @@ -22,7 +23,6 @@ public CommandResult execute(Model model) { requireNonNull(model); previousAddressBook = new AddressBook(model.getAddressBook()); model.setAddressBook(new AddressBook()); - model.addCommandToLog(this); return new CommandResult(MESSAGE_SUCCESS); } @@ -30,4 +30,9 @@ public CommandResult execute(Model model) { public void undo(Model model) { model.setAddressBook(previousAddressBook); } + + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } } diff --git a/src/main/java/seedu/address/logic/commands/Command.java b/src/main/java/seedu/address/logic/commands/Command.java index 529f93dabbc..3b89b0df340 100644 --- a/src/main/java/seedu/address/logic/commands/Command.java +++ b/src/main/java/seedu/address/logic/commands/Command.java @@ -22,4 +22,8 @@ public abstract class Command { */ public abstract void undo(Model model); + /** + * Returns whether the command can be undone. + */ + public abstract boolean canBeUndone(); } diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index ecc2bffe85a..d0efb3ebbb4 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -24,6 +24,7 @@ public class DeleteCommand extends Command { + "Example: " + COMMAND_WORD + " 1"; public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; + private static final boolean IS_UNDOABLE = true; private final Index targetIndex; @@ -48,7 +49,6 @@ public CommandResult execute(Model model) throws CommandException { model.getAddressBookIndex(targetIndex.getZeroBased())); model.deletePerson(personToDelete); deletedPerson = personToDelete; - model.addCommandToLog(this); return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete))); } @@ -60,6 +60,11 @@ public void undo(Model model) { model.insertPerson(deletedPerson, deletedPersonIndex.getZeroBased()); } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/commands/DeleteGameCommand.java b/src/main/java/seedu/address/logic/commands/DeleteGameCommand.java index a7c71b3169d..22b048bf51f 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteGameCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteGameCommand.java @@ -31,6 +31,7 @@ public class DeleteGameCommand extends Command { public static final String MESSAGE_DELETE_GAME_SUCCESS = "Deleted Game from Person: %1$s"; public static final String MESSAGE_NOT_DELETED = "The game provided does not exist for that person."; + private static final boolean IS_UNDOABLE = true; private final Index index; private final String gameName; @@ -69,7 +70,6 @@ public CommandResult execute(Model model) throws CommandException { deletedGame = gameMap.remove(gameName); model.setPerson(personToEdit, personToEdit); - model.addCommandToLog(this); return new CommandResult(String.format(MESSAGE_DELETE_GAME_SUCCESS, Messages.format(deletedGame))); } @@ -83,6 +83,10 @@ public void undo(Model model) { model.setPerson(personToEdit, personToEdit); } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } @Override public boolean equals(Object other) { diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index b31e6fcb1ed..f8546675e13 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -8,7 +8,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_PREFERREDTIME; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.util.Collections; import java.util.HashMap; @@ -59,6 +58,7 @@ public class EditCommand extends Command { public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; + private static final boolean IS_UNDOABLE = true; private final Index index; private final EditPersonDescriptor editPersonDescriptor; @@ -94,8 +94,6 @@ public CommandResult execute(Model model) throws CommandException { } model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - model.addCommandToLog(this); return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); } @@ -104,7 +102,11 @@ public void undo(Model model) { requireNonNull(model); model.setPerson(editedPerson, personToEdit); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + } + + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; } /** diff --git a/src/main/java/seedu/address/logic/commands/EditGameCommand.java b/src/main/java/seedu/address/logic/commands/EditGameCommand.java index c6de5e9f636..c1e531e7ad5 100644 --- a/src/main/java/seedu/address/logic/commands/EditGameCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditGameCommand.java @@ -44,6 +44,7 @@ public class EditGameCommand extends Command { public static final String MESSAGE_EDIT_GAME_SUCCESS = "Edited Game: %1$s"; public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; + private static final boolean IS_UNDOABLE = true; private final Index index; private final String gameName; @@ -86,7 +87,6 @@ public CommandResult execute(Model model) throws CommandException { Game editedGame = createEditedGame(gameToEdit, editGameDescriptor); gameMap.put(gameName, editedGame); model.setPerson(personToEdit, personToEdit); - model.addCommandToLog(this); return new CommandResult(String.format(MESSAGE_EDIT_GAME_SUCCESS, Messages.format(editedGame))); } @@ -98,6 +98,11 @@ public void undo(Model model) { model.setPerson(personToEdit, personToEdit); } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } + /** * Creates and returns a {@code Game} with the details of {@code gameToEdit} * edited with {@code editGameDescriptor}. diff --git a/src/main/java/seedu/address/logic/commands/ExitCommand.java b/src/main/java/seedu/address/logic/commands/ExitCommand.java index 981bf332e21..cc353e09bf7 100644 --- a/src/main/java/seedu/address/logic/commands/ExitCommand.java +++ b/src/main/java/seedu/address/logic/commands/ExitCommand.java @@ -10,6 +10,7 @@ public class ExitCommand extends Command { public static final String COMMAND_WORD = "exit"; public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ..."; + private static final boolean IS_UNDOABLE = false; @Override public CommandResult execute(Model model) { @@ -21,4 +22,8 @@ public void undo(Model model) { } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } } diff --git a/src/main/java/seedu/address/logic/commands/FavouriteGameCommand.java b/src/main/java/seedu/address/logic/commands/FavouriteGameCommand.java index e440e9a21f5..a2eec17e942 100644 --- a/src/main/java/seedu/address/logic/commands/FavouriteGameCommand.java +++ b/src/main/java/seedu/address/logic/commands/FavouriteGameCommand.java @@ -30,6 +30,7 @@ public class FavouriteGameCommand extends Command { public static final String MESSAGE_FAVOURITE_GAME_SUCCESS = "Favourited Game: %1$s"; public static final String MESSAGE_GAME_NOT_SPECIFIED = "Please specify a game!"; public static final String MESSAGE_GAME_NOT_FOUND = "Game not found!"; + private static final boolean IS_UNDOABLE = true; private Index index; private String gameName; @@ -66,7 +67,6 @@ public CommandResult execute(Model model) throws CommandException { prevGameIsFavourite = targetGame.getFavouriteStatus(); targetGame.setAsFavourite(); model.setPerson(targetPerson, targetPerson); - model.addCommandToLog(this); return new CommandResult(String.format(MESSAGE_FAVOURITE_GAME_SUCCESS, gameName)); } @@ -90,6 +90,11 @@ public void undo(Model model) { model.setPerson(targetPerson, targetPerson); } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/commands/FindCommand.java b/src/main/java/seedu/address/logic/commands/FindCommand.java index ec185ec6f9f..7acba5e4456 100644 --- a/src/main/java/seedu/address/logic/commands/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindCommand.java @@ -22,6 +22,7 @@ public class FindCommand extends Command { + "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" + "Example: " + COMMAND_WORD + " alice bob charlie"; + private static final boolean IS_UNDOABLE = true; private final NameContainsKeywordsPredicate predicate; private Predicate previousPredicate; @@ -35,7 +36,6 @@ public CommandResult execute(Model model) { requireNonNull(model); previousPredicate = model.getCurrentPredicate(); model.updateFilteredPersonList(predicate); - model.addCommandToLog(this); return new CommandResult( String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); } @@ -46,6 +46,11 @@ public void undo(Model model) { model.updateFilteredPersonList(previousPredicate); } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/commands/FindTimeCommand.java b/src/main/java/seedu/address/logic/commands/FindTimeCommand.java index b58528bf72c..899628cfe17 100644 --- a/src/main/java/seedu/address/logic/commands/FindTimeCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindTimeCommand.java @@ -24,6 +24,7 @@ public class FindTimeCommand extends Command { + "Tips: RANGE has format HHmm, same ending time as starting time is allowed.\n" + "Parameters: RANGE [MORE_RANGES]...\n" + "Example: " + COMMAND_WORD + " 1100-1230 2130-2245"; + private static final boolean IS_UNDOABLE = true; private final PreferredTimeOverlapsRangesPredicate predicate; private Predicate previousPredicate; @@ -37,7 +38,6 @@ public CommandResult execute(Model model) { requireNonNull(model); previousPredicate = model.getCurrentPredicate(); model.updateFilteredPersonList(predicate); - model.addCommandToLog(this); return new CommandResult( String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); } @@ -48,6 +48,11 @@ public void undo(Model model) { model.updateFilteredPersonList(previousPredicate); } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/commands/HelpCommand.java b/src/main/java/seedu/address/logic/commands/HelpCommand.java index 139f70dba28..18c7743a4e2 100644 --- a/src/main/java/seedu/address/logic/commands/HelpCommand.java +++ b/src/main/java/seedu/address/logic/commands/HelpCommand.java @@ -13,6 +13,7 @@ public class HelpCommand extends Command { + "Example: " + COMMAND_WORD; public static final String SHOWING_HELP_MESSAGE = "Opened help window."; + private static final boolean IS_UNDOABLE = false; @Override public CommandResult execute(Model model) { @@ -23,4 +24,9 @@ public CommandResult execute(Model model) { public void undo(Model model) { } + + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } } diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index be8cdc5d591..a33ed6befab 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -16,6 +16,7 @@ public class ListCommand extends Command { public static final String COMMAND_WORD = "list"; public static final String MESSAGE_SUCCESS = "Listed all persons"; + private static final boolean IS_UNDOABLE = true; private Predicate previousPredicate; @@ -24,7 +25,6 @@ public CommandResult execute(Model model) { requireNonNull(model); previousPredicate = model.getCurrentPredicate(); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - model.addCommandToLog(this); return new CommandResult(MESSAGE_SUCCESS); } @@ -33,4 +33,9 @@ public void undo(Model model) { requireNonNull(model); model.updateFilteredPersonList(previousPredicate); } + + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } } diff --git a/src/main/java/seedu/address/logic/commands/LoadCommand.java b/src/main/java/seedu/address/logic/commands/LoadCommand.java index ed9d3a953f5..1da542e3ee2 100644 --- a/src/main/java/seedu/address/logic/commands/LoadCommand.java +++ b/src/main/java/seedu/address/logic/commands/LoadCommand.java @@ -8,6 +8,9 @@ public class LoadCommand extends Command { public static final String COMMAND_WORD = "load"; public static final String MESSAGE_SUCCESS = "The saved address book has been loaded!"; + private static final boolean IS_UNDOABLE = false; + + @Override public CommandResult execute(Model model) throws CommandException { return new CommandResult(MESSAGE_SUCCESS, false, false, false, true); } @@ -16,4 +19,9 @@ public CommandResult execute(Model model) throws CommandException { public void undo(Model model) { } + + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } } diff --git a/src/main/java/seedu/address/logic/commands/SaveCommand.java b/src/main/java/seedu/address/logic/commands/SaveCommand.java index 60febbe2698..a541c09cab6 100644 --- a/src/main/java/seedu/address/logic/commands/SaveCommand.java +++ b/src/main/java/seedu/address/logic/commands/SaveCommand.java @@ -9,6 +9,9 @@ public class SaveCommand extends Command { public static final String COMMAND_WORD = "save"; public static final String MESSAGE_SUCCESS = "Address book has been saved!"; + private static final boolean IS_UNDOABLE = false; + + @Override public CommandResult execute(Model model) throws CommandException { return new CommandResult(MESSAGE_SUCCESS, false, false, true, false); } @@ -17,4 +20,9 @@ public CommandResult execute(Model model) throws CommandException { public void undo(Model model) { } + + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } } diff --git a/src/main/java/seedu/address/logic/commands/UndoCommand.java b/src/main/java/seedu/address/logic/commands/UndoCommand.java index 8e326c47e34..ce445e03589 100644 --- a/src/main/java/seedu/address/logic/commands/UndoCommand.java +++ b/src/main/java/seedu/address/logic/commands/UndoCommand.java @@ -13,8 +13,10 @@ public class UndoCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Undoes previous user command.\n" + "Example: " + COMMAND_WORD; - public static final String MESSAGE_SUCCESS = "Undid previous command."; + //public static final String MESSAGE_SUCCESS = "Undid previous command."; + public static final String MESSAGE_SUCCESS = "Undid previous command: %1$s"; public static final String MESSAGE_INVALID_PREVIOUS_COMMAND = "No Command found to undo"; + private static final boolean IS_UNDOABLE = false; @Override public CommandResult execute(Model model) throws CommandException { @@ -23,11 +25,16 @@ public CommandResult execute(Model model) throws CommandException { throw new CommandException(MESSAGE_INVALID_PREVIOUS_COMMAND); } previousCommand.undo(model); - return new CommandResult(MESSAGE_SUCCESS); + return new CommandResult(String.format(MESSAGE_SUCCESS, model.getPreviousInput())); } @Override public void undo(Model model) { } + + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } } diff --git a/src/main/java/seedu/address/logic/commands/UnfavouriteGameCommand.java b/src/main/java/seedu/address/logic/commands/UnfavouriteGameCommand.java index f5baa5859c0..b02f3d8d0cf 100644 --- a/src/main/java/seedu/address/logic/commands/UnfavouriteGameCommand.java +++ b/src/main/java/seedu/address/logic/commands/UnfavouriteGameCommand.java @@ -31,6 +31,7 @@ public class UnfavouriteGameCommand extends Command { public static final String MESSAGE_UNFAVOURITE_GAME_SUCCESS = "Un-favourited Game: %1$s"; public static final String MESSAGE_GAME_NOT_SPECIFIED = "Please specify a game!"; public static final String MESSAGE_GAME_NOT_FOUND = "Game not found!"; + private static final boolean IS_UNDOABLE = true; private Index index; private String gameName; @@ -67,7 +68,6 @@ public CommandResult execute(Model model) throws CommandException { prevGameIsFavourite = targetGame.getFavouriteStatus(); targetGame.removeFavourite(); model.setPerson(targetPerson, targetPerson); - model.addCommandToLog(this); return new CommandResult(String.format(MESSAGE_UNFAVOURITE_GAME_SUCCESS, gameName)); } @@ -91,6 +91,11 @@ public void undo(Model model) { model.setPerson(targetPerson, targetPerson); } + @Override + public boolean canBeUndone() { + return IS_UNDOABLE; + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 66eea9a0ba2..4b362e97031 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -107,7 +107,18 @@ public interface Model { void addCommandToLog(Command command); /** - * Returns most recent {@code Command} in {@code CommandLog}. + * Returns and removes most recent {@code Command} in {@code CommandLog}. */ Command getPreviousCommand(); + + /** + * Adds the user input string to {@code CommandLog}. + */ + void addInputToLog(String input); + + /** + * Returns and removes most recent user input string in {@code CommandLog}. + * @return + */ + String getPreviousInput(); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index d65783c92ed..cf7ee155741 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -177,7 +177,16 @@ public void addCommandToLog(Command command) { @Override public Command getPreviousCommand() { - return commandLog.undo(); + return commandLog.getPreviousCommand(); } + @Override + public void addInputToLog(String input) { + commandLog.addinput(input); + } + + @Override + public String getPreviousInput() { + return commandLog.getPreviousInput(); + } } diff --git a/src/main/java/seedu/address/ui/HelpWindow.java b/src/main/java/seedu/address/ui/HelpWindow.java index 8165596d46b..82bba826958 100644 --- a/src/main/java/seedu/address/ui/HelpWindow.java +++ b/src/main/java/seedu/address/ui/HelpWindow.java @@ -74,8 +74,6 @@ public String getDescription() { */ public HelpWindow(Stage root) { super(FXML, root); - - this.getRoot().setResizable(true); this.getRoot().setMinHeight(500); this.getRoot().setMinWidth(600); diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 8dd7722ab75..6227d15a01c 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -182,6 +182,16 @@ public void addCommandToLog(Command command) { public Command getPreviousCommand() { throw new AssertionError("This method should not be called."); } + + @Override + public void addInputToLog(String input) { + throw new AssertionError("This method should not be called."); + } + + @Override + public String getPreviousInput() { + throw new AssertionError("This method should not be called."); + } } /** @@ -234,6 +244,10 @@ public Predicate getCurrentPredicate() { public ReadOnlyAddressBook getAddressBook() { return new AddressBook(); } - } + @Override + public void addInputToLog(String input) { + + } + } } diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 82b1816bfc4..ca2f8a93426 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -108,6 +108,24 @@ public static void assertCommandSuccess(Command command, Model actualModel, Stri assertCommandSuccess(command, actualModel, expectedCommandResult, expectedModel); } + /** + * Executes the given {@code command} while unfiltering the {@code actualModel}, confirms that
+ * - the returned {@link CommandResult} matches {@code expectedMessage}
+ * - the {@code actualModel} matches {@code expectedModel} + */ + public static void assertCommandSuccessUnfilter(Command command, Model actualModel, String expectedMessage, + Model expectedModel) { + CommandResult expectedCommandResult = new CommandResult(expectedMessage); + try { + CommandResult result = command.execute(actualModel); + actualModel.updateFilteredPersonList(unused -> true); + assertEquals(expectedCommandResult, result); + assertEquals(expectedModel, actualModel); + } catch (CommandException ce) { + throw new AssertionError("Execution of command should not fail.", ce); + } + } + /** * Executes the given {@code command}, confirms that
* - a {@code CommandException} is thrown
diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 469dd97daa7..d2629ca2741 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -10,6 +10,7 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccessUnfilter; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; @@ -95,8 +96,7 @@ public void execute_filteredList_success() { Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson); - - assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); + assertCommandSuccessUnfilter(editCommand, model, expectedMessage, expectedModel); } @Test diff --git a/src/test/java/seedu/address/logic/commands/EditGameCommandTest.java b/src/test/java/seedu/address/logic/commands/EditGameCommandTest.java index 7a41d18ad10..14fd6b5e413 100644 --- a/src/test/java/seedu/address/logic/commands/EditGameCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditGameCommandTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccessUnfilter; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; @@ -112,8 +113,7 @@ public void execute_filteredList_success() { Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson); - showPersonAtIndex(expectedModel, INDEX_FIRST_PERSON); - assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); + assertCommandSuccessUnfilter(editCommand, model, expectedMessage, expectedModel); } @Test