From 5fcbe7eff1eb3c1e003a576ab60708100a1f53d4 Mon Sep 17 00:00:00 2001 From: Marc Stammerjohann Date: Thu, 21 Dec 2017 14:00:51 +0100 Subject: [PATCH] #79: add shortcut to navigate through vaults * CTRL + UP * CTRL + DOWN --- .../ui/controllers/MainController.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java index 682cd0afb..2b29d1281 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java @@ -74,6 +74,8 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.ToggleButton; import javafx.scene.image.Image; import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyCodeCombination; +import javafx.scene.input.KeyCombination; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; import javafx.scene.layout.HBox; @@ -107,6 +109,9 @@ public class MainController implements ViewController { private final BooleanBinding isShowingSettings; private final Map unlockedVaults = new HashMap<>(); + private final KeyCombination keyCodeCombinationCtrlUp = new KeyCodeCombination(KeyCode.UP, KeyCombination.CONTROL_DOWN); + private final KeyCombination keyCodeCombinationCtrlDown = new KeyCodeCombination(KeyCode.DOWN, KeyCombination.CONTROL_DOWN); + private Subscription subs = Subscription.EMPTY; @Inject @@ -171,6 +176,7 @@ public class MainController implements ViewController { vaultList.setItems(vaults); vaultList.setOnKeyReleased(this::didPressKeyOnList); vaultList.setCellFactory(this::createDirecoryListCell); + root.setOnKeyReleased(this::didPressKeyOnRoot); activeController.set(viewControllerLoader.load("/fxml/welcome.fxml")); selectedVault.bind(vaultList.getSelectionModel().selectedItemProperty()); removeVaultButton.disableProperty().bind(canEditSelectedVault.not()); @@ -408,6 +414,19 @@ public class MainController implements ViewController { } } + private void didPressKeyOnRoot(KeyEvent event) { + if (keyCodeCombinationCtrlUp.match(event)) { + vaultList.getSelectionModel().select( + vaultList.getSelectionModel().getSelectedIndex() == 0 ? 0 + : vaultList.getSelectionModel().getSelectedIndex() - 1); + } else if (keyCodeCombinationCtrlDown.match(event)) { + vaultList.getSelectionModel().select( + vaultList.getSelectionModel().getSelectedIndex() == vaultList.getItems().size() + ? vaultList.getItems().size() + : vaultList.getSelectionModel().getSelectedIndex() + 1); + } + } + private void didClickOnListCell(MouseEvent e) { if (MouseEvent.MOUSE_CLICKED.equals(e.getEventType()) && e.getSource() instanceof Cell && ((Cell) e.getSource()).isSelected()) { activeController.get().focus();