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

Live reloading when switching themes #7336

Merged
merged 55 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
87a8c32
live reloading when switching themes, refs #7335
docrjp Jan 12, 2021
0e3310f
preview fully live reloads now, refs #7335
docrjp Jan 12, 2021
3d442d5
remove restart warnings for theme, rfs #7335
docrjp Jan 12, 2021
be101ba
fix import checkstyle violations
docrjp Jan 12, 2021
6293332
add custom static factory to ThemePreference
docrjp Jan 12, 2021
04a202d
live reload font override preference changes
docrjp Jan 17, 2021
752095a
rename Theme to ThemeManager
docrjp Jan 17, 2021
27445da
rename empty theme to light and remove StyleSheetEmpty
docrjp Jan 17, 2021
ed8feb2
remove redundant restart messages from resource bundle
docrjp Jan 17, 2021
fcff1d5
Merge remote-tracking branch 'upstream/master' into fix-7335
calixtus Feb 26, 2021
4902c79
Moved construction of ThemeManager to Globals and added some small fixes
calixtus Feb 28, 2021
7d6d510
Fixed some tests
calixtus Feb 28, 2021
ac437d5
Merge remote-tracking branch 'upstream/master' into fix-7335
calixtus Mar 5, 2021
13a9f2e
Merge remote-tracking branch 'upstream/master' into fix-7335
calixtus Mar 10, 2021
09cd062
Fixed ThemeTest
calixtus Mar 10, 2021
0593492
Removed Light.css
calixtus Mar 10, 2021
9c1e9d0
Merge remote-tracking branch 'upstream/master' into fix-7335
calixtus Mar 11, 2021
8e8ceb7
Injecting ThemeManager
calixtus Mar 11, 2021
c04ed80
Removed restart message
calixtus Mar 11, 2021
a4c0917
Minor tweaks and checkstyle
calixtus Mar 13, 2021
ebddcaa
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus Apr 26, 2021
557f0de
Changed constant names to more meaningful ones
calixtus Apr 26, 2021
9cdab98
Removed workaround for fixed bug with external jrt stylesheets and re…
calixtus Apr 26, 2021
699aaca
Fixed concurrency issue
calixtus Apr 26, 2021
8a7e119
Fixed ThemeTest
calixtus Apr 27, 2021
f295619
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus May 7, 2021
a89b255
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus May 9, 2021
74b5559
Restored DataUrl
calixtus May 10, 2021
2d2e506
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus Jun 1, 2021
477dbdc
Removed currentAppearancePreferences, refactored ThemeManager and add…
calixtus Jun 2, 2021
c9c9595
Removed setter in PreviewViewer
calixtus Jun 2, 2021
767830e
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus Jun 4, 2021
f7b6e82
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus Aug 18, 2021
471659e
Fixed merge errors
calixtus Aug 18, 2021
9c833f4
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus Sep 2, 2021
c1216eb
Fixed merge errors
calixtus Sep 2, 2021
a4d782a
Fixed merge errors
calixtus Sep 2, 2021
d9ca623
Fixed IndexOutOfBoundsException
calixtus Sep 2, 2021
27352cc
Fixed IndexOutOfBoundsException
calixtus Sep 2, 2021
5d261c1
WIP tests
calixtus Sep 10, 2021
a40d317
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus Sep 10, 2021
35af350
Fixed merge error
calixtus Sep 10, 2021
02cee7c
Checkstyle
calixtus Sep 10, 2021
cdf354a
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus Dec 14, 2021
4f1fa8f
Fixed merge conflicts and annoying race condition
calixtus Dec 14, 2021
1053f9c
Merge remote-tracking branch 'upstream/main' into fix-7335
calixtus Dec 30, 2021
f8ca9dd
Fixed merge errors
calixtus Dec 30, 2021
85787e3
Fixed tests
calixtus Dec 31, 2021
8574d53
Avoided Optional as field, implemented TDiez suggestion
calixtus Dec 31, 2021
ae0e432
Checkstyle and CHANGELOG.md
calixtus Dec 31, 2021
749f023
Fix issue about font sizing, removed restart warnings
calixtus Jan 1, 2022
12c9839
Fixed tests
calixtus Jan 1, 2022
0253a3a
checkstyle
calixtus Jan 1, 2022
ad7a8a8
l10n
calixtus Jan 1, 2022
72775e9
Modified comments
calixtus Jan 3, 2022
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 @@ -68,9 +68,9 @@ public class ManageStudyDefinitionView extends BaseDialog<SlrStudyAndDirectory>
@FXML private TableColumn<StudyDatabaseItem, String> databaseColumn;
@FXML private TableColumn<StudyDatabaseItem, String> databaseActionColumn;

