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

Watch main css file for change and reapply automatically #3847

Merged
merged 7 commits into from
Mar 18, 2018

Conversation

tobiasdiez
Copy link
Member

@tobiasdiez tobiasdiez commented Mar 14, 2018

With this PR, working on styling and css files should be easier. Css files are now watched for changes and automatically reloaded. Thus JabRef does not have to be restarted in order to apply a new design. In IntellJ you can now start debugging, edit the css and apply the changes by Build > Build project or Run > Reload Changed Classes.

The idea of the ThemeLoader class is to support external css files (next to the jar file) in the future so that users could change the theme on their own.

I'll add a short note documenting this feature to the wiki after this PR gets merged.


  • Change in CHANGELOG.md described
  • Tests created for changes
  • Manually tested changed features in running JabRef
  • Screenshots added in PR description (for bigger UI changes)
  • Ensured that the git commit message is a good one
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

@tobiasdiez tobiasdiez added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Mar 14, 2018
@clarity-bot
Copy link

clarity-bot bot commented Mar 14, 2018

I generated a structure-diff below from pulling d72e463 on JabRef:hotReloadCss into affca25 on JabRef:maintable-beta.

Structure Diff

Copy link
Member

@stefan-kolb stefan-kolb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this code wacthes for CSS file changes all the time in production code? I'm ok with adding this for the dev version but imho something like this shouldn't be inside the release code.

@tobiasdiez
Copy link
Member Author

tobiasdiez commented Mar 14, 2018

@stefan-kolb The idea was actually that external css files are also supported so that the user can edit them directly (in the hope that we can get one or two designers interested, which create a nice theme for us - similar to the dozen of different color schemes for IDEs). The overhead of the change listener should be almost non-existing (and we don't have a method to test for production code, do we?)

@stefan-kolb
Copy link
Member

stefan-kolb commented Mar 14, 2018

We could still use external css files without polling for changes all the time. I don't think its valuable except for debugging/designing purposes. A simple restart of the app if one wants a new CSS theme would totally be standard behavior.

@Siedlerchr
Copy link
Member

When you use ScenicView it has the ability to hook into the css files and you can then achieve the same effect.
Agree with @stefan-kolb that constant polling for a file which does not get changed by most users is useless and produces uncessary IO.

@halirutan
Copy link
Collaborator

I also think polling all the time for CSS changes is too much and I would not expose this feature directly to the user (at least not all the time). However, wouldn't it be possible to merge it anyway, but make the polling turned on by e.g. a command-line switch or a Java environment variable? This would have no impact on the performance of the release version and it would help us and possibly non-existent godlike UI designers with too much time :)

@Siedlerchr Have you actually tried this with JabRef and ScenicView? For inspecting the tree-nodes, it is OK, but changing the style is a pain. It is much more convenient to work in the CSS files, at least with my current experience.

I would really like to see this happen and as long as we only do polling on demand, it should not have a performance impact. @tobiasdiez Do you agree that there is no performance drop without polling?

@tobiasdiez
Copy link
Member Author

The file monitor is now only activated if the css file exists as a direct physical file, i.e. is not bundled in the jar. You guys are of course right that there is no need to monitor a css file in the bundled jar archive.

By the way, if I understand it correctly, then the Watcher does not poll the file for changes but actually registers listeners that fire upon changes (at least for modern OSs). Thus it is very performative and scales to thousands of active file listeners (and the limit lies more in the IOPS needed for registering the listeners). There shouldn't be any noticeable overhead for a few files.

The "live reloading" has now to be turned on by defining -Djabref.main.css
Additionally, the location of the Main.css file can be given as parameter to
this property. This makes it way more convenient when working on the code, because
usually the location of the Main.css is in the build folder. Now, you can
use the Main.css from the source directly.
@halirutan
Copy link
Collaborator

I tested the live reloading from IDEA and it was inconvenient because the watched Main.css was the one from the build folder. I introduced the -Djabref.main.css property that lets you specify the path to the CSS file. In addition, I made it mandatory that the -Djabref.main.css needs to be defined to turn on file polling. Just giving -Djabref.main.css without a parameter, will turn on polling as the version of @tobiasdiez did.

I wanted it to be as convenient for me as possible and I would like to change the source Main.css and not the one in the build folder. If one of the expert designers we expect to arrive soon (:smile:) wants to play with the style, he/she can then use the JabRef.jar and just place a copy of the Main.css wherever he likes. Simply starting

java -Djabref.main.css="/path/to/Main.css" -jar JabRef.jar

lets them turn on live styling.

I have tested this version both from the IDE and from command-line and it seems to work as expected. Can we merge this into the maintable-beta so that I can pull it into my other branch?

Copy link
Member Author

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your changes @halirutan! +1 for merge.

@Siedlerchr
Copy link
Member

If you fix the checkstyle issue (constant names must be uppercase with underscore), we can merge

Co-authored-by: Tobias Diez <[email protected]>
Co-authored-by: Patrick Scheibe <[email protected]>
@Siedlerchr Siedlerchr merged commit 41c66f4 into maintable-beta Mar 18, 2018
@Siedlerchr Siedlerchr deleted the hotReloadCss branch March 18, 2018 14:46
@halirutan
Copy link
Collaborator

@Siedlerchr Thanks! I usually use this format as well, but Tobi used CamelCase and I wasn't sure anymore how we handle this.

Siedlerchr added a commit that referenced this pull request Mar 18, 2018
…esDlg

* upstream/maintable-beta:
  Get rid of journal abbrev loader in linkedFiles (#3862)
  fix build, remove layout prefs, pass journal abbrev loader and prefs where necessary
  Watch main css file for change and reapply automatically (#3847)
  Provides download option in context menu and fixes #3614 (#3824)
  Minor refactoring

# Conflicts:
#	src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants