-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Improve database writer #718
Conversation
Could you rebase this on master as both pre-requisite PRs are already merged in. So this could be completed now. |
866af07
to
3fbc0a2
Compare
One question: currently the save methods take parameters |
I guess that if this is merged in first, it should be quite OK to rebase #762 (although many changes are redundant). Regarding your question: it would be nice to be able to save like this, but I guess it is another of JabRefs almost finished/commented out and then removed features... Considering that one can save selected entries and it is quite easy to see which entries are in the active group/search selection, I'd say remove. |
b6b728a
to
0b6a839
Compare
I think the code is now mature enough to be reviewed. I added some notes above in the first post. Sorry that this PR is rather big. |
@@ -32,8 +32,6 @@ public BibDatabaseContext(BibDatabase database, MetaData metaData, Defaults defa | |||
this.defaults = Objects.requireNonNull(defaults); | |||
this.database = Objects.requireNonNull(database); | |||
this.metaData = Objects.requireNonNull(metaData); | |||
|
|||
this.setMode(getMode()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you delete this? What happens if you load a bib file and save it afterwards - is there a comment about the type stored in the file then still?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the line because otherwise the biblatex mode would be written every time even if it is the default one. In addition, I found it irritating that a constructor changed values in the parameters passed to it (just using a metadata in a specific context shouldn't change it values).
But yes, the biblatex mode is correctly written. I added a test for it now.
I also pushed it to the branch JabRef/databaseWriter so that a build should be available under http://builds.jabref.org/. |
Do we have the "only update if it changed" functionality for the preamble, strings and comments as well? |
For strings and the epilogue yes, for the preamble kind of (the text in the preamble is stored and exactly rewritten, but the preamble tag and newlines around it are not stored). For the metadata there is no such functionality. |
@tobiasdiez Regarding the two parameters (#718 (comment)): Aren't they used for "Save selected as plain BibTeX..."? |
@koppor No it is not used for this function. "Save selected..." gets all the selected items and pass them to the save function. The code in question reads if (selectedOnly) {
session = FileActions.savePartOfDatabase(
panel.getBibDatabaseContext(),
file, Globals.prefs,
panel.getSelectedEntries(), encoding, FileActions.DatabaseSaveType.DEFAULT);
} else {
session = FileActions.saveDatabase(panel.getBibDatabaseContext(),
file, Globals.prefs, false, false, encoding, false);
} |
Please rebase. I think this should be merged. One suggestion regarding the SavePreferences: You could create a new instance after the call of a setter. This would result in the benefits of having final variables and it still allows to create derivations of this.
|
Combine saveDatabase and savePartOfDatabase to one underlying method. Introduce new class SavePreferences which controls how the database is written. Move a few methods from the writer to another class (like `getReader`) or from another place to the writer (like `writeMetaData`)
Extract display of order config from DatabasePropertiesDialog and FileSortTab to special class which can be reused.
…ialization Also adds a lot of tests for serialization (and a few to the parser)
17c9086
to
4557efb
Compare
Rebased and implemented the |
In my case (JabRef 3.2 on 32- and 64-bit Windows the problem is not fixed. Original lines @Preamble{{\providecommand{\noopsort}[1]{}}} (or @Preamble ...) are always changed to after saving changed bib file. Kind regards, |
@jkomelj You have to use the latest development version or wait for the release of 3.3 (probably in 1-2 weeks) |
Thank you |
The aim of this PR is to improve the database writer, in particular fix #621 and #669.
Also add tests to the writer and parser (and do some refactorings to make test writing easier).
Changes (to serialization):
@Comment
instead of@comment
and@Preamble
instead of@PREAMBLE
. This should follow the convention for entries.@String
and the bracket and after the bracket, i.e.@String{name = {string}}
instead of@String { name = {string} }
Refactorings: