diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanelController.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanelController.java index 0def5bb29..4a9e161dd 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanelController.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanelController.java @@ -65,6 +65,7 @@ import javafx.scene.control.TreeTableView; import javafx.scene.image.Image; import javafx.scene.input.InputEvent; +import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundImage; @@ -911,6 +912,20 @@ protected void controllerDidLoadFxml() { = getEditorController().getContextMenuController(); scrollPane.setContextMenu(contextMenuController.getContextMenu()); + scrollPane.setOnKeyPressed(e -> { + + if (e.getCode() == KeyCode.ESCAPE) { + // on ESC we select the parent of current selected item + Selection selection = getEditorController().getSelection(); + FXOMObject parent = selection.getAncestor(); + + if (parent != null) { + selection.clear(); + selection.select(parent); + } + } + }); + // Setup default workspace background setWorkspaceBackground(ImageUtils.getImage(getDefaultWorkspaceBackgroundURL())); } diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/hierarchy/treeview/HierarchyTreeViewController.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/hierarchy/treeview/HierarchyTreeViewController.java index dce380884..dec62e927 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/hierarchy/treeview/HierarchyTreeViewController.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/hierarchy/treeview/HierarchyTreeViewController.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2016, 2022 Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -46,11 +47,14 @@ import javafx.scene.Node; import javafx.scene.control.Cell; import javafx.scene.control.Control; +import javafx.scene.control.MultipleSelectionModel; import javafx.scene.control.ScrollBar; import javafx.scene.control.SelectionMode; import javafx.scene.control.TreeCell; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeView; +import javafx.scene.control.TableView.TableViewSelectionModel; +import javafx.scene.input.KeyCode; /** * Hierarchy panel controller based on the TreeView control. @@ -85,6 +89,22 @@ protected void initializePanel() { // We do not use the platform editing feature because // editing is started on selection + simple click instead of double click treeView.setEditable(false); + + treeView.setOnKeyPressed(event -> { + + if (event.getCode() == KeyCode.ESCAPE) { + // on ESC we select the parent of current selected item + MultipleSelectionModel> selectionModel = treeView.getSelectionModel(); + TreeItem item = selectionModel.getSelectedItem(); + if (item != null) { + TreeItem parent = item.getParent(); + if (parent != null) { + selectionModel.clearSelection(); + selectionModel.select(parent); + } + } + } + }); } @Override