Skip to content

Commit

Permalink
fix "save" button in preference dialog not response (#4406)
Browse files Browse the repository at this point in the history
Fixes #4391.

* fix "save" button in preference dialog not response or work

this is because default value for fxTheme is not set, thus cause null exception
solution: set default value "Base.css" for key "fxTheme" in preferencewq

* avoid repeat adding the same css

* fix code style
  • Loading branch information
Fancy Zhang authored and tobiasdiez committed Oct 25, 2018
1 parent e8daf26 commit 4d89b0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/org/jabref/gui/util/ThemeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
*/
public class ThemeLoader {

private static final String DEFAULT_PATH_MAIN_CSS = JabRefFrame.class.getResource("Base.css").toExternalForm();
public static final String DEFAULT_MAIN_CSS = "Base.css";
private static final String DEFAULT_PATH_MAIN_CSS = JabRefFrame.class.getResource(DEFAULT_MAIN_CSS).toExternalForm();
private static final Logger LOGGER = LoggerFactory.getLogger(ThemeLoader.class);
private String cssProperty = System.getProperty("jabref.theme.css");
private final FileUpdateMonitor fileUpdateMonitor;
Expand All @@ -57,25 +58,31 @@ public ThemeLoader(FileUpdateMonitor fileUpdateMonitor, JabRefPreferences jabRef
}
}


/**
* Installs the base css file as a stylesheet in the given scene.
* Changes in the css file lead to a redraw of the scene using the new css file.
*/
public void installBaseCss(Scene scene, JabRefPreferences preferences) {
addAndWatchForChanges(scene, DEFAULT_PATH_MAIN_CSS, 0);

if (StringUtil.isNotBlank(cssProperty)) {
final Path path = Paths.get(cssProperty);
if (Files.isReadable(path)) {
String cssUrl = path.toUri().toString();
addAndWatchForChanges(scene, cssUrl, 1);
addAndWatchForChanges(scene, cssUrl, 0);
} else {
LOGGER.warn(path.toAbsolutePath() + " is not readable");
}
} else {
addAndWatchForChanges(scene, DEFAULT_PATH_MAIN_CSS, 0);
}

preferences.getFontSize().ifPresent(size -> scene.getRoot().setStyle("-fx-font-size: " + size + "pt;"));
}

private void addAndWatchForChanges(Scene scene, String cssUrl, int index) {
// avoid repeat add
if (scene.getStylesheets().contains(cssUrl)) return;

scene.getStylesheets().add(index, cssUrl);

try {
Expand All @@ -86,7 +93,6 @@ private void addAndWatchForChanges(Scene scene, String cssUrl, int index) {
LOGGER.info("Enabling live reloading of " + cssFile);
fileUpdateMonitor.addListenerForFile(cssFile, () -> {
LOGGER.info("Reload css file " + cssFile);

DefaultTaskExecutor.runInJavaFXThread(() -> {
scene.getStylesheets().remove(cssUrl);
scene.getStylesheets().add(index, cssUrl);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.jabref.gui.maintable.ColumnPreferences;
import org.jabref.gui.maintable.MainTablePreferences;
import org.jabref.gui.preferences.ImportSettingsTab;
import org.jabref.gui.util.ThemeLoader;
import org.jabref.logic.bibtex.FieldContentParserPreferences;
import org.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences;
Expand Down Expand Up @@ -780,6 +781,8 @@ private JabRefPreferences() {
+ "\\begin{comment}<BR><BR><b>Comment: </b> \\format[HTMLChars]{\\comment} \\end{comment}"
+ "</dd>__NEWLINE__<p></p></font>");

// set default theme
defaults.put(JabRefPreferences.FX_THEME, ThemeLoader.DEFAULT_MAIN_CSS);
setLanguageDependentDefaultValues();
}

Expand Down

0 comments on commit 4d89b0a

Please sign in to comment.