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

fix: Prevents CTRL+P from being masked by a given accelerator defined in FXML (#553) #593

Merged
merged 15 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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