Skip to content

Commit

Permalink
Established structure for undo and redo, missing inverse commands for…
Browse files Browse the repository at this point in the history
… each undoable operation
  • Loading branch information
tet54 committed Oct 24, 2016
1 parent 2641c57 commit 35217da
Show file tree
Hide file tree
Showing 19 changed files with 374 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>addressbook-level4</name>
<name>main</name>
<comment>Project addressbook-level4 created by Buildship.</comment>
<projects>
</projects>
Expand Down
72 changes: 70 additions & 2 deletions src/main/java/seedu/savvytasker/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,18 @@ public CommandResult execute(String commandText) {
command.setLogic(this);

CommandResult result = command.execute();
if (command.canUndo()) {

if (command.isUndo()){
if (!undo()) {
result = new CommandResult("Cannot Undo");
}
}
else if (command.isRedo()){
if (!redo()) {
result = new CommandResult("Cannot Redo");
}
}
else if (command.canUndo()){
undoStack.push(command);
redoStack.clear();
}
Expand Down Expand Up @@ -109,14 +120,71 @@ private boolean undo() {
}

return undone;

/*
undone = false;
if (!undoStack.isEmpty()) {
String commandText = undoStack.pop();
String commandType[] = commandText.split(" ");
if (commandType[0].equals("add")) {
String commandTextInverse = new String("delete " + model.getFilteredTaskList().size()); //TODO: can only undo after add at end of list
Command commandInverse = parser.parse(commandTextInverse);
commandInverse.setData(model);
CommandResult tempResult = commandInverse.execute();
}
else if (commandType[0].equals("delete")){
String commandTextInverse = new String("add" + " " + "temporary task"); //TODO: need to find details
Command commandInverse = parser.parse(commandTextInverse);
commandInverse.setData(model);
CommandResult tempResult = commandInverse.execute();
}
else if (commandType[0].equals("modify")){
String commandTextInverse = new String("modify" + " " + commandType[0]); //TODO: need to find original
Command commandInverse = parser.parse(commandTextInverse);
commandInverse.setData(model);
CommandResult tempResult = commandInverse.execute();
}
else if (commandType[0].equals("alias")){
String commandTextInverse = new String("unalias" + " " + commandType[2]);
Command commandInverse = parser.parse(commandTextInverse);
commandInverse.setData(model);
CommandResult tempResult = commandInverse.execute();
}
else if (commandType[0].equals("unalias")){
String commandTextInverse = new String("alias" + " " + commandType[0] + " " + commandType[1]); //TODO: need to find keyword
Command commandInverse = parser.parse(commandTextInverse);
commandInverse.setData(model);
CommandResult tempResult = commandInverse.execute();
}
else if (commandType[0].equals("mark")){
String commandTextInverse = new String("unmark" + " " + commandType[1]);
Command commandInverse = parser.parse(commandTextInverse);
commandInverse.setData(model);
CommandResult tempResult = commandInverse.execute();
}
else if (commandType[0].equals("unmark")){
String commandTextInverse = new String("mark" + " " + commandType[1]);
Command commandInverse = parser.parse(commandTextInverse);
commandInverse.setData(model);
CommandResult tempResult = commandInverse.execute();
}
//command.undo();
redoStack.push(commandText);
undone = true;
}
return undone;
*/
}

private boolean redo() {
boolean redone = false;

if (!redoStack.isEmpty()) {
Command command = redoStack.pop();
command.redo();
command.execute();
undoStack.push(command);
redone = true;
}
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/seedu/savvytasker/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,27 @@ public boolean redo() {
*/
@Override
public boolean undo() {
// TODO Auto-generated method stub

System.out.println("entered undo!! in add");

return false;
}

/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}

}
17 changes: 17 additions & 0 deletions src/main/java/seedu/savvytasker/logic/commands/AliasCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,21 @@ public boolean undo() {
return false;
}

/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}
18 changes: 18 additions & 0 deletions src/main/java/seedu/savvytasker/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,22 @@ public boolean undo() {
// nothing required to be done
return true;
}

/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}
12 changes: 12 additions & 0 deletions src/main/java/seedu/savvytasker/logic/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,16 @@ protected void indicateAttemptToExecuteIncorrectCommand() {
* @return true if the operation completed successfully, false otherwise
*/
public abstract boolean undo();

/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
public abstract boolean isUndo();

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
public abstract boolean isRedo();
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,22 @@ public boolean undo() {
// nothing required to be done
return true;
}


/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}
17 changes: 17 additions & 0 deletions src/main/java/seedu/savvytasker/logic/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,21 @@ public boolean undo() {
return true;
}

/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}
17 changes: 17 additions & 0 deletions src/main/java/seedu/savvytasker/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,21 @@ public boolean undo() {
return true;
}

/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}
18 changes: 18 additions & 0 deletions src/main/java/seedu/savvytasker/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,22 @@ public boolean undo() {
// nothing required to be done
return true;
}

/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ public boolean undo() {
// nothing required to be done
return true;
}


/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}

19 changes: 19 additions & 0 deletions src/main/java/seedu/savvytasker/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,23 @@ public boolean undo() {
// nothing required to be done
return true;
}

/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}

18 changes: 18 additions & 0 deletions src/main/java/seedu/savvytasker/logic/commands/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,22 @@ public boolean undo() {
// TODO Auto-generated method stub
return false;
}

/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,22 @@ public boolean undo() {
// TODO Auto-generated method stub
return false;
}


/**
* Check if command is an undo command
* @return true if the command is an undo operation, false otherwise
*/
@Override
public boolean isUndo() {
return false;
}

/**
* Check if command is a redo command
* @return true if the command is a redo operation, false otherwise
*/
@Override
public boolean isRedo(){
return false;
}
}
Loading

0 comments on commit 35217da

Please sign in to comment.