Skip to content

Commit

Permalink
Update auto complete feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Wanchunwei committed Mar 25, 2019
1 parent eaf2f91 commit 2831bf7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 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>main</name>
<name>Main</name>
<comment>Project main created by Buildship.</comment>
<projects>
</projects>
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/seedu/address/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
*/
public class CommandBox extends UiPart<Region> {

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 {
Expand Down Expand Up @@ -69,9 +69,10 @@ public CommandBox(CommandExecutor commandExecutor, List<String> 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,
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class MainWindow extends UiPart<Stage> {
private TaskListPanel taskListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
private CommandBox commandBox;

//To check which scene to show
private String optionPage = DEFAULT_PAGE;
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/ui/UiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2831bf7

Please sign in to comment.