-
-
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
Support CitationStyles #1928
Support CitationStyles #1928
Conversation
The text of the preferences tab is not completely visible, either reword or adjust the width of the side panel. |
@@ -638,8 +642,12 @@ public void windowClosing(WindowEvent e) { | |||
return; | |||
} | |||
|
|||
if (bp.getPreviewPanel() != null) { | |||
bp.getPreviewPanel().updateLayout(); |
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.
Please rename
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.
fixed
When pressing the up or down button the selected entry becomes deselected and I have to select it again, this can be quite frustrating if I want to move a citation style to the top. Can you please change it so the selected entry stays selected? |
if (CitationStyle.isCitationStyleFile(style)){ | ||
chosenModel.addElement(CitationStyle.createCitationStyleFromFile(style)); | ||
} | ||
else { |
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.
Weird formatting, move this to the end of the line above.
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.
fixed
The preview panel is not being updated after changing the citation style but rather displays always the first selected entry. Steps to reproduce:
|
The preview panel is not being updated after changing the citation style when working with multiple databases. Steps to reproduce:
|
I think it would be great to also add the selected citation styles to the "Export to clipboard" dialog. |
import org.apache.commons.logging.LogFactory; | ||
|
||
|
||
public class CitationStyleWorker extends SwingWorker<String, Void> { |
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.
Please add a javadoc comment.
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.
fixed
When the bugs are fixed and the other minor comments have been addressed then it's fine by me. |
@@ -118,6 +121,12 @@ dependencies { | |||
compile 'org.apache.logging.log4j:log4j-api:2.6.2' | |||
compile 'org.apache.logging.log4j:log4j-core:2.6.2' | |||
|
|||
// need to use snapshots as the stable version is from 2013 and doesn't support v1.0.1 CitationStyles | |||
compile 'org.citationstyles:styles:1.0.1-SNAPSHOT' |
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.
Please also follow https://github.com/JabRef/jabref/blob/master/CONTRIBUTING.md#when-adding-a-library
Is there an issue asking for a release of the library? - If yes, please link it here and open an issue at jabref/issues linking that issue. If no, please either contact the maintainers directly or open an issue at their repo. Also open an issue at jabref/issues.
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.
done
Fixed the Bug (both were caused by the same thing) |
The "export to clipboard" is not important. If some interested user requests it, work on it can be done. |
@@ -12,6 +12,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# | |||
## [Unreleased] | |||
|
|||
### Changed | |||
- Added support for over 1000 (self updating) 1.0.1 Citation Styles | |||
- You can set and cycle different preview Styles (including CitationStyles) |
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.
"styles" with lower case s
/** | ||
* WARNING: The generation of a citation may take some time, better call it in outside the main Thread | ||
*/ | ||
public class CitationStyleGenerator { |
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.
You can also mark the class as protected so that nobody outside of the package can use it (i.e. everybody is forced to use the cache).
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.
^done
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 not package-private?
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 don't like package-private (because writing nothing looks like somebody just forgot to specify the correct visibility)
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.
The code looks really good. Just some minor remarks (mostly around Optionals) and please add a few tests.
@@ -20,6 +20,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# | |||
- The search result Window won't stay on top anymore if the main Window is focused and will be present in the taskbar | |||
- The user can jump from the searchbar to the maintable with `ctrl+enter` | |||
- Implemented [#573 (comment)](https://github.com/JabRef/jabref/issues/573#issuecomment-232284156): Added shortcut: closing the search result window with `ctrl+w` | |||
- Added support for over 1000 1.0.1 CitationStyles |
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.
Maybe reformulate to 1000 citation styles (using CitationStyles 1.0.1) and add link.
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.
done
String style = previewPreferences.getPreviewCycle().get(previewPreferences.getCyclePreviewPosition()); | ||
|
||
if (CitationStyle.isCitationStyleFile(style)) { | ||
if (getBasePanel() != null) { |
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.
basepanel.ifPresent(...) and maybe remove getBasePanel
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.
done
} | ||
} else { | ||
updatePreviewLayout(previewPreferences.getPreviewStyle()); | ||
if (getBasePanel() != null) { |
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.
Same as above
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.
done
|
||
if (citationStyleWorker != null){ |
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.
Make citationStyleWorker also an Optional.
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.
done
.addSearchListener(previewPanel[1]); | ||
|
||
this.preview = previewPanel[activePreview]; | ||
if (panel.getPreviewPanel() != null){ |
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.
Make getPreviewPanel return an Optional
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.
done
} | ||
|
||
public void setCitationStyle(CitationStyle citationStyle) { | ||
if (citationStyle == null || this.citationStyle == citationStyle) { |
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 would guard citationStyle
from being null (Objects.requireNonNull).
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.
done
if (citationStyle == null || this.citationStyle == citationStyle) { | ||
return; | ||
} | ||
if (this.citationStyle == null || !this.citationStyle.getSource().equals(citationStyle.getSource())) { |
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.
Overwrite equals in CitationStyle and reuse here.
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.
done
*/ | ||
@Subscribe | ||
public void listen(EntryChangedEvent entryChangedEvent) { | ||
if (entryChangedEvent != null && entryChangedEvent.getBibEntry() != null){ |
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.
Can the event and/or the BibEntry ever be null?
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.
The event itself shouldn't be null, for its properties there are no null checks.
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.
Then just add Objects.requireNonNull(entryChangedEvent)
and remove the != null
check.
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.
Further please investigate the "call hierarchy" whether getBibEntry()
may ever be null. I don't think so. Thus, please add Objects.requireNonNull(entryChangedEvent.getBibEntry();
.
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.
Is it not more useful to add the Objects.requireNonNull
to the constructor of the EntryEvent
?
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.
The more places the better
LOGGER.error("Bad character inside BibEntry", e); | ||
// sadly one can not easily retrieve the bad char from the TokenMgrError | ||
return new StringBuilder() | ||
.append(Localization.lang("Bad character inside BibEntry")) |
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.
Use a proper word instead of BibEntry
(no idea what we usually use...probably entry
)
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.
entry
was used in other translations
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.
Just look at other localizations.
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.
done
public void getDefault() throws Exception { | ||
Assert.assertNotNull(CitationStyle.getDefault()); | ||
} | ||
|
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.
Please add some tests. At least one test should verify that a BibEntry is properly converted into the correct string.
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 added a Test to check the generated citation with the default citation style on the test bibEntry.
this.basePanel = Optional.ofNullable(panel); | ||
|
||
createPreviewPane(); | ||
updateLayout(); | ||
|
||
if (panel != null) { |
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.
Use this.basePanel
instead here?
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.
done
this.preferences = preferences; | ||
} | ||
|
||
public static void putDefaults(Map<String, Object> defaults) { |
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.
Although there are some classes that use this, as far as I know, the decision is that all constants and all defaults setting should be in JabRefPreferences
.
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.
They are back in JabRefPreferences
.
Is the use of Citation Styles only for the preview pane ? I have downloaded the latest developer version and connected to a LibreOffice document to see if I could use the CSL styles to format my bibliography, but when I open the "Select style" window, only the jstyle format seems to be supported. |
I think, this would be the next logical step: to use Citation Styles in Libre Office. |
Please open a new issue to offer tracking the status. Maybe @oscargus has some time to work on that. |
If I use Biblatex style biblio entries, then I have fields like "journaltitle," "location," and "date" instead of "journal," "address," and "year." These are not picked up by the new Preview citation styles. Further, as reported by boceckts above, one can't get the citation style displayed, so as to edit it. The whole new Preview citation feature is wonderfully helpful. I use it a lot! Thank you. |
Implements #119.
The User can choose multiple CitationStyles which he can cycle threw in the preview panel (forward with F9, backwards shift + F9, both are in the context menu and the menu bar) .
As discussed I removed the 2nd Preview.
Preview before:
Preview after:
Preferences before:
Preferences after:
I didn't include the localization (other the English) on purpose because they create unnecessary conflicts when rebasing quite often (I push them when everything else is fine).
The Help page has to be updated too. I do that as soon as this PR is merged.
Warning: currently I read the available CitationStyles at runtime. I had problems reading them from the gradle dependency thus currently they are only found when JabRef is started from the JAR.