diff --git a/.project b/.project index f151561e3e92..444e583482a2 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - main + Main Project main created by Buildship. diff --git a/src/main/java/seedu/address/ui/CommandBox.java b/src/main/java/seedu/address/ui/CommandBox.java index 49733ad0e82b..b0d56fcf458d 100644 --- a/src/main/java/seedu/address/ui/CommandBox.java +++ b/src/main/java/seedu/address/ui/CommandBox.java @@ -29,10 +29,10 @@ */ public class CommandBox extends UiPart { + public static final String NO_MATCHED_COMMAND = "No matched command!"; public static final String ERROR_STYLE_CLASS = "error"; private static final String FXML = "CommandBox.fxml"; - private static final String[] CommandList; static { @@ -69,9 +69,10 @@ public CommandBox(CommandExecutor commandExecutor, List history) { /** * Handles the key press event, {@code keyEvent}. + * @throws Exception */ @FXML - private void handleKeyPress(KeyEvent keyEvent) { + private void handleKeyPress(KeyEvent keyEvent) throws Exception { switch (keyEvent.getCode()) { case UP: // As up and down buttons will alter the position of the caret, @@ -93,7 +94,7 @@ private void handleKeyPress(KeyEvent keyEvent) { } } - private void autoCompleteInputCommand() { + private void autoCompleteInputCommand() throws Exception { String text = commandTextField.getText(); String completedtext = getCompletedtext(text); commandTextField.setText(completedtext); @@ -117,7 +118,11 @@ private String getMostSimilarCommand(String text, String[] commandlist) { highestRatio = getSimilarityRatio(text, commands); highestRatioCommand = commands; } - System.out.println(getSimilarityRatio(text, commands)); + //System.out.println(getSimilarityRatio(text, commands)); + } + + if(highestRatio < 0.5) { + return NO_MATCHED_COMMAND; } return highestRatioCommand; } @@ -221,6 +226,21 @@ private void handleCommandEntered() { } } + /** + * Handles the tap button pressed event. + */ + @FXML + private void handleCommandtapped() { + try { + commandExecutor.execute(commandTextField.getText()); + initHistory(); + historySnapshot.next(); + commandTextField.setText(""); + } catch (CommandException | ParseException e) { + initHistory(); + setStyleToIndicateCommandFailure(); + } + } /** * Initializes the history snapshot. */ diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index b2a79e7c4609..0908ee6ae085 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -39,6 +39,7 @@ public class MainWindow extends UiPart { private TaskListPanel taskListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; + private CommandBox commandBox; //To check which scene to show private String optionPage = DEFAULT_PAGE; @@ -150,7 +151,8 @@ void fillInnerParts() { StatusBarFooter statusBarFooter = new StatusBarFooter(logic.getTaskBookFilePath(), logic.getTaskBook()); statusbarPlaceholder.getChildren().add(statusBarFooter.getRoot()); - CommandBox commandBox = new CommandBox(this::executeCommand, logic.getHistory()); + commandBox = new CommandBox(this::executeCommand, logic.getHistory()); + commandBoxPlaceholder.getChildren().add(commandBox.getRoot()); } @@ -223,7 +225,6 @@ private CommandResult executeCommand(String commandText) throws CommandException CommandResult commandResult = logic.execute(commandText); logger.info("Result: " + commandResult.getFeedbackToUser()); resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser()); - if (commandResult.isShowHelp()) { handleHelp(); } diff --git a/src/main/java/seedu/address/ui/UiManager.java b/src/main/java/seedu/address/ui/UiManager.java index 0cd4c1ac0019..67c892acac99 100644 --- a/src/main/java/seedu/address/ui/UiManager.java +++ b/src/main/java/seedu/address/ui/UiManager.java @@ -42,6 +42,7 @@ public void start(Stage primaryStage) { mainWindow.show(); //This should be called before creating other UI parts mainWindow.fillInnerParts(); + } catch (Throwable e) { logger.severe(StringUtil.getDetails(e)); showFatalErrorDialogAndShutdown("Fatal error during initializing", e);