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: Force refresh of theme and stylesheets when swatch color changes #781

Merged
merged 1 commit into from
Oct 30, 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 @@ -2343,6 +2343,8 @@ public boolean canPerform() {
@Override
public void perform() {
GluonEditorController.getInstance().setGluonSwatch(gluonSwatch);
// After swatch changes, force theme update to refresh the content
documentWindowController.getEditorController().refreshTheme();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,16 @@ public ObservableValue<Theme> themeProperty() {
return themeProperty;
}

/**
* Refresh the theme and related stylesheets in different
* places (content, preview, ...)
*/
public void refreshTheme() {
EditorPlatform.Theme currentTheme = getTheme();
setTheme(null);
setTheme(currentTheme);
Comment on lines +589 to +590
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is setting the theme to null required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

EditorController has themeProperty with a default theme. When the theme changes, it refresh the scene graph from the invalidated() method, and there are a bunch of listeners in different places (5 so far) attached to themeProperty() that react accordingly.

For instance, in ContentPaneController we have:

editorController.themeProperty().addListener((ov, t, t1) -> themeDidChange());

that ultimately calls EditorPlatform::getStylesheetsForTheme, that brings in the Gluon plugin stylesheets and the updated swatch color stylesheet.

The easy way to trigger all those listeners is to force an invalidation of editorController.themeProperty(), and that's easily done with setting null and restoring the current theme.

}

/**
*
* @return the list of scene style sheet used by this editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,9 @@ private void themeDidChange() {
if (contentGroup != null) {
final EditorPlatform.Theme theme = getEditorController().getTheme();
List<String> themeStylesheets = new ArrayList<>(EditorPlatform.getStylesheetsForTheme(theme));
themeStylesheets.addAll(theme.getStylesheetURLs());
if (theme != null) {
themeStylesheets.addAll(theme.getStylesheetURLs());
}
workspaceController.setThemeStylesheet(themeStylesheets, theme);
}
}
Expand Down