Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ESC key selects parent of selected node #389

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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;
Expand Down Expand Up @@ -909,6 +910,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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,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.
Expand Down Expand Up @@ -85,6 +88,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 -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for why this is setOnKeyPressed() and the other change is addEventFilter()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, sorry, I did not receive any mail about your comment. Let me check in the next days.

Copy link
Contributor Author

@luca-domenichini luca-domenichini Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlmasB changed to always call setOnKerPressed()

Copy link
Collaborator

@Oliver-Loeffler Oliver-Loeffler Oct 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this looks okay for me.


if (event.getCode() == KeyCode.ESCAPE) {
// on ESC we select the parent of current selected item
MultipleSelectionModel<TreeItem<HierarchyItem>> selectionModel = treeView.getSelectionModel();
TreeItem<HierarchyItem> item = selectionModel.getSelectedItem();
if (item != null) {
TreeItem<HierarchyItem> parent = item.getParent();
if (parent != null) {
selectionModel.clearSelection();
selectionModel.select(parent);
}
}
}
});
}

@Override
Expand Down