Skip to content

Commit

Permalink
fix: Remove platform theme url from stylesheets, (#761)
Browse files Browse the repository at this point in the history
* Remove platform theme url from stylesheets, to prevent user agent from being overwritten

* fix typo

* Fix preview
  • Loading branch information
jperedadnr authored Oct 22, 2024
1 parent 91f6846 commit 8cb8648
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public static Theme valueOf(String themeName) {
// no-op
}

public static boolean isPlatformThemeStylesheetURL(String stylesheetURL) {
// Return USER_AGENT css, which is Modena for fx 8.0
return stylesheetURL != null && stylesheetURL.equals(Theme.MODENA.getStylesheetURLs().getFirst());
}

public static String getPlatformThemeStylesheetURL() {
// Return USER_AGENT css, which is Modena for fx 8.0
return Theme.MODENA.getStylesheetURLs().getFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ private void themeDidChange() {
final EditorPlatform.Theme theme = getEditorController().getTheme();
List<String> themeStylesheets = new ArrayList<>(EditorPlatform.getStylesheetsForTheme(theme));
themeStylesheets.addAll(theme.getStylesheetURLs());
workspaceController.setThemeStyleSheet(themeStylesheets, theme);
workspaceController.setThemeStylesheet(themeStylesheets, theme);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,18 @@ public List<String> getThemeStyleSheets() {
return Collections.unmodifiableList(themeStylesheets);
}

public void setThemeStyleSheet(List<String> themeStyleSheets, EditorPlatform.Theme theme) {
assert themeStyleSheets != null;
public void setThemeStylesheet(List<String> themeStylesheets, EditorPlatform.Theme theme) {
assert themeStylesheets != null;
assert theme != null;
List<String> stylesheets = new ArrayList<>(EditorPlatform.getStylesheetsForTheme(theme));
stylesheets.addAll(themeStyleSheets);
contentSubScene.setUserAgentStylesheet(stylesheets.getFirst());
themeStylesheets.stream()
.filter(s -> !EditorPlatform.isPlatformThemeStylesheetURL(s))
.forEach(stylesheets::add);
contentSubScene.setUserAgentStylesheet(stylesheets.stream().findFirst().orElse(null));

ObservableList<String> currentStyleSheets = FXCollections.observableArrayList(stylesheets);
themeStylesheets.clear();
themeStylesheets.addAll(currentStyleSheets);
ObservableList<String> currentStylesheets = FXCollections.observableArrayList(stylesheets);
this.themeStylesheets.clear();
this.themeStylesheets.addAll(currentStylesheets);
contentGroupApplyCss();

// Update scenegraph layout, etc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ public void run() {

Object sceneGraphRoot = clone.getDisplayNodeOrSceneGraphRoot();
themeStyleSheetsList = new ArrayList<>(EditorPlatform.getStylesheetsForTheme(editorController.getTheme()));
themeStyleSheetsList.addAll(editorControllerTheme.getStylesheetURLs());
editorControllerTheme.getStylesheetURLs().stream()
.filter(s -> !EditorPlatform.isPlatformThemeStylesheetURL(s))
.forEach(themeStyleSheetsList::add);

if (sceneGraphRoot instanceof Parent) {
((Parent) sceneGraphRoot).setId(NID_PREVIEW_ROOT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.TreeMap;
import java.util.TreeSet;

import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform;
import javafx.beans.property.ReadOnlyProperty;
import javafx.collections.FXCollections;
import javafx.css.CssMetaData;
Expand Down Expand Up @@ -151,10 +152,12 @@ public static boolean isThemeClass(Theme theme, String styleClass) {

public static List<String> getThemeStyleClasses(Theme theme) {
Set<String> themeClasses = new HashSet<>();
theme.getStylesheetURLs().forEach(themeStyleSheet -> {
URL resource = Button.class.getResource("/" + themeStyleSheet);
themeClasses.addAll(getStyleClasses(resource));
});
theme.getStylesheetURLs().stream()
.filter(s -> !EditorPlatform.isPlatformThemeStylesheetURL(s))
.forEach(themeStyleSheet -> {
URL resource = Button.class.getResource("/" + themeStyleSheet);
themeClasses.addAll(getStyleClasses(resource));
});
return new ArrayList<>(themeClasses);
}

Expand Down

0 comments on commit 8cb8648

Please sign in to comment.