Skip to content

Commit

Permalink
Navigate to CommandBox TextField with any letter press
Browse files Browse the repository at this point in the history
  • Loading branch information
Inaba Kazuhiro committed Oct 30, 2016
1 parent a2d3dd3 commit ce65750
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/seedu/taskman/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static CommandBox load(Stage primaryStage, AnchorPane commandBoxPlacehold
commandBox.addToPlaceholder();
return commandBox;
}

public TextField getTextField() {
return commandTextField;
}

public void configure(ResultDisplay resultDisplay, Logic logic) {
this.resultDisplay = resultDisplay;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/seedu/taskman/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.control.ListView;
import javafx.scene.control.MenuItem;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
Expand Down Expand Up @@ -238,6 +239,18 @@ private void handleExit() {
raise(new ExitAppRequestEvent());
}

@FXML
public void handleEnterPressed(KeyEvent key){
if (commandBox.getTextField().isFocused()) {
return;
} else if (key.getCode().isLetterKey()){
System.out.println(key.getCode().getName() + " is pressed!");
commandBox.getTextField().requestFocus();
} else {
return;
}
}

private void configureFocus() {
ArrayList<Node> nodes = getAllNodes();
for (Node node : nodes) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>

<VBox xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seedu.taskman.ui.MainWindow">
<VBox onKeyPressed="#handleEnterPressed" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seedu.taskman.ui.MainWindow">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>
Expand Down

0 comments on commit ce65750

Please sign in to comment.