Skip to content

Commit ceece31

Browse files
fix: Prevents CTRL+P from being masked by a given accelerator defined 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.
1 parent ad3003e commit ceece31

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ public enum ActionStatus {
323323
}
324324
event.consume();
325325
}
326+
327+
// Keep preview function working even if preview accelerator is
328+
// already occupied in FXML
329+
if (KeyCode.P.equals(event.getCode()) && modifierDown) {
330+
menuBarController.showPreview();
331+
event.consume();
332+
}
326333
};
327334

328335
/*

app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ public class MenuBarController {
432432
private static final KeyCombination.Modifier modifier;
433433
private final Map<KeyCombination, MenuItem> keyToMenu = new HashMap<>();
434434

435+
private DocumentControlActionController previewController;
436+
435437
static {
436438
if (EditorPlatform.IS_MAC) {
437439
modifier = KeyCombination.META_DOWN;
@@ -445,6 +447,12 @@ public MenuBarController(DocumentWindowController documentWindowController) {
445447
this.documentWindowController = documentWindowController;
446448
}
447449

450+
public void showPreview() {
451+
if (previewController != null && previewController.canPerform()) {
452+
previewController.perform();
453+
}
454+
}
455+
448456
public MenuBar getMenuBar() {
449457

450458
if (menuBar == null) {
@@ -1037,7 +1045,10 @@ public void perform() {
10371045
/*
10381046
* Preview menu
10391047
*/
1040-
showPreviewInWindowMenuItem.setUserData(new DocumentControlActionController(DocumentControlAction.SHOW_PREVIEW_WINDOW));
1048+
if (null == previewController) {
1049+
previewController = new DocumentControlActionController(DocumentControlAction.SHOW_PREVIEW_WINDOW);
1050+
}
1051+
showPreviewInWindowMenuItem.setUserData(previewController);
10411052
showPreviewInWindowMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.P, modifier));
10421053
showPreviewInDialogMenuItem.setUserData(new DocumentControlActionController(DocumentControlAction.SHOW_PREVIEW_DIALOG));
10431054
caspianHighContrastThemeMenuItem.setUserData(new SetThemeActionController(EditorPlatform.Theme.CASPIAN_HIGH_CONTRAST));

0 commit comments

Comments
 (0)