Skip to content

Commit

Permalink
Add value delimiter to preferences.
Browse files Browse the repository at this point in the history
  • Loading branch information
kubovy authored and koppor committed Jan 11, 2013
1 parent c43cc1f commit 4f9fb0b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
20 changes: 19 additions & 1 deletion src/java/net/sf/jabref/AdvancedTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ public class AdvancedTab extends JPanel implements PrefsTab {
JLabel lab;
JCheckBox useDefault, useRemoteServer, useNativeFileDialogOnMac, filechooserDisableRename,
useIEEEAbrv, biblatexMode;
JComboBox<String> valueDelimiter;
JTextField className, remoteServerPort;
JButton def1 = new JButton(Globals.lang("Default")),
def2 = new JButton(Globals.lang("Default"));
JPanel p1 = new JPanel(),
p2 = new JPanel();
String oldLnf = "";
boolean oldUseDef, oldBiblMode=false, oldConvertToEquation, oldCaseKeeperOnSearch, oldUnitFormatterOnSearch;
int oldPort = -1;
int oldPort = -1, valueDelimiterSelected;

public final static String PREF_IMPORT_CONVERT_TO_EQUATION = "importFileConvertToEquation";
public final static String PREF_IMPORT_FILENAMEPATTERN = "importFileNamePattern";
Expand All @@ -67,6 +68,9 @@ public AdvancedTab(JabRefPreferences prefs, HelpDialog diag) {
filechooserDisableRename = new JCheckBox(Globals.lang("Disable file renaming in non-native file dialog"));
useIEEEAbrv = new JCheckBox(Globals.lang("Use IEEE LaTeX abbreviations"));
biblatexMode = new JCheckBox(Globals.lang("BibLaTeX mode"));
valueDelimiter = new JComboBox<String>(new String[]{
Globals.lang("Quotes: \", \""),
Globals.lang("Curly Brackets: {, }") });
remoteServerPort = new JTextField();
className = new JTextField(50);
final JTextField clName = className;
Expand Down Expand Up @@ -149,6 +153,17 @@ public void stateChanged(ChangeEvent e) {
builder.append(new JPanel());
builder.append(biblatexMode);

builder.nextLine();
builder.appendSeparator(Globals.lang("Export options"));
FormLayout layout2 = new FormLayout(
"left:pref, 8dlu, fill:pref", "");
DefaultFormBuilder builder2 = new DefaultFormBuilder(layout2);
builder2.append(new JLabel(Globals.lang("Value delimiter:")));
builder2.append(valueDelimiter);
builder.nextLine();
builder.append(new JPanel());
builder.append(builder2.getPanel());

builder.nextLine();
builder.appendSeparator(Globals.lang("Import conversions"));
builder.nextLine();
Expand Down Expand Up @@ -182,6 +197,8 @@ public void setValues() {
useIEEEAbrv.setSelected(Globals.prefs.getBoolean("useIEEEAbrv"));
oldBiblMode = Globals.prefs.getBoolean("biblatexMode");
biblatexMode.setSelected(oldBiblMode);
valueDelimiterSelected = Globals.prefs.getInt("valueDelimiters");
valueDelimiter.setSelectedIndex(valueDelimiterSelected);
oldConvertToEquation = Globals.prefs.getBoolean("useConvertToEquation");
useConvertToEquation.setSelected(oldConvertToEquation);
oldCaseKeeperOnSearch = Globals.prefs.getBoolean("useCaseKeeperOnSearch");
Expand Down Expand Up @@ -244,6 +261,7 @@ public void storeSettings() {
Globals.lang("BibLaTeX mode"), JOptionPane.WARNING_MESSAGE);
}

_prefs.putInt("valueDelimiters", valueDelimiter.getSelectedIndex());
_prefs.putBoolean("useConvertToEquation", useConvertToEquation.isSelected());
_prefs.putBoolean("useCaseKeeperOnSearch", useCaseKeeperOnSearch.isSelected());
_prefs.putBoolean("useUnitFormatterOnSearch", useUnitFormatterOnSearch.isSelected());
Expand Down
13 changes: 13 additions & 0 deletions src/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public class JabRefPreferences {
// modifications, in order to indicate a removed default file type:
public static final String FILE_TYPE_REMOVED_FLAG = "REMOVED";

private static final char[][] VALUE_DELIMITERS =
new char[][]{ {'"', '"'}, {'{', '}'} };

public String WRAPPED_USERNAME, MARKING_WITH_NUMBER_PATTERN;

Preferences prefs;
Expand Down Expand Up @@ -450,6 +453,7 @@ private JabRefPreferences() {
defaults.put("deletePlugins", "");
defaults.put("enforceLegalBibtexKey", Boolean.TRUE);
defaults.put("biblatexMode", Boolean.FALSE);
defaults.put("valueDelimiters", 0);
defaults.put("keyGenFirstLetterA", Boolean.TRUE);
defaults.put("keyGenAlwaysAddLetter", Boolean.FALSE);
defaults.put(JabRefPreferences.EMAIL_SUBJECT, Globals.lang("References"));
Expand Down Expand Up @@ -561,6 +565,15 @@ public void updateSpecialFieldHandling() {

}

public char getValueDelimiters(int index) {
return getValueDelimiters()[index];
}

public char[] getValueDelimiters() {
return VALUE_DELIMITERS[getInt(
"valueDelimiters")];
}

/**
* Check whether a key is set (differently from null).
* @param key The key to check.
Expand Down
13 changes: 7 additions & 6 deletions src/java/net/sf/jabref/export/LatexFieldFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class LatexFieldFormatter implements FieldFormatter {
int col; // First line usually starts about so much further to the right.
final int STARTCOL = 4;
private boolean neverFailOnHashes = false;
private static char[] valueDelimiters = {'"', '"'}; //TODO JK: Make configurable

public void setNeverFailOnHashes(boolean neverFailOnHashes) {
this.neverFailOnHashes = neverFailOnHashes;
}

public String format(String text, String fieldName)
throws IllegalArgumentException {
if (text == null) return valueDelimiters[0] + "" + valueDelimiters[1];
if (text == null) return Globals.prefs.getValueDelimiters(0)
+ "" + Globals.prefs.getValueDelimiters(1);

if (Globals.prefs.putBracesAroundCapitals(fieldName) && !Globals.BIBTEX_STRING.equals(fieldName)) {
text = Util.putBracesAroundCapitals(text);
Expand Down Expand Up @@ -77,7 +77,8 @@ public String format(String text, String fieldName)
if (!ok)
throw new IllegalArgumentException("Curly braces { and } must be balanced.");

sb = new StringBuffer(valueDelimiters[0]+"");
sb = new StringBuffer(
Globals.prefs.getValueDelimiters(0) + "");
// No formatting at all for these fields, to allow custom formatting?
//if (Globals.prefs.getBoolean("preserveFieldFormatting"))
// sb.append(text);
Expand All @@ -87,7 +88,7 @@ public String format(String text, String fieldName)
//else
sb.append(text);

sb.append(valueDelimiters[1]);
sb.append(Globals.prefs.getValueDelimiters(1));

return sb.toString();
}
Expand Down Expand Up @@ -158,7 +159,7 @@ private void writeText(String text, int start_pos,
/*sb.append("{");
sb.append(text.substring(start_pos, end_pos));
sb.append("}");*/
sb.append(valueDelimiters[0]);
sb.append(Globals.prefs.getValueDelimiters(0));
boolean escape = false, inCommandName = false, inCommand = false,
inCommandOption = false;
int nestedEnvironments = 0;
Expand Down Expand Up @@ -223,7 +224,7 @@ else if (!inCommandOption && (c == '{')) {
sb.append(c);
escape = (c == '\\');
}
sb.append(valueDelimiters[1]);
sb.append(Globals.prefs.getValueDelimiters(1));
}

private void writeStringLabel(String text, int start_pos, int end_pos,
Expand Down

0 comments on commit 4f9fb0b

Please sign in to comment.