Skip to content

Commit

Permalink
Add unarchive feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mario7lorenzo committed Feb 13, 2020
1 parent a9cdab5 commit d05d69d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
4 changes: 3 additions & 1 deletion data/archive.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
T | 0 | helloworld
T | 0 | helloworld
T | 0 | helloworld
E | 0 | valentine with girlfriend | 14-02-2020 21:00
E | 0 | drunk with friends | 13-02-2020 23:59
8 changes: 7 additions & 1 deletion data/tasks.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
T | 0 | helloworld
T | 0 | helloworld
E | 0 | drunk with friends | 13-02-2020 23:59
E | 0 | valentine with girlfriend | 14-02-2020 21:00
D | 0 | CS2103 Duke Project | 14-02-2020 23:59
T | 0 | dddskpfs
T | 0 | duar
T | 0 | tod
T | 0 | todododod
T | 0 | dododododo
2 changes: 1 addition & 1 deletion src/main/java/duke/command/UnarchiveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String execute(TaskList taskList, Storage storage, ArchiveList archiveLis
Task task = archiveList.getTask(this.index);
archiveList.deleteArchivedTask(this.index, storage);
taskList.addTask(task, storage);
return "Done! I have successfully unarchived: " + task;
return "Done! I have successfully unarchived:\n" + task;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/duke/util/Keyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public enum Keyword {
* <li>ARCHIVE_LIST</li>
* <li>ARCHIVE_ADD</li>
* <li>ARCHIVE_DELETE</li>
* <li>UNARCHIVE</li>
* <li>NOTE_LIST</li>
* <li>NOTE_ADD</li>
* <li>NOTE_DELETE</li>
*/

LIST, DONE, TODO, DEADLINE, EVENT, DELETE, FIND, BYE, REMINDER, ARCHIVE_LIST, ARCHIVE_ADD, ARCHIVE_DELETE,
NOTE_LIST, NOTE_ADD, NOTE_DELETE;
UNARCHIVE, NOTE_LIST, NOTE_ADD, NOTE_DELETE;
}
28 changes: 28 additions & 0 deletions src/main/java/duke/util/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import duke.command.NoteAddCommand;
import duke.command.NoteDeleteCommand;
import duke.command.NoteListCommand;
import duke.command.UnarchiveCommand;
import duke.exception.DukeInvalidArgumentFormatException;
import duke.exception.DukeInvalidDateFormatException;
import duke.exception.DukeUnknownKeywordException;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class Parser {
put("archive-list", Keyword.ARCHIVE_LIST);
put("archive-add", Keyword.ARCHIVE_ADD);
put("archive-delete", Keyword.ARCHIVE_DELETE);
put("unarchive", Keyword.UNARCHIVE);
put("note-list", Keyword.NOTE_LIST);
put("note-add", Keyword.NOTE_ADD);
put("note-delete", Keyword.NOTE_DELETE);
Expand Down Expand Up @@ -157,6 +159,9 @@ private Command validateCommand(Keyword keyword, String details, IList<Task> tas
case ARCHIVE_DELETE:
command = checkValidArchiveDeleteArgument(details, archiveList);
break;
case UNARCHIVE:
command = checkValidUnarchiveArgument(details, archiveList);
break;
case NOTE_LIST:
command = checkValidNoteListArgument(details);
break;
Expand Down Expand Up @@ -418,6 +423,29 @@ private ArchiveDeleteCommand checkValidArchiveDeleteArgument(String details, ILi
return new ArchiveDeleteCommand(index);
}

/**
* Verifies that the command entered by the client is a valid unarchive command.
* @param details The details of the command.
* @param taskList The list of the archives.
* @return The UnarchiveCommand instance of the corresponding input.
*/

private UnarchiveCommand checkValidUnarchiveArgument(String details, IList<Task> taskList) throws
DukeInvalidArgumentFormatException {
int index = -1;
try {
index = Integer.parseInt(details);
} catch (NumberFormatException e) {
throw new DukeInvalidArgumentFormatException("☹ OOPS!!! "
+ "The argument for 'archive-delete' command requires a number.");
}

if (index <= 0 || index > taskList.size()) {
throw new DukeInvalidArgumentFormatException("☹ OOPS!!! The index given is out of bound.");
}
return new UnarchiveCommand(index);
}

/**
* Verifies that the command entered by the client is a valid
* note-add command.
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/view/DialogBox.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>

<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="400.0"
type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity"
prefWidth="400.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="dialog" style="-fx-background-color: #bfff00;" wrapText="true">
<padding>
Expand Down

0 comments on commit d05d69d

Please sign in to comment.