Skip to content

Commit

Permalink
Fix custom theme styles not applied to the entry preview (#7071)
Browse files Browse the repository at this point in the history
* Fix custom theme styles not applied to the entry preview

Make comment more precise

* cbheckstyle

* Update CHANGELOG.md
  • Loading branch information
Siedlerchr committed Nov 4, 2020
1 parent b5bcea4 commit 67f67a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ inserting new citations in a OpenOffic/LibreOffice document. [#6957](https://git
- We fixed an issue where identity column header had incorrect foreground color in the Dark theme. [#6796](https://github.com/JabRef/jabref/issues/6796)
- We fixed an issue where the RIS exporter added extra blank lines.[#7007](https://github.com/JabRef/jabref/pull/7007/files)
- We fixed an issue where clicking on Collapse All button in the Search for Unlinked Local Files expanded the directory structure erroneously [#6848](https://github.com/JabRef/jabref/issues/6848)
- We fixed an issue, when pulling changes from shared database via shortcut caused creation a new new tech report [6867](https://github.com/JabRef/jabref/issues/6867)
- We fixed an issue, when pulling changes from shared database via shortcut caused creation of a new tech report [6867](https://github.com/JabRef/jabref/issues/6867)
- We fixed an issue where the JabRef GUI does not highlight the "All entries" group on start-up [#6691](https://github.com/JabRef/jabref/issues/6691)
- We fixed an issue where a custom dark theme was not applied to the entry preview tab [7068](https://github.com/JabRef/jabref/issues/7068)

### Removed

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/jabref/gui/preview/PreviewViewer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.preview;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Base64;
import java.util.Objects;
Expand Down Expand Up @@ -119,12 +120,19 @@ public PreviewViewer(BibDatabaseContext database, DialogService dialogService, S
public void setTheme(Theme theme) {
if (theme.getType() == Theme.Type.DARK) {
// We need to load the css file manually, due to a bug in the jdk
// TODO: Remove this workaround as soon as https://github.com/openjdk/jfx/pull/22 is merged
// https://bugs.openjdk.java.net/browse/JDK-8240969
// TODO: Remove this workaround as soon as openjfx 16 is released
URL url = JabRefFrame.class.getResource(theme.getPath().getFileName().toString());
String dataUrl = "data:text/css;charset=utf-8;base64," +
Base64.getEncoder().encodeToString(StringUtil.getResourceFileAsString(url).getBytes());

previewView.getEngine().setUserStyleSheetLocation(dataUrl);
} else if (theme.getType() != Theme.Type.LIGHT) {
try {
previewView.getEngine().setUserStyleSheetLocation(theme.getPath().toUri().toURL().toExternalForm());
} catch (MalformedURLException ex) {
LOGGER.error("Cannot set custom theme, invalid url", ex);
}
}
}

Expand Down Expand Up @@ -171,7 +179,7 @@ public void setEntry(BibEntry newEntry) {
}

private void update() {
if (entry.isEmpty() || layout == null) {
if (entry.isEmpty() || (layout == null)) {
// Nothing to do
return;
}
Expand Down

0 comments on commit 67f67a1

Please sign in to comment.