Skip to content

Commit

Permalink
fix: Prevents CTRL+P from being masked by a given accelerator defined…
Browse files Browse the repository at this point in the history
… in FXML (#553) (#593)

* fix: Prevents CTRL+P from being masked by a given accelerator defined in FXML. Hence allowing to show preview with CTRL+P.
* Added showPreview method to MenuBarController.
* Key code provided by event is now compared to KeyCode instance.
  • Loading branch information
Oliver-Loeffler authored Nov 10, 2024
1 parent ad3003e commit ceece31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ public enum ActionStatus {
}
event.consume();
}

// Keep preview function working even if preview accelerator is
// already occupied in FXML
if (KeyCode.P.equals(event.getCode()) && modifierDown) {
menuBarController.showPreview();
event.consume();
}
};

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ public class MenuBarController {
private static final KeyCombination.Modifier modifier;
private final Map<KeyCombination, MenuItem> keyToMenu = new HashMap<>();

private DocumentControlActionController previewController;

static {
if (EditorPlatform.IS_MAC) {
modifier = KeyCombination.META_DOWN;
Expand All @@ -445,6 +447,12 @@ public MenuBarController(DocumentWindowController documentWindowController) {
this.documentWindowController = documentWindowController;
}

public void showPreview() {
if (previewController != null && previewController.canPerform()) {
previewController.perform();
}
}

public MenuBar getMenuBar() {

if (menuBar == null) {
Expand Down Expand Up @@ -1037,7 +1045,10 @@ public void perform() {
/*
* Preview menu
*/
showPreviewInWindowMenuItem.setUserData(new DocumentControlActionController(DocumentControlAction.SHOW_PREVIEW_WINDOW));
if (null == previewController) {
previewController = new DocumentControlActionController(DocumentControlAction.SHOW_PREVIEW_WINDOW);
}
showPreviewInWindowMenuItem.setUserData(previewController);
showPreviewInWindowMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.P, modifier));
showPreviewInDialogMenuItem.setUserData(new DocumentControlActionController(DocumentControlAction.SHOW_PREVIEW_DIALOG));
caspianHighContrastThemeMenuItem.setUserData(new SetThemeActionController(EditorPlatform.Theme.CASPIAN_HIGH_CONTRAST));
Expand Down

0 comments on commit ceece31

Please sign in to comment.