-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Create sensible default settings for "Enable save actions" and "Cleanup" dialogs #2051
Changes from 12 commits
67d35cb
e3c0031
0a3d823
e209e5a
d597ad9
897fb9e
704eca7
e4afabf
75497c1
c3dee55
d18bbce
5677942
b15e7fa
b593ced
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,14 @@ | |
|
||
import net.sf.jabref.logic.formatter.Formatters; | ||
import net.sf.jabref.logic.formatter.IdentityFormatter; | ||
import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; | ||
import net.sf.jabref.logic.formatter.bibtexfields.HtmlToUnicodeFormatter; | ||
import net.sf.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter; | ||
import net.sf.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter; | ||
import net.sf.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; | ||
import net.sf.jabref.logic.formatter.bibtexfields.OrdinalsToSuperscriptFormatter; | ||
import net.sf.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; | ||
import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter; | ||
import net.sf.jabref.model.cleanup.FieldFormatterCleanup; | ||
import net.sf.jabref.model.cleanup.FieldFormatterCleanups; | ||
import net.sf.jabref.model.cleanup.Formatter; | ||
|
@@ -18,17 +23,38 @@ | |
public class Cleanups { | ||
|
||
public static final FieldFormatterCleanups DEFAULT_SAVE_ACTIONS; | ||
public static final FieldFormatterCleanups RECOMMEND_BIBTEX_ACTIONS; | ||
public static final FieldFormatterCleanups RECOMMEND_BIBLATEX_ACTIONS; | ||
public static List<Formatter> availableFormatters; | ||
|
||
|
||
static { | ||
availableFormatters = new ArrayList<>(); | ||
availableFormatters.addAll(Formatters.ALL); | ||
|
||
List<FieldFormatterCleanup> defaultFormatters = new ArrayList<>(); | ||
defaultFormatters.add(new FieldFormatterCleanup(FieldName.PAGES, new NormalizePagesFormatter())); | ||
defaultFormatters.add(new FieldFormatterCleanup(FieldName.DATE, new NormalizeDateFormatter())); | ||
defaultFormatters.add(new FieldFormatterCleanup(FieldName.MONTH, new NormalizeMonthFormatter())); | ||
defaultFormatters.add(new FieldFormatterCleanup(FieldName.BOOKTITLE, new OrdinalsToSuperscriptFormatter())); | ||
DEFAULT_SAVE_ACTIONS = new FieldFormatterCleanups(false, defaultFormatters); | ||
|
||
List<FieldFormatterCleanup> recommendedBibTeXFormatters = new ArrayList<>(); | ||
recommendedBibTeXFormatters.addAll(defaultFormatters); | ||
recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.TITLE, new HtmlToLatexFormatter())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to not run the HTML/Unicode -> Latex converter on all [text] fields? Similar question for the Latex/HTML -> Unicode for biblatex. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @koppor what do you think about that ??? 😄 |
||
recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.TITLE, new UnicodeToLatexFormatter())); | ||
recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.BOOKTITLE, new UnicodeToLatexFormatter())); | ||
recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.JOURNAL, new UnicodeToLatexFormatter())); | ||
recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.AUTHOR, new UnicodeToLatexFormatter())); | ||
recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.EDITOR, new UnicodeToLatexFormatter())); | ||
defaultFormatters.add(new FieldFormatterCleanup(FieldName.INTERNAL_ALL_TEXT_FIELDS_FIELD, new OrdinalsToSuperscriptFormatter())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. recommendedBibTeXFormatters instead of defaultFormatters (same below) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its still "defaultFormatters" here instead of "recommendedBibTeXFormatters".... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 😄 |
||
RECOMMEND_BIBTEX_ACTIONS = new FieldFormatterCleanups(false, recommendedBibTeXFormatters); | ||
|
||
List<FieldFormatterCleanup> recommendedBibLaTeXFormatters = new ArrayList<>(); | ||
recommendedBibLaTeXFormatters.addAll(defaultFormatters); | ||
recommendedBibLaTeXFormatters.add(new FieldFormatterCleanup(FieldName.TITLE, new HtmlToUnicodeFormatter())); | ||
recommendedBibLaTeXFormatters.add(new FieldFormatterCleanup(FieldName.INTERNAL_ALL_TEXT_FIELDS_FIELD, new LatexToUnicodeFormatter())); | ||
defaultFormatters.add(new FieldFormatterCleanup(FieldName.INTERNAL_ALL_TEXT_FIELDS_FIELD, new OrdinalsToSuperscriptFormatter())); | ||
RECOMMEND_BIBLATEX_ACTIONS = new FieldFormatterCleanups(false, recommendedBibLaTeXFormatters); | ||
} | ||
|
||
public static List<Formatter> getAvailableFormatters() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import net.sf.jabref.model.FieldChange; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
import net.sf.jabref.model.entry.FieldName; | ||
import net.sf.jabref.model.entry.event.EntryEventSource; | ||
|
||
/** | ||
|
@@ -24,8 +26,10 @@ public FieldFormatterCleanup(String field, Formatter formatter) { | |
|
||
@Override | ||
public List<FieldChange> cleanup(BibEntry entry) { | ||
if ("all".equalsIgnoreCase(field)) { | ||
if (FieldName.INTERNAL_ALL_FIELD.equalsIgnoreCase(field)) { | ||
return cleanupAllFields(entry); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to add test coverage here? - This branch is not covered by test cases. |
||
} else if (FieldName.INTERNAL_ALL_TEXT_FIELDS_FIELD.equalsIgnoreCase(field)) { | ||
return cleanupAllTextFields(entry); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please also cover by test cases |
||
} else { | ||
return cleanupSingleField(field, entry); | ||
} | ||
|
@@ -73,6 +77,17 @@ private List<FieldChange> cleanupAllFields(BibEntry entry) { | |
return fieldChanges; | ||
} | ||
|
||
private List<FieldChange> cleanupAllTextFields(BibEntry entry) { | ||
List<FieldChange> fieldChanges = new ArrayList<>(); | ||
Set<String> fields = entry.getFieldNames(); | ||
fields.removeAll(FieldName.getNotTextFieldNames()); | ||
for (String fieldKey : fields) { | ||
fieldChanges.addAll(cleanupSingleField(fieldKey, entry)); | ||
} | ||
|
||
return fieldChanges; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
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.
work with "isBibLatex" instead of negating it.
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 😄