forked from nus-cs2103-AY2021S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a696175
commit 8222f50
Showing
9 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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,6 +2,7 @@ | |
|
||
public enum ActionType { | ||
MARK_DONE, | ||
EDIT, | ||
DELETE, | ||
ADD_TODO, | ||
ADD_DEADLINE, | ||
|
This file contains 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 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 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,46 @@ | ||
package duke.command; | ||
|
||
import duke.ActionType; | ||
import duke.DukeException; | ||
import duke.Storage; | ||
import duke.Ui; | ||
import duke.tasks.Task; | ||
import duke.tasks.TaskList; | ||
|
||
/** | ||
* Command to edit a task | ||
*/ | ||
public class EditCommand extends Command { | ||
private final int taskIndex; | ||
private final String editInput; | ||
/** | ||
* EditCommand constructor | ||
* | ||
* @param taskIndex Index of task to be edited | ||
*/ | ||
public EditCommand(int taskIndex, String editInput) { | ||
super(false); | ||
this.taskIndex = taskIndex; | ||
this.editInput = editInput; | ||
} | ||
|
||
/** | ||
* Edits task, then prints its info | ||
* | ||
* @param tasks List of tasks | ||
* @param ui User interface to print task | ||
* @param storage File storage object | ||
* @return Info on edited task | ||
* @throws DukeException if exception encountered | ||
*/ | ||
@Override | ||
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException { | ||
if (taskIndex >= tasks.size()) { | ||
throw new DukeException("Task does not exist _(´ཀ`」 ∠)_"); | ||
} else { | ||
Task editedTask = tasks.edit(taskIndex, editInput); | ||
storage.updateFile(tasks); | ||
return ui.printTask(editedTask, ActionType.EDIT); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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