Skip to content

Commit

Permalink
Add exit case and handle exit in main window
Browse files Browse the repository at this point in the history
  • Loading branch information
dasha3412 committed Sep 18, 2024
1 parent ab4431c commit b789d9f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/main/java/victor/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ public Handler() {
* @param request A string containing the user's input to the task bot.
* @return A string containing the program's response to the user input.
*/
public String handleRequest(String request) {
public Command handleRequest(String request) {
Command command = parser.parseInput(request);
command.setData(taskList);
ReturnMessage returnMessage = command.execute();
command.write(DATA_PATH);
return returnMessage.getMessagesAsString();
return command;
}
}
8 changes: 6 additions & 2 deletions src/main/java/victor/controls/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import victor.Handler;
import victor.commands.Command;
import victor.messages.ReturnMessage;

/**
* Controller for the main GUI.
Expand Down Expand Up @@ -62,10 +64,12 @@ public void welcomeUser() {
@FXML
private void handleUserInput() {
String input = userInput.getText();
if (input.trim().equalsIgnoreCase("bye")) {
Command command = handler.handleRequest(input);
if (command.isExit()) {
stage.close();
}
String response = handler.handleRequest(input);
ReturnMessage returnMessage = command.execute();
String response = returnMessage.getMessagesAsString();
dialogContainer.getChildren().addAll(
DialogBox.getUserDialog(input, userImage),
DialogBox.getVictorDialog(response, victorImage)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/victor/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Command parseInput(String input) {
case "mark" -> new MarkCommand(inputWords);
case "unmark" -> new UnmarkCommand(inputWords);
case "list" -> new ListCommand(inputWords);
case "bye" -> new ExitCommand(inputWords);
case "bye", "exit" -> new ExitCommand(inputWords);
case "find" -> new FindCommand(inputWords);
default -> new Command(inputWords);
};
Expand Down

0 comments on commit b789d9f

Please sign in to comment.