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

Rename labelpattern to bibtexkeypattern and fix pref issue #1704

Merged
merged 9 commits into from
Aug 11, 2016
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Unified dialogs for opening/saving files

### Fixed
- Fixed [#1632](https://github.com/JabRef/jabref/issues/1632) User comments (@Comment) with or without brackets are now kept
- Fixed [#1632](https://github.com/JabRef/jabref/issues/1632): User comments (@Comment) with or without brackets are now kept
- Fixed [#1264](https://github.com/JabRef/jabref/issues/1264): S with caron does not render correctly
- LaTeX to Unicode converter now handles combining accents
- Fixed NullPointerException when clicking Browse in Journal abbreviations with empty text field
Expand All @@ -57,6 +57,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed NullPointerException when clicking OK without specifying a field name in set/clear/rename fields
- Fixed IndexOutOfBoundsException when trying to download a full text document without selecting an entry
- Fixed NullPointerException when trying to set a special field or mark an entry through the menu without having an open database
- Fixed [#1257](https://github.com/JabRef/jabref/issues/1324): Preferences for the BibTeX key generator set in a version prior to 3.2 are now migrated automatically to the new version

### Removed
- It is not longer possible to choose to convert HTML sub- and superscripts to equations
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/sf/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private void openWindow() {
// Perform checks and changes for users with a preference set from an older JabRef version.
PreferencesMigrations.upgradeSortOrder();
PreferencesMigrations.upgradeFaultyEncodingStrings();
PreferencesMigrations.upgradeLabelPatternToBibtexKeyPattern();

// This property is set to make the Mac OSX Java VM move the menu bar to the top of the screen
if (OS.OS_X) {
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/net/sf/jabref/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
import net.sf.jabref.logic.layout.format.FileLinkPreferences;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern;
import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.labelpattern.AbstractLabelPattern;
import net.sf.jabref.model.labelpattern.DatabaseLabelPattern;

import com.google.common.eventbus.EventBus;
import org.apache.commons.logging.Log;
Expand All @@ -70,7 +70,7 @@ public class MetaData implements Iterable<String> {
private GroupTreeNode groupsRoot;
private final EventBus eventBus = new EventBus();

private AbstractLabelPattern labelPattern;
private AbstractBibtexKeyPattern bibtexKeyPattern;

private Charset encoding = Globals.prefs.getDefaultEncoding();

Expand Down Expand Up @@ -239,36 +239,36 @@ private static Optional<String> getNextUnit(Reader reader) throws IOException {
/**
* @return the stored label patterns
*/
public AbstractLabelPattern getLabelPattern() {
if (labelPattern != null) {
return labelPattern;
public AbstractBibtexKeyPattern getBibtexKeyPattern() {
if (bibtexKeyPattern != null) {
return bibtexKeyPattern;
}

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

// read the data from the metadata and store it into the labelPattern
// read the data from the metadata and store it into the bibtexKeyPattern
for (String key : this) {
if (key.startsWith(PREFIX_KEYPATTERN)) {
List<String> value = getData(key);
String type = key.substring(PREFIX_KEYPATTERN.length());
labelPattern.addLabelPattern(type, value.get(0));
bibtexKeyPattern.addBibtexKeyPattern(type, value.get(0));
}
}
List<String> defaultPattern = getData(KEYPATTERNDEFAULT);
if (defaultPattern != null) {
labelPattern.setDefaultValue(defaultPattern.get(0));
bibtexKeyPattern.setDefaultValue(defaultPattern.get(0));
}

return labelPattern;
return bibtexKeyPattern;
}

/**
* Updates the stored key patterns to the given key patterns.
*
* @param labelPattern the key patterns to update to. <br />
* A reference to this object is stored internally and is returned at getLabelPattern();
* @param bibtexKeyPattern the key patterns to update to. <br />
* A reference to this object is stored internally and is returned at getBibtexKeyPattern();
*/
public void setLabelPattern(AbstractLabelPattern labelPattern) {
public void setBibtexKeyPattern(AbstractBibtexKeyPattern bibtexKeyPattern) {
// remove all keypatterns from metadata
Iterator<String> iterator = this.iterator();
while (iterator.hasNext()) {
Expand All @@ -279,26 +279,26 @@ public void setLabelPattern(AbstractLabelPattern labelPattern) {
}

// set new value if it is not a default value
Set<String> allKeys = labelPattern.getAllKeys();
Set<String> allKeys = bibtexKeyPattern.getAllKeys();
for (String key : allKeys) {
String metaDataKey = PREFIX_KEYPATTERN + key;
if (!labelPattern.isDefaultValue(key)) {
if (!bibtexKeyPattern.isDefaultValue(key)) {
List<String> data = new ArrayList<>();
data.add(labelPattern.getValue(key).get(0));
data.add(bibtexKeyPattern.getValue(key).get(0));
this.putData(metaDataKey, data);
}
}

// store default pattern
if (labelPattern.getDefaultValue() == null) {
if (bibtexKeyPattern.getDefaultValue() == null) {
this.remove(KEYPATTERNDEFAULT);
} else {
List<String> data = new ArrayList<>();
data.add(labelPattern.getDefaultValue().get(0));
data.add(bibtexKeyPattern.getDefaultValue().get(0));
this.putData(KEYPATTERNDEFAULT, data);
}

this.labelPattern = labelPattern;
this.bibtexKeyPattern = bibtexKeyPattern;
}

public Optional<FieldFormatterCleanups> getSaveActions() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/sf/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import net.sf.jabref.importer.fetcher.EntryFetcher;
import net.sf.jabref.importer.fetcher.EntryFetchers;
import net.sf.jabref.logic.CustomEntryTypesManager;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.exporter.BibDatabaseWriter;
import net.sf.jabref.logic.exporter.BibtexDatabaseWriter;
import net.sf.jabref.logic.exporter.ExportFormats;
Expand All @@ -35,8 +37,6 @@
import net.sf.jabref.logic.exporter.SavePreferences;
import net.sf.jabref.logic.exporter.SaveSession;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternPreferences;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.logic.logging.JabRefLogger;
import net.sf.jabref.logic.search.DatabaseSearcher;
import net.sf.jabref.logic.search.SearchQuery;
Expand Down Expand Up @@ -434,8 +434,8 @@ 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,
LabelPatternPreferences.fromPreferences(Globals.prefs));
BibtexKeyPatternUtil.makeLabel(metaData, database, entry,
BibtexKeyPatternPreferences.fromPreferences(Globals.prefs));
}
} else {
LOGGER.info(Localization.lang("No meta data present in BIB_file. Cannot regenerate BibTeX keys"));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/external/RegExpFileSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -331,7 +331,7 @@ public static String getFieldAndFormat(String fieldAndFormat, BibEntry entry, Bi

// If no field value was found, try to interpret it as a key generator field marker:
String fieldValue = BibDatabase.getResolvedField(beforeColon, entry, database)
.orElse(LabelPatternUtil.makeLabel(entry, beforeColon));
.orElse(BibtexKeyPatternUtil.makeLabel(entry, beforeColon));

if (fieldValue == null) {
return "";
Expand All @@ -342,7 +342,7 @@ public static String getFieldAndFormat(String fieldAndFormat, BibEntry entry, Bi
}

String[] parts = afterColon.split(":");
fieldValue = LabelPatternUtil.applyModifiers(fieldValue, parts, 0);
fieldValue = BibtexKeyPatternUtil.applyModifiers(fieldValue, parts, 0);

return fieldValue;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import net.sf.jabref.gui.actions.Actions;
import net.sf.jabref.gui.actions.BaseAction;
import net.sf.jabref.gui.actions.CleanupAction;
import net.sf.jabref.gui.bibtexkeypattern.SearchFixDuplicateLabels;
import net.sf.jabref.gui.desktop.JabRefDesktop;
import net.sf.jabref.gui.entryeditor.EntryEditor;
import net.sf.jabref.gui.exporter.ExportToClipboardAction;
Expand All @@ -82,7 +83,6 @@
import net.sf.jabref.gui.groups.GroupTreeNodeViewModel;
import net.sf.jabref.gui.journals.AbbreviateAction;
import net.sf.jabref.gui.journals.UnabbreviateAction;
import net.sf.jabref.gui.labelpattern.SearchFixDuplicateLabels;
import net.sf.jabref.gui.maintable.MainTable;
import net.sf.jabref.gui.maintable.MainTableDataModel;
import net.sf.jabref.gui.maintable.MainTableFormat;
Expand Down Expand Up @@ -110,15 +110,15 @@
import net.sf.jabref.logic.autocompleter.AutoCompleter;
import net.sf.jabref.logic.autocompleter.AutoCompleterFactory;
import net.sf.jabref.logic.autocompleter.ContentAutoCompleters;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.exporter.BibtexDatabaseWriter;
import net.sf.jabref.logic.exporter.FileSaveSession;
import net.sf.jabref.logic.exporter.SaveException;
import net.sf.jabref.logic.exporter.SavePreferences;
import net.sf.jabref.logic.exporter.SaveSession;
import net.sf.jabref.logic.l10n.Encodings;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternPreferences;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.logic.layout.Layout;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.layout.LayoutHelper;
Expand Down Expand Up @@ -493,8 +493,8 @@ public void run() {
// Finally, set the new keys:
for (BibEntry entry : entries) {
bes = entry;
LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes,
LabelPatternPreferences.fromPreferences(Globals.prefs));
BibtexKeyPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes,
BibtexKeyPatternPreferences.fromPreferences(Globals.prefs));
ce.addEdit(new UndoableKeyChange(database, bes, (String) oldvals.get(bes),
bes.getCiteKeyOptional().orElse(null)));
}
Expand Down Expand Up @@ -1930,8 +1930,8 @@ public void autoGenerateKeysBeforeSaving() {
for (BibEntry bes : database.getEntries()) {
Optional<String> oldKey = bes.getCiteKeyOptional();
if (!(oldKey.isPresent()) || oldKey.get().isEmpty()) {
LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes,
LabelPatternPreferences.fromPreferences(Globals.prefs));
BibtexKeyPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes,
BibtexKeyPatternPreferences.fromPreferences(Globals.prefs));
ce.addEdit(new UndoableKeyChange(database, bes, null, bes.getCiteKeyOptional().get())); // Cite key is set here
any = true;
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@
import javax.swing.WindowConstants;

import net.sf.jabref.MetaData;
import net.sf.jabref.gui.bibtexkeypattern.BibtexKeyPatternPanel;
import net.sf.jabref.gui.keyboard.KeyBinder;
import net.sf.jabref.gui.labelpattern.LabelPatternPanel;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.labelpattern.AbstractLabelPattern;
import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern;

import com.jgoodies.forms.builder.ButtonBarBuilder;

public class BibtexKeyPatternDialog extends JDialog {

private MetaData metaData;
private BasePanel panel;
private final LabelPatternPanel labelPatternPanel;
private final BibtexKeyPatternPanel bibtexKeyPatternPanel;


public BibtexKeyPatternDialog(JabRefFrame parent, BasePanel panel) {
super(parent, Localization.lang("BibTeX key patterns"), true);
this.labelPatternPanel = new LabelPatternPanel(panel);
this.bibtexKeyPatternPanel = new BibtexKeyPatternPanel(panel);
setPanel(panel);
init();
}
Expand All @@ -58,13 +58,13 @@ public BibtexKeyPatternDialog(JabRefFrame parent, BasePanel panel) {
public void setPanel(BasePanel panel) {
this.panel = panel;
this.metaData = panel.getBibDatabaseContext().getMetaData();
AbstractLabelPattern keypatterns = metaData.getLabelPattern();
labelPatternPanel.setValues(keypatterns);
AbstractBibtexKeyPattern keypatterns = metaData.getBibtexKeyPattern();
bibtexKeyPatternPanel.setValues(keypatterns);
}

private void init() {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(labelPatternPanel, BorderLayout.CENTER);
getContentPane().add(bibtexKeyPatternPanel, BorderLayout.CENTER);

JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(); // label of "cancel" is set later as the label is overwritten by assigning an action to the button
Expand All @@ -84,7 +84,7 @@ private void init() {
pack();

ok.addActionListener(e -> {
metaData.setLabelPattern(labelPatternPanel.getLabelPatternAsDatabaseLabelPattern());
metaData.setBibtexKeyPattern(bibtexKeyPatternPanel.getKeyPatternAsDatabaseBibtexKeyPattern());
panel.markNonUndoableBaseChanged();
dispose();
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/EntryTypeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import javax.swing.event.ListSelectionListener;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.CustomEntryType;
Expand Down Expand Up @@ -72,7 +72,7 @@ protected void addField(String str) {
return;
}

String testString = LabelPatternUtil.checkLegalKey(s,
String testString = BibtexKeyPatternUtil.checkLegalKey(s,
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
if (!testString.equals(s) || (s.indexOf('&') >= 0)) {
// Report error and exit.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/FieldSetComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
import javax.swing.event.ListSelectionListener;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.preferences.JabRefPreferences;

/**
Expand Down Expand Up @@ -247,7 +247,7 @@ protected void addField(String str) {
return;
}

String testString = LabelPatternUtil.checkLegalKey(s,
String testString = BibtexKeyPatternUtil.checkLegalKey(s,
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
if (!testString.equals(s) || (s.indexOf('&') >= 0)) {
// Report error and exit.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
import net.sf.jabref.gui.entryeditor.EntryEditorTabList;
import net.sf.jabref.gui.help.HelpAction;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.help.HelpFile;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.preferences.JabRefPreferences;

import com.jgoodies.forms.builder.ButtonBarBuilder;
Expand Down Expand Up @@ -136,7 +136,7 @@ private void okActionPerformed() {
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
return;
}
String testString = LabelPatternUtil.checkLegalKey(parts[1],
String testString = BibtexKeyPatternUtil.checkLegalKey(parts[1],
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
if (!testString.equals(parts[1]) || (parts[1].indexOf('&') >= 0)) {
// Report error and exit.
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@
import net.sf.jabref.importer.ImportInspector;
import net.sf.jabref.importer.OutputPrinter;
import net.sf.jabref.logic.bibtex.comparator.FieldComparator;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.groups.AllEntriesGroup;
import net.sf.jabref.logic.groups.EntriesGroupChange;
import net.sf.jabref.logic.groups.GroupTreeNode;
import net.sf.jabref.logic.help.HelpFile;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternPreferences;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.logic.util.UpdateField;
import net.sf.jabref.model.DuplicateCheck;
import net.sf.jabref.model.database.BibDatabase;
Expand Down Expand Up @@ -463,8 +463,8 @@ private void generateKeySelectedEntry() {
database.insertEntry(entry);

// Generate a unique key:
LabelPatternUtil.makeLabel(localMetaData, database, entry,
LabelPatternPreferences.fromPreferences(Globals.prefs));
BibtexKeyPatternUtil.makeLabel(localMetaData, database, entry,
BibtexKeyPatternPreferences.fromPreferences(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 @@ -505,8 +505,8 @@ private void generateKeys() {
entry.setId(IdGenerator.next());
database.insertEntry(entry);

LabelPatternUtil.makeLabel(localMetaData, database, entry,
LabelPatternPreferences.fromPreferences(Globals.prefs));
BibtexKeyPatternUtil.makeLabel(localMetaData, database, entry,
BibtexKeyPatternPreferences.fromPreferences(Globals.prefs));
// Add the generated key to our list: -- TODO: Why??
keys.add(entry.getCiteKeyOptional());
}
Expand Down
Loading