-
-
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 9 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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import java.awt.event.MouseEvent; | ||
import java.awt.event.MouseMotionAdapter; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
@@ -25,12 +26,14 @@ | |
import javax.swing.event.ListDataEvent; | ||
import javax.swing.event.ListDataListener; | ||
|
||
import net.sf.jabref.JabRefGUI; | ||
import net.sf.jabref.logic.cleanup.Cleanups; | ||
import net.sf.jabref.logic.l10n.Localization; | ||
import net.sf.jabref.model.cleanup.FieldFormatterCleanup; | ||
import net.sf.jabref.model.cleanup.FieldFormatterCleanups; | ||
import net.sf.jabref.model.cleanup.Formatter; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
import net.sf.jabref.model.entry.FieldName; | ||
import net.sf.jabref.model.entry.InternalBibtexFields; | ||
import net.sf.jabref.model.metadata.MetaData; | ||
|
||
|
@@ -49,6 +52,7 @@ public class FieldFormatterCleanupsPanel extends JPanel { | |
private JTextArea descriptionAreaText; | ||
private JButton removeButton; | ||
private JButton resetButton; | ||
private JButton recommendButton; | ||
|
||
private final FieldFormatterCleanups defaultFormatters; | ||
|
||
|
@@ -131,12 +135,32 @@ public void contentsChanged(ListDataEvent e) { | |
resetButton = new JButton(Localization.lang("Reset")); | ||
resetButton.addActionListener(e -> ((CleanupActionsListModel) actionsList.getModel()).reset(defaultFormatters)); | ||
|
||
boolean isBibTeX = !JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabaseContext().isBiblatexMode(); | ||
String mode; | ||
|
||
if (isBibTeX) { | ||
mode = "BibTeX"; | ||
} else { | ||
mode = "BibLaTeX"; | ||
} | ||
|
||
recommendButton = new JButton(Localization.lang("Recommended for %0", mode)); | ||
recommendButton.addActionListener(e -> { | ||
|
||
if (isBibTeX) { | ||
((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBTEX_ACTIONS); | ||
} else { | ||
((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBLATEX_ACTIONS); | ||
} | ||
}); | ||
|
||
removeButton = new JButton(Localization.lang("Remove selected")); | ||
removeButton.addActionListener( | ||
e -> ((CleanupActionsListModel) actionsList.getModel()).removeAtIndex(actionsList.getSelectedIndex())); | ||
|
||
builder.add(removeButton).xy(7, 11); | ||
builder.add(resetButton).xy(3, 11); | ||
builder.add(recommendButton).xy(5, 11); | ||
builder.add(getSelectorPanel()).xyw(3, 15, 5); | ||
|
||
makeDescriptionTextAreaLikeJLabel(); | ||
|
@@ -193,8 +217,7 @@ private JPanel getSelectorPanel() { | |
"pref, 2dlu, pref:grow, 2dlu")); | ||
|
||
List<String> fieldNames = InternalBibtexFields.getAllPublicFieldNames(); | ||
fieldNames.add(BibEntry.KEY_FIELD); | ||
fieldNames.add("all"); | ||
fieldNames.addAll(Arrays.asList(BibEntry.KEY_FIELD, FieldName.ABSTRACT_ALL_FIELD, FieldName.ABSTRACT_ALL_TEXT_FIELDS_FIELD)); | ||
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. I would do three calls using 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. and extract it to a new method |
||
Collections.sort(fieldNames); | ||
String[] allPlusKey = fieldNames.toArray(new String[fieldNames.size()]); | ||
|
||
|
@@ -305,6 +328,7 @@ private void setStatus(boolean status) { | |
addButton.setEnabled(status); | ||
removeButton.setEnabled(status); | ||
resetButton.setEnabled(status); | ||
recommendButton.setEnabled(status); | ||
|
||
} | ||
} | ||
|
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,35 @@ | |
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())); | ||
defaultFormatters.add(new FieldFormatterCleanup(FieldName.ABSTRACT_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. Maybe we should stay with 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. I would completely remove the OrdinalsToSuperscript from the defaults. 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 remove of OrdinalsToSuperscript ??? |
||
DEFAULT_SAVE_ACTIONS = new FieldFormatterCleanups(false, defaultFormatters); | ||
|
||
List<FieldFormatterCleanup> recommendedBibTeXFormatters = new ArrayList<>(defaultFormatters); | ||
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. Make it more clear that default formatters are also added: (same for biblatex) |
||
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())); | ||
RECOMMEND_BIBTEX_ACTIONS = new FieldFormatterCleanups(false, recommendedBibTeXFormatters); | ||
|
||
List<FieldFormatterCleanup> recommendedBibLaTeXFormatters = new ArrayList<>(defaultFormatters); | ||
recommendedBibLaTeXFormatters.add(new FieldFormatterCleanup(FieldName.TITLE, new HtmlToUnicodeFormatter())); | ||
recommendedBibLaTeXFormatters.add(new FieldFormatterCleanup(FieldName.ABSTRACT_ALL_TEXT_FIELDS_FIELD, new LatexToUnicodeFormatter())); | ||
RECOMMEND_BIBLATEX_ACTIONS = new FieldFormatterCleanups(false, recommendedBibLaTeXFormatters); | ||
} | ||
|
||
public static List<Formatter> getAvailableFormatters() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package net.sf.jabref.model.cleanup; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
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 +27,10 @@ public FieldFormatterCleanup(String field, Formatter formatter) { | |
|
||
@Override | ||
public List<FieldChange> cleanup(BibEntry entry) { | ||
if ("all".equalsIgnoreCase(field)) { | ||
if (FieldName.ABSTRACT_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.ABSTRACT_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 +78,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(Arrays.asList(FieldName.DOI, FieldName.FILE, FieldName.URL, FieldName.URI, FieldName.ISBN, FieldName.ISSN, FieldName.MONTH, FieldName.DATE, FieldName.YEAR)); | ||
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. return these fields from a new method |
||
for (String fieldKey : fields) { | ||
fieldChanges.addAll(cleanupSingleField(fieldKey, entry)); | ||
} | ||
|
||
return fieldChanges; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,17 +45,10 @@ | |
import net.sf.jabref.logic.citationstyle.CitationStyle; | ||
import net.sf.jabref.logic.cleanup.CleanupPreferences; | ||
import net.sf.jabref.logic.cleanup.CleanupPreset; | ||
import net.sf.jabref.logic.cleanup.Cleanups; | ||
import net.sf.jabref.logic.exporter.CustomExportList; | ||
import net.sf.jabref.logic.exporter.ExportComparator; | ||
import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; | ||
import net.sf.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter; | ||
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.UnitsToLatexFormatter; | ||
import net.sf.jabref.logic.formatter.casechanger.ProtectTermsFormatter; | ||
import net.sf.jabref.logic.importer.ImportFormatPreferences; | ||
import net.sf.jabref.logic.importer.Importer; | ||
import net.sf.jabref.logic.journals.JournalAbbreviationLoader; | ||
import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; | ||
import net.sf.jabref.logic.l10n.Localization; | ||
|
@@ -76,8 +69,6 @@ | |
import net.sf.jabref.logic.xmp.XMPPreferences; | ||
import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; | ||
import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; | ||
import net.sf.jabref.model.cleanup.FieldFormatterCleanup; | ||
import net.sf.jabref.model.cleanup.FieldFormatterCleanups; | ||
import net.sf.jabref.model.database.BibDatabaseMode; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
import net.sf.jabref.model.entry.CustomEntryType; | ||
|
@@ -346,24 +337,6 @@ public class JabRefPreferences { | |
public static final String CLEANUP_CONVERT_TO_BIBLATEX = "CleanUpConvertToBiblatex"; | ||
public static final String CLEANUP_FIX_FILE_LINKS = "CleanUpFixFileLinks"; | ||
public static final String CLEANUP_FORMATTERS = "CleanUpFormatters"; | ||
public static final CleanupPreset CLEANUP_DEFAULT_PRESET; | ||
static { | ||
EnumSet<CleanupPreset.CleanupStep> deactivedJobs = EnumSet.of( | ||
CleanupPreset.CleanupStep.CLEAN_UP_UPGRADE_EXTERNAL_LINKS, | ||
CleanupPreset.CleanupStep.RENAME_PDF_ONLY_RELATIVE_PATHS, | ||
CleanupPreset.CleanupStep.CONVERT_TO_BIBLATEX); | ||
|
||
List<FieldFormatterCleanup> activeFormatterCleanups = new ArrayList<>(); | ||
activeFormatterCleanups.add(new FieldFormatterCleanup(FieldName.PAGES, new NormalizePagesFormatter())); | ||
activeFormatterCleanups.add(new FieldFormatterCleanup(FieldName.DATE, new NormalizeDateFormatter())); | ||
activeFormatterCleanups.add(new FieldFormatterCleanup(FieldName.MONTH, new NormalizeMonthFormatter())); | ||
activeFormatterCleanups.add(new FieldFormatterCleanup(FieldName.TITLE, new ProtectTermsFormatter())); | ||
activeFormatterCleanups.add(new FieldFormatterCleanup(FieldName.TITLE, new UnitsToLatexFormatter())); | ||
activeFormatterCleanups.add(new FieldFormatterCleanup(FieldName.TITLE, new LatexCleanupFormatter())); | ||
activeFormatterCleanups.add(new FieldFormatterCleanup(FieldName.TITLE, new HtmlToLatexFormatter())); | ||
FieldFormatterCleanups formatterCleanups = new FieldFormatterCleanups(true, activeFormatterCleanups); | ||
CLEANUP_DEFAULT_PRESET = new CleanupPreset(EnumSet.complementOf(deactivedJobs), formatterCleanups); | ||
} | ||
|
||
public static final String IMPORT_DEFAULT_PDF_IMPORT_STYLE = "importDefaultPDFimportStyle"; | ||
public static final String IMPORT_ALWAYSUSE = "importAlwaysUsePDFImportStyle"; | ||
|
@@ -797,7 +770,7 @@ private JabRefPreferences() { | |
defaults.put(DB_CONNECT_USERNAME, "root"); | ||
|
||
defaults.put(ASK_AUTO_NAMING_PDFS_AGAIN, Boolean.TRUE); | ||
insertCleanupPreset(defaults, CLEANUP_DEFAULT_PRESET); | ||
insertCleanupPreset(defaults); | ||
|
||
// defaults for DroppedFileHandler UI | ||
defaults.put(DROPPEDFILEHANDLER_LEAVE, Boolean.FALSE); | ||
|
@@ -1352,7 +1325,14 @@ public void setDefaultEncoding(Charset encoding) { | |
put(DEFAULT_ENCODING, encoding.name()); | ||
} | ||
|
||
private static void insertCleanupPreset(Map<String, Object> storage, CleanupPreset preset) { | ||
private static void insertCleanupPreset(Map<String, Object> storage) { | ||
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. rename method to |
||
EnumSet<CleanupPreset.CleanupStep> deactivedJobs = EnumSet.of( | ||
CleanupPreset.CleanupStep.CLEAN_UP_UPGRADE_EXTERNAL_LINKS, | ||
CleanupPreset.CleanupStep.RENAME_PDF_ONLY_RELATIVE_PATHS, | ||
CleanupPreset.CleanupStep.CONVERT_TO_BIBLATEX); | ||
|
||
CleanupPreset preset = new CleanupPreset(EnumSet.complementOf(deactivedJobs), Cleanups.DEFAULT_SAVE_ACTIONS); | ||
|
||
storage.put(CLEANUP_DOI, preset.isCleanUpDOI()); | ||
storage.put(CLEANUP_ISSN, preset.isCleanUpISSN()); | ||
storage.put(CLEANUP_MOVE_PDF, preset.isMovePDF()); | ||
|
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 😄