@Inject DialogService dialogService;
@Inject PreferencesService prefs;
@Inject ThemeManager themeManager;
@Inject private DialogService dialogService;
@Inject private PreferencesService prefs;
@Inject private ThemeManager themeManager;

private ManageStudyDefinitionViewModel viewModel;
private final Study study;
calixtus marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
43 changes: 21 additions & 22 deletions src/test/java/org/jabref/gui/theme/ThemeManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
import org.jabref.gui.util.DefaultFileUpdateMonitor;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.preferences.AppearancePreferences;
import org.jabref.preferences.PreferencesService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mockito;
import org.testfx.framework.junit5.ApplicationExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -44,22 +42,20 @@ class ThemeManagerTest {
}""";

private Path tempFolder;
private PreferencesService preferencesService;

@BeforeEach
void setUp(@TempDir Path tempFolder) {
this.tempFolder = tempFolder;
this.preferencesService = Mockito.mock(PreferencesService.class);
}

@Test
public void themeManagerUsesProvidedTheme() throws IOException {
Path testCss = tempFolder.resolve("test.css");
Files.writeString(testCss, TEST_CSS_CONTENT, StandardOpenOption.CREATE);
when(preferencesService.getAppearancePreferences()).thenReturn(
new AppearancePreferences(false, 0, new Theme(testCss.toString())));
AppearancePreferences appearancePreferences =
new AppearancePreferences(false, 0, new Theme(testCss.toString()));

ThemeManager themeManager = new ThemeManager(preferencesService, new DummyFileUpdateMonitor(), Runnable::run);
ThemeManager themeManager = new ThemeManager(appearancePreferences, new DummyFileUpdateMonitor(), Runnable::run);

assertEquals(Theme.Type.CUSTOM, themeManager.getActiveTheme().getType());
assertEquals(testCss.toString(), themeManager.getActiveTheme().getName());
Expand All @@ -76,11 +72,11 @@ public void customThemeAvailableEvenWhenDeleted() throws IOException {
validation (at the moment) but by making a valid CSS block we don't preclude adding validation later */
Path testCss = tempFolder.resolve("test.css");
Files.writeString(testCss, TEST_CSS_CONTENT, StandardOpenOption.CREATE);
when(preferencesService.getAppearancePreferences()).thenReturn(
new AppearancePreferences(false, 0, new Theme(testCss.toString())));
AppearancePreferences appearancePreferences =
new AppearancePreferences(false, 0, new Theme(testCss.toString()));

// ActiveTheme should provide the additionalStylesheet that was created before
ThemeManager themeManagerCreatedBeforeFileDeleted = new ThemeManager(preferencesService, new DummyFileUpdateMonitor(), Runnable::run);
ThemeManager themeManagerCreatedBeforeFileDeleted = new ThemeManager(appearancePreferences, new DummyFileUpdateMonitor(), Runnable::run);

Files.delete(testCss);

Expand All @@ -104,11 +100,11 @@ public void customThemeAvailableEvenWhenDeleted() throws IOException {
@Test
public void customThemeBecomesAvailableAfterFileIsCreated() throws IOException {
Path testCss = tempFolder.resolve("test.css");
when(preferencesService.getAppearancePreferences()).thenReturn(
new AppearancePreferences(false, 0, new Theme(testCss.toString())));
AppearancePreferences appearancePreferences =
new AppearancePreferences(false, 0, new Theme(testCss.toString()));

// ActiveTheme should provide no additionalStylesheet when no file exists
ThemeManager themeManagerCreatedBeforeFileExists = new ThemeManager(preferencesService, new DummyFileUpdateMonitor(), Runnable::run);
ThemeManager themeManagerCreatedBeforeFileExists = new ThemeManager(appearancePreferences, new DummyFileUpdateMonitor(), Runnable::run);
assertEquals(Optional.empty(), themeManagerCreatedBeforeFileExists.getActiveTheme()
.getAdditionalStylesheet(),
"didn't expect additional stylesheet to be available because it didn't exist when theme was created");
Expand All @@ -135,11 +131,11 @@ public void largeCustomThemeNotHeldInMemory() throws IOException {
Files.writeString(largeCssTestFile, testString, StandardOpenOption.APPEND);
}
Files.writeString(largeCssTestFile, " */", StandardOpenOption.APPEND);
when(preferencesService.getAppearancePreferences()).thenReturn(
new AppearancePreferences(false, 0, new Theme(largeCssTestFile.toString())));
AppearancePreferences appearancePreferences =
new AppearancePreferences(false, 0, new Theme(largeCssTestFile.toString()));

// ActiveTheme should provide the large additionalStylesheet that was created before
ThemeManager themeManager = new ThemeManager(preferencesService, new DummyFileUpdateMonitor(), Runnable::run);
ThemeManager themeManager = new ThemeManager(appearancePreferences, new DummyFileUpdateMonitor(), Runnable::run);
Optional<String> cssLocationBeforeRemoved = themeManager.getActiveTheme()
.getAdditionalStylesheet()
.map(StyleSheet::getWebEngineStylesheet);
Expand Down Expand Up @@ -168,9 +164,10 @@ public void installThemeOnScene() throws IOException {

Path testCss = tempFolder.resolve("reload.css");
Files.writeString(testCss, TEST_CSS_CONTENT, StandardOpenOption.CREATE);
when(preferencesService.getAppearancePreferences()).thenReturn(new AppearancePreferences(false, 0, new Theme(testCss.toString())));
AppearancePreferences appearancePreferences =
new AppearancePreferences(false, 0, new Theme(testCss.toString()));

ThemeManager themeManager = new ThemeManager(preferencesService, new DummyFileUpdateMonitor(), Runnable::run);
ThemeManager themeManager = new ThemeManager(appearancePreferences, new DummyFileUpdateMonitor(), Runnable::run);

themeManager.installCss(scene);

Expand All @@ -182,9 +179,10 @@ public void installThemeOnScene() throws IOException {
public void installThemeOnWebEngine() throws IOException {
Path testCss = tempFolder.resolve("reload.css");
Files.writeString(testCss, TEST_CSS_CONTENT, StandardOpenOption.CREATE);
when(preferencesService.getAppearancePreferences()).thenReturn(new AppearancePreferences(false, 0, new Theme(testCss.toString())));
AppearancePreferences appearancePreferences =
new AppearancePreferences(false, 0, new Theme(testCss.toString()));

ThemeManager themeManager = new ThemeManager(preferencesService, new DummyFileUpdateMonitor(), Runnable::run);
ThemeManager themeManager = new ThemeManager(appearancePreferences, new DummyFileUpdateMonitor(), Runnable::run);

CompletableFuture<String> webEngineStyleSheetLocation = new CompletableFuture<>();

Expand All @@ -210,7 +208,8 @@ public void installThemeOnWebEngine() throws IOException {
public void liveReloadCssDataUrl() throws IOException, InterruptedException {
Path testCss = tempFolder.resolve("reload.css");
Files.writeString(testCss, TEST_CSS_CONTENT, StandardOpenOption.CREATE);
when(preferencesService.getAppearancePreferences()).thenReturn(new AppearancePreferences(false, 0, new Theme(testCss.toString())));
AppearancePreferences appearancePreferences =
new AppearancePreferences(false, 0, new Theme(testCss.toString()));

final ThemeManager themeManager;

Expand All @@ -221,7 +220,7 @@ public void liveReloadCssDataUrl() throws IOException, InterruptedException {
// Wait for the watch service to start
Thread.sleep(500);

themeManager = new ThemeManager(preferencesService, fileUpdateMonitor, Runnable::run);
themeManager = new ThemeManager(appearancePreferences, fileUpdateMonitor, Runnable::run);

Scene scene = mock(Scene.class);
when(scene.getStylesheets()).thenReturn(FXCollections.observableArrayList());
Expand Down