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 "save" button in preference dialog not response #4406

Merged
merged 3 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
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