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

Some Globals.prefs injection in logic and model #1593

Merged
merged 17 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed [#1592](https://github.com/JabRef/jabref/issues/1592): LibreOffice: wrong numbers in citation labels

### Removed
- It is not longer possible to choose to convert HTML sub- and superscripts to equations



Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public String htmlToLatexConversion() {
@Benchmark
public boolean keywordGroupContains() throws ParseException {
KeywordGroup group = new KeywordGroup("testGroup", "keyword", "testkeyword", false, false,
GroupHierarchyType.INDEPENDENT);
GroupHierarchyType.INDEPENDENT, Globals.prefs);
return group.containsAll(database.getEntries());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ private static void start(String[] args) {
Globals.prefs.setLanguageDependentDefaultValues();

// Update which fields should be treated as numeric, based on preferences:
InternalBibtexFields.setNumericFieldsFromPrefs();
InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS));

/* Build list of Import and Export formats */
Globals.IMPORT_FORMAT_READER.resetImportFormats();
CustomEntryTypesManager.loadCustomEntryTypes(preferences);
ExportFormats.initAllExports();
ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs));

// Read list(s) of journal names and abbreviations
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void putData(String key, List<String> orderedData) {
*/
private void putGroups(List<String> orderedData) throws ParseException {
try {
groupsRoot = GroupTreeNode.parse(orderedData);
groupsRoot = GroupTreeNode.parse(orderedData, Globals.prefs);
} catch (ParseException e) {
throw new ParseException(Localization.lang(
"Group tree could not be parsed. If you save the BibTeX database, all groups will be lost."), e);
Expand Down Expand Up @@ -238,7 +238,7 @@ public AbstractLabelPattern getLabelPattern() {
return labelPattern;
}

labelPattern = new DatabaseLabelPattern();
labelPattern = new DatabaseLabelPattern(Globals.prefs);

// read the data from the metadata and store it into the labelPattern
for (String key : this) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private void importPreferences() {
try {
Globals.prefs.importPreferences(cli.getPreferencesImport());
CustomEntryTypesManager.loadCustomEntryTypes(Globals.prefs);
ExportFormats.initAllExports();
ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs));
} catch (JabRefException ex) {
LOGGER.error("Cannot import preferences", ex);
}
Expand Down Expand Up @@ -435,7 +435,7 @@ private void regenerateBibtexKeys(List<ParserResult> loaded) {
LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata"));
for (BibEntry entry : database.getEntries()) {
// try to make a new label
LabelPatternUtil.makeLabel(metaData, database, entry);
LabelPatternUtil.makeLabel(metaData, database, entry, Globals.prefs);
}
} else {
LOGGER.info(Localization.lang("No meta data present in bibfile. Cannot regenerate BibTeX keys"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/external/AutoSetLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void run() {
String regExp = Globals.prefs.get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY);
result = RegExpFileSearch.findFilesForSet(entries, extensions, dirs, regExp);
} else {
result = FileUtil.findAssociatedFiles(entries, extensions, dirs);
result = FileUtil.findAssociatedFiles(entries, extensions, dirs, Globals.prefs);
}

boolean foundAny = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ private void downloadFinished() {
// FIXME: will break download if no bibtexkey is present!
private String getSuggestedFileName(String suffix) {
String plannedName = FileUtil.createFileNameFromPattern(databaseContext.getDatabase(),
frame.getCurrentBasePanel().getSelectedEntries().get(0), Globals.journalAbbreviationLoader);
frame.getCurrentBasePanel().getSelectedEntries().get(0), Globals.journalAbbreviationLoader,
Globals.prefs);

if (!suffix.isEmpty()) {
plannedName += "." + suffix;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/external/DroppedFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private boolean tryXmpImport(String fileName, ExternalFileType fileType, NamedCo

List<BibEntry> xmpEntriesInFile;
try {
xmpEntriesInFile = XMPUtil.readXMP(fileName);
xmpEntriesInFile = XMPUtil.readXMP(fileName, Globals.prefs);
} catch (IOException e) {
LOGGER.warn("Problem reading XMP", e);
return false;
Expand Down Expand Up @@ -350,7 +350,8 @@ private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileTy
renameCheckBox.setText(Localization.lang("Rename file to").concat(": "));

// Determine which name to suggest:
String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.journalAbbreviationLoader);
String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.journalAbbreviationLoader,
Globals.prefs);

renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension()));

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/external/MoveFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void actionPerformed(ActionEvent event) {
// Determine which name to suggest:
String suggName = FileUtil
.createFileNameFromPattern(eEditor.getDatabase(), eEditor.getEntry(),
Globals.journalAbbreviationLoader)
Globals.journalAbbreviationLoader, Globals.prefs)
.concat(entry.type.isPresent() ? "." + entry.type.get().getExtension() : "");
CheckBoxMessage cbm = new CheckBoxMessage(Localization.lang("Move file to file directory?"),
Localization.lang("Rename to '%0'", suggName),
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public void run() {
// Finally, set the new keys:
for (BibEntry entry : entries) {
bes = entry;
LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes);
LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes, Globals.prefs);
ce.addEdit(new UndoableKeyChange(database, bes, (String) oldvals.get(bes),
bes.getCiteKey()));
}
Expand Down Expand Up @@ -990,7 +990,7 @@ private void copyKeyAndTitle() {
"\\bibtexkey - \\begin{title}\\format[RemoveBrackets]{\\title}\\end{title}\n");
Layout layout;
try {
layout = new LayoutHelper(sr, Globals.journalAbbreviationLoader).getLayoutFromText();
layout = new LayoutHelper(sr, Globals.prefs, Globals.journalAbbreviationLoader).getLayoutFromText();
} catch (IOException e) {
LOGGER.info("Could not get layout", e);
return;
Expand Down Expand Up @@ -1987,7 +1987,7 @@ public void autoGenerateKeysBeforeSaving() {
for (BibEntry bes : database.getEntries()) {
String oldKey = bes.getCiteKey();
if ((oldKey == null) || oldKey.isEmpty()) {
LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes);
LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes, Globals.prefs);
ce.addEdit(new UndoableKeyChange(database, bes, null, bes.getCiteKey()));
any = true;
}
Expand Down Expand Up @@ -2425,7 +2425,7 @@ public Optional<String> searchAndOpen() {
String regExp = Globals.prefs.get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY);
result = RegExpFileSearch.findFilesForSet(entries, extensions, dirs, regExp);
} else {
result = FileUtil.findAssociatedFiles(entries, extensions, dirs);
result = FileUtil.findAssociatedFiles(entries, extensions, dirs, Globals.prefs);
}
if (result.containsKey(entry)) {
final List<File> res = result.get(entry);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private void generateKeySelectedEntry() {
database.insertEntry(entry);

// Generate a unique key:
LabelPatternUtil.makeLabel(localMetaData, database, entry);
LabelPatternUtil.makeLabel(localMetaData, database, entry, Globals.prefs);
// Remove the entry from the database again, since we only added it in
// order to
// make sure the key was unique:
Expand Down Expand Up @@ -502,7 +502,7 @@ private void generateKeys() {
entry.setId(IdGenerator.next());
database.insertEntry(entry);

LabelPatternUtil.makeLabel(localMetaData, database, entry);
LabelPatternUtil.makeLabel(localMetaData, database, entry, Globals.prefs);
// Add the generated key to our list:
keys.add(entry.getCiteKey());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ private void tearDownJabRef(List<String> filenames) {
}

fileHistory.storeHistory();
prefs.customExports.store();
prefs.customExports.store(Globals.prefs);
prefs.customImports.store();
CustomEntryTypesManager.saveCustomEntryTypes(prefs);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/gui/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public void updateLayout(String layoutFormat) {
private void updateLayout() {
StringReader sr = new StringReader(layoutFile.replace("__NEWLINE__", "\n"));
try {
layout = Optional.of(new LayoutHelper(sr, Globals.journalAbbreviationLoader).getLayoutFromText());
layout = Optional
.of(new LayoutHelper(sr, Globals.prefs, Globals.journalAbbreviationLoader).getLayoutFromText());
} catch (IOException e) {
layout = Optional.empty();
LOGGER.debug("no layout could be set", e);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/sf/jabref/gui/StringDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import net.sf.jabref.gui.undo.UndoableStringChange;
import net.sf.jabref.gui.util.PositionWindow;
import net.sf.jabref.logic.bibtex.LatexFieldFormatter;
import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import net.sf.jabref.logic.bibtex.comparator.BibtexStringComparator;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.database.BibDatabase;
Expand Down Expand Up @@ -266,7 +267,8 @@ public void setValueAt(Object value, int row, int col) {

if (!value.equals(subject.getContent())) {
try {
new LatexFieldFormatter().format((String) value, "__dummy");
new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs))
.format((String) value, "__dummy");
} catch (IllegalArgumentException ex) {
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/sf/jabref/gui/TransferableBibtexEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

import javax.swing.JOptionPane;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.bibtex.BibEntryWriter;
import net.sf.jabref.logic.bibtex.LatexFieldFormatter;
import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -63,7 +65,8 @@ public Object getTransferData(DataFlavor flavor)
} else if (flavor.equals(DataFlavor.stringFlavor)) {
try {
StringWriter sw = new StringWriter();
BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(), false);
BibEntryWriter bibtexEntryWriter = new BibEntryWriter(
new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), false);
for (BibEntry entry : data) {
bibtexEntryWriter.write(entry, sw, BibDatabaseMode.BIBTEX);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/actions/CleanupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private int showDialog(CleanupPresetPanel presetPanel) {
private void doCleanup(CleanupPreset preset, BibEntry entry, NamedCompound ce) {
// Create and run cleaner
BibDatabaseContext bibDatabaseContext = panel.getBibDatabaseContext();
CleanupWorker cleaner = new CleanupWorker(bibDatabaseContext, Globals.journalAbbreviationLoader);
CleanupWorker cleaner = new CleanupWorker(bibDatabaseContext, Globals.journalAbbreviationLoader, Globals.prefs);
List<FieldChange> changes = cleaner.cleanup(preset, entry);

unsuccessfulRenames = cleaner.getUnsuccessfulRenames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.FieldChange;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;
import net.sf.jabref.specialfields.Printed;
import net.sf.jabref.specialfields.Priority;
import net.sf.jabref.specialfields.Quality;
Expand Down Expand Up @@ -321,7 +322,8 @@ private NamedCompound updateKeywords(List<BibEntry> entries, Set<String> keyword
keywords.addAll(keywordsToAdd);

// put keywords back
Optional<FieldChange> change = entry.putKeywords(keywords);
Optional<FieldChange> change = entry.putKeywords(keywords,
Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR));
if (change.isPresent()) {
ce.addEdit(new UndoableFieldChange(change.get()));
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import net.sf.jabref.logic.autocompleter.AutoCompleter;
import net.sf.jabref.logic.bibtex.BibEntryWriter;
import net.sf.jabref.logic.bibtex.LatexFieldFormatter;
import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.logic.search.SearchQueryHighlightListener;
Expand Down Expand Up @@ -592,7 +593,8 @@ public void updateSource() {

public static String getSourceString(BibEntry entry, BibDatabaseMode type) throws IOException {
StringWriter stringWriter = new StringWriter(200);
LatexFieldFormatter formatter = LatexFieldFormatter.buildIgnoreHashes();
LatexFieldFormatter formatter = LatexFieldFormatter
.buildIgnoreHashes(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs));
new BibEntryWriter(formatter, false).writeWithoutPrependedNewlines(entry, stringWriter, type);

return stringWriter.getBuffer().toString();
Expand Down Expand Up @@ -813,7 +815,8 @@ private boolean storeSource() {
String newValue = newEntry.getField(field);
if (!Objects.equals(oldValue, newValue)) {
// Test if the field is legally set.
new LatexFieldFormatter().format(newValue, field);
new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs))
.format(newValue, field);

compound.addEdit(new UndoableFieldChange(entry, field, oldValue, newValue));
entry.setField(field, newValue);
Expand Down Expand Up @@ -1167,7 +1170,8 @@ public void actionPerformed(ActionEvent event) {
// properly formatted. If that happens, the field
// is not stored and the textarea turns red.
if (toSet != null) {
new LatexFieldFormatter().format(toSet, fieldEditor.getFieldName());
new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs))
.format(toSet, fieldEditor.getFieldName());
}

String oldValue = entry.getField(fieldEditor.getFieldName());
Expand Down Expand Up @@ -1362,7 +1366,8 @@ public void actionPerformed(ActionEvent e) {
}
}

LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry);
LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry,
Globals.prefs);

// Store undo information:
panel.getUndoManager().addEdit(new UndoableKeyChange(panel.getDatabase(), entry, (String) oldValue, entry.getCiteKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import net.sf.jabref.gui.fieldeditors.FieldEditor;
import net.sf.jabref.gui.mergeentries.MergeEntryDOIDialog;
import net.sf.jabref.gui.undo.UndoableFieldChange;
import net.sf.jabref.logic.journals.JournalAbbreviationPreferences;
import net.sf.jabref.logic.journals.JournalAbbreviationRepository;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.net.URLUtil;
Expand Down Expand Up @@ -93,7 +94,8 @@ public static Optional<JComponent> getJournalExtraComponent(JabRefFrame frame, B
button.setToolTipText(ABBREVIATION_TOOLTIP_TEXT);
button.addActionListener(actionEvent -> {
String text = editor.getText();
JournalAbbreviationRepository abbreviationRepository = Globals.journalAbbreviationLoader.getRepository();
JournalAbbreviationRepository abbreviationRepository = Globals.journalAbbreviationLoader
.getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs));
if (abbreviationRepository.isKnownName(text)) {
String s = abbreviationRepository.getNextAbbreviation(text).orElse(text);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/exporter/ExportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public InternalExportAction(JabRefFrame frame, boolean selectedOnly) {

@Override
public void actionPerformed(ActionEvent e) {
ExportFormats.initAllExports();
ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs));
JFileChooser fc = ExportAction
.createExportFileChooser(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY));
fc.showSaveDialog(frame);
Expand Down
Loading