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

MacOS: avoid hiding SceneBuilder menu bar with FXML menu bar when useSystemMenuBar property is enabled #405

Merged
merged 47 commits into from
Jan 17, 2022

Conversation

Oliver-Loeffler
Copy link
Collaborator

@Oliver-Loeffler Oliver-Loeffler commented Sep 7, 2021

For MacOS, when Scene Builder opens a FXML file with a MenuBar with property useSystemMenuBar="true",
then the SceneBuilder menu bar is replaced with the menu bar defined in FXML. Hence SceneBuilder becomes impossible to use.

This PR introduces code which conditionally disables the useSystemMenuBar="true" in the constructor of com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument. As there was already a boolean parameter normalized, the boolean arguments have been replaced with an enum type FXOMDocumentSwitch which provides the values NON_NORMALIZED and FOR_PREVIEW. The change of internal API is minimal and there is no change in default behavior of the FXOMDocument constructor.

Default behavior
For normal loading of an FXML file using the FXOMDocument constructor, the FXML text which is supplied to the FXMLLoader is modified, so that value of useSystemMenuBar is turned to false. This change is not reflected in the FXOM so that the original setting is preserved and can be saved to an FXML file again.
Thus, when loading an accordingly modified FXML file, the SceneBuilder menu will remain the one displayed in MacOS menu bar.
An prepared example is provided within the test resources. kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenu_SystemMenuBarEnabled.fxml

Preview behavior
For previews instead, it migh be desirable to have exactly the behavior that the menu from a given FXML is displayed in MacOS menu bar. Therefore, the argument FXOMDocumentSwitch.FOR_PREVIEW is added to the call of the FXOMDocument constructor in com.oracle.javafx.scenebuilder.kit.preview.PreviewWindowController. In that case, the FXML text which is supplied to the FXMLLoader is not modified at all and if the property useSystemMenuBar="true" exists, then the menubar defined in preview will be displayed in MacOS menu bar.

Issue

Fixes #404

Progress

@Oliver-Loeffler Oliver-Loeffler force-pushed the issue-404 branch 3 times, most recently from 3b2e343 to c2e75cd Compare September 7, 2021 17:10
@Oliver-Loeffler Oliver-Loeffler changed the title Fix for issue #404 MacOS: avoid hiding SceneBuilder menu bar with FXML menu bar when 'useSystemMenuBar="true"' Sep 13, 2021
@Oliver-Loeffler Oliver-Loeffler changed the title MacOS: avoid hiding SceneBuilder menu bar with FXML menu bar when 'useSystemMenuBar="true"' MacOS: avoid hiding SceneBuilder menu bar with FXML menu bar when useSystemMenuBar property is enabled Sep 13, 2021
@abhinayagarwal abhinayagarwal added this to the 18 milestone Sep 13, 2021
@abhinayagarwal abhinayagarwal added the bug Something isn't working label Sep 13, 2021
@abhinayagarwal
Copy link
Collaborator

Hi @Oliver-Loeffler ,

Do you plan to work on this PR and resolve Jose's comments?

@Oliver-Loeffler
Copy link
Collaborator Author

Yes for sure - will see to make some progress here during next days.

@Oliver-Loeffler
Copy link
Collaborator Author

Hi @abhinayagarwal & @jperedadnr,
it took a while but eventually I was able to put some more work in this. Thanks for your feedback so far - looking forward to your remarks & advice.

@Oliver-Loeffler
Copy link
Collaborator Author

@jperedadnr Many thanks for your patience in this!

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Gluon and/or its affiliates.
* Copyright (c) 2022, Gluon and/or its affiliates.
Copy link
Collaborator

Choose a reason for hiding this comment

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

2019, 2022,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

@@ -1,4 +1,5 @@
/*
/*
* Copyright (c) 2017, 2022, Gluon and/or its affiliates.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copyright (c) 2022, ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Corrected

this.glue = new GlueDocument(fxmlText);
this.location = location;
this.classLoader = classLoader;
this.resources = resources;
initialDeclaredClasses = new ArrayList<>();
if (this.glue.getRootElement() != null) {
String fxmlTextToLoad = fxmlText;
if (!Set.of(switches).contains(FXOMDocumentSwitch.FOR_PREVIEW)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Extract Set.of(switches) to a variable, so you don't create the set twice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is now on set used for both places where it is required.

Copy link
Collaborator

@jperedadnr jperedadnr left a comment

Choose a reason for hiding this comment

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

Looks good, great job!

@jperedadnr jperedadnr merged commit 731dbf1 into gluonhq:master Jan 17, 2022
Oliver-Loeffler added a commit to Oliver-Loeffler/scenebuilder that referenced this pull request Jan 21, 2022
…SystemMenuBar property is enabled (gluonhq#405)

Co-authored-by: Oliver-Loeffler <Oliver-Loeffler@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scenebuilder on MacOS does not display menu
3 participants