Skip to content

Commit c8017eb

Browse files
committed
Merge pull request #63 from lenhard/improve-test-coverage
Refactor Preferences
2 parents ad5b7c7 + 0957ffd commit c8017eb

File tree

6 files changed

+1089
-510
lines changed

6 files changed

+1089
-510
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[master]
2+
- Refactored preferences
23
- Remove local jgoodies dependency: replace SimpleInteralFrame with swingx JXTitledPanel and UIFSplitPane by JSplitPane
34
- Fix several FindBugs warnings
45
- Fix for bug #1276: OO styles do not consider editor fields anymore for sorting

src/main/java/net/sf/jabref/JabRefPreferences.java

Lines changed: 606 additions & 510 deletions
Large diffs are not rendered by default.
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
package net.sf.jabref;
2+
3+
import java.util.Collections;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
public class KeyBinds {
8+
9+
public static final String ABBREVIATE = "Abbreviate";
10+
public static final String AUTOGENERATE_BIB_TE_X_KEYS = "Autogenerate BibTeX keys";
11+
public static final String AUTOMATICALLY_LINK_FILES = "Automatically link files";
12+
public static final String BACK = "Back";
13+
public static final String BACK_HELP_DIALOG = "Back, help dialog";
14+
public static final String CLEANUP = "Cleanup";
15+
public static final String CLEAR_SEARCH = "Clear search";
16+
public static final String CLOSE_DATABASE = "Close database";
17+
public static final String CLOSE_DIALOG = "Close dialog";
18+
public static final String CLOSE_ENTRY_EDITOR = "Close entry editor";
19+
public static final String CLOSE_PREAMBLE_EDITOR = "Close preamble editor";
20+
public static final String COPY = "Copy";
21+
public static final String COPY_BIB_TE_X_KEY = "Copy BibTeX key";
22+
public static final String COPY_BIB_TE_X_KEY_AND_TITLE = "Copy BibTeX key and title";
23+
public static final String COPY_CITE_BIB_TE_X_KEY = "Copy \\cite{BibTeX key}";
24+
public static final String CUT = "Cut";
25+
public static final String DECREASE_TABLE_FONT_SIZE = "Decrease table font size";
26+
public static final String DELETE = "Delete";
27+
public static final String EDIT_ENTRY = "Edit entry";
28+
public static final String EDIT_PREAMBLE = "Edit preamble";
29+
public static final String EDIT_STRINGS = "Edit strings";
30+
public static final String ENTRY_EDITOR_NEXT_ENTRY = "Entry editor, next entry";
31+
public static final String ENTRY_EDITOR_NEXT_PANEL = "Entry editor, next panel";
32+
public static final String ENTRY_EDITOR_NEXT_PANEL_2 = "Entry editor, next panel 2";
33+
public static final String ENTRY_EDITOR_PREVIOUS_ENTRY = "Entry editor, previous entry";
34+
public static final String ENTRY_EDITOR_PREVIOUS_PANEL = "Entry editor, previous panel";
35+
public static final String ENTRY_EDITOR_PREVIOUS_PANEL_2 = "Entry editor, previous panel 2";
36+
public static final String ENTRY_EDITOR_STORE_FIELD = "Entry editor, store field";
37+
public static final String FETCH_AR_XIV_ORG = "Fetch ArXiv.org";
38+
public static final String FETCH_INSPIRE = "Fetch INSPIRE";
39+
public static final String FETCH_MEDLINE = "Fetch Medline";
40+
public static final String FETCH_SPIRES = "Fetch SPIRES";
41+
public static final String FILE_LIST_EDITOR_MOVE_ENTRY_DOWN = "File list editor, move entry down";
42+
public static final String FILE_LIST_EDITOR_MOVE_ENTRY_UP = "File list editor, move entry up";
43+
public static final String FOCUS_ENTRY_TABLE = "Focus entry table";
44+
public static final String FORWARD = "Forward";
45+
public static final String FORWARD_HELP_DIALOG = "Forward, help dialog";
46+
public static final String HELP = "Help";
47+
public static final String HIDE_SHOW_TOOLBAR = "Hide/show toolbar";
48+
public static final String IMPORT_INTO_CURRENT_DATABASE = "Import into current database";
49+
public static final String IMPORT_INTO_NEW_DATABASE = "Import into new database";
50+
public static final String INCREASE_TABLE_FONT_SIZE = "Increase table font size";
51+
public static final String INCREMENTAL_SEARCH = "Incremental search";
52+
public static final String LOAD_SESSION = "Load session";
53+
public static final String MARK_ENTRIES = "Mark entries";
54+
public static final String MINIMIZE_TO_SYSTEM_TRAY = "Minimize to system tray";
55+
public static final String NEW_ARTICLE = "New article";
56+
public static final String NEW_BOOK = "New book";
57+
public static final String NEW_ENTRY = "New entry";
58+
public static final String NEW_FILE_LINK = "New file link";
59+
public static final String NEW_FROM_PLAIN_TEXT = "New from plain text";
60+
public static final String NEW_INBOOK = "New inbook";
61+
public static final String NEW_MASTERSTHESIS = "New mastersthesis";
62+
public static final String NEW_PHDTHESIS = "New phdthesis";
63+
public static final String NEW_PROCEEDINGS = "New proceedings";
64+
public static final String NEW_UNPUBLISHED = "New unpublished";
65+
public static final String NEXT_TAB = "Next tab";
66+
public static final String OPEN_DATABASE = "Open database";
67+
public static final String OPEN_FILE = "Open file";
68+
public static final String OPEN_FOLDER = "Open folder";
69+
public static final String OPEN_PDF_OR_PS = "Open PDF or PS";
70+
public static final String OPEN_SPIRES_ENTRY = "Open SPIRES entry";
71+
public static final String OPEN_URL_OR_DOI = "Open URL or DOI";
72+
public static final String PASTE = "Paste";
73+
public static final String PREAMBLE_EDITOR_STORE_CHANGES = "Preamble editor, store changes";
74+
public static final String PREVIOUS_TAB = "Previous tab";
75+
public static final String PUSH_TO_APPLICATION = "Push to application";
76+
public static final String PUSH_TO_LY_X = "Push to LyX";
77+
public static final String PUSH_TO_WIN_EDT = "Push to WinEdt";
78+
public static final String QUIT_JAB_REF = "Quit JabRef";
79+
public static final String REDO = "Redo";
80+
public static final String REFRESH_OO = "Refresh OO";
81+
public static final String REPEAT_INCREMENTAL_SEARCH = "Repeat incremental search";
82+
public static final String REPLACE_STRING = "Replace string";
83+
public static final String RESOLVE_DUPLICATE_BIB_TE_X_KEYS = "Resolve duplicate BibTeX keys";
84+
public static final String SAVE_ALL = "Save all";
85+
public static final String SAVE_DATABASE = "Save database";
86+
public static final String SAVE_DATABASE_AS = "Save database as ...";
87+
public static final String SAVE_SESSION = "Save session";
88+
public static final String SEARCH = "Search";
89+
public static final String SEARCH_ACM_PORTAL = "Search ACM Portal";
90+
public static final String SEARCH_ADS = "Search ADS";
91+
public static final String SEARCH_IEEE_XPLORE = "Search IEEEXplore";
92+
public static final String SEARCH_JSTOR = "Search JSTOR";
93+
public static final String SEARCH_SCIENCE_DIRECT = "Search ScienceDirect";
94+
public static final String SELECT_ALL = "Select all";
95+
public static final String STRING_DIALOG_ADD_STRING = "String dialog, add string";
96+
public static final String STRING_DIALOG_MOVE_STRING_DOWN = "String dialog, move string down";
97+
public static final String STRING_DIALOG_MOVE_STRING_UP = "String dialog, move string up";
98+
public static final String STRING_DIALOG_REMOVE_STRING = "String dialog, remove string";
99+
public static final String SWITCH_PREVIEW_LAYOUT = "Switch preview layout";
100+
public static final String SYNCHRONIZE_FILES = "Synchronize files";
101+
public static final String SYNCHRONIZE_PDF = "Synchronize PDF";
102+
public static final String SYNCHRONIZE_PS = "Synchronize PS";
103+
public static final String TOGGLE_ENTRY_PREVIEW = "Toggle entry preview";
104+
public static final String TOGGLE_GROUPS_INTERFACE = "Toggle groups interface";
105+
public static final String UNABBREVIATE = "Unabbreviate";
106+
public static final String UNDO = "Undo";
107+
public static final String UNMARK_ENTRIES = "Unmark entries";
108+
public static final String WRITE_XMP = "Write XMP";
109+
110+
private final HashMap<String, String> keyBindMap = new HashMap<String, String>();
111+
112+
113+
public KeyBinds() {
114+
keyBindMap.put(PUSH_TO_APPLICATION, "ctrl L");
115+
keyBindMap.put(PUSH_TO_LY_X, "ctrl L");
116+
keyBindMap.put(PUSH_TO_WIN_EDT, "ctrl shift W");
117+
keyBindMap.put(QUIT_JAB_REF, "ctrl Q");
118+
keyBindMap.put(OPEN_DATABASE, "ctrl O");
119+
keyBindMap.put(SAVE_DATABASE, "ctrl S");
120+
keyBindMap.put(SAVE_DATABASE_AS, "ctrl shift S");
121+
keyBindMap.put(SAVE_ALL, "ctrl alt S");
122+
keyBindMap.put(CLOSE_DATABASE, "ctrl W");
123+
keyBindMap.put(NEW_ENTRY, "ctrl N");
124+
keyBindMap.put(CUT, "ctrl X");
125+
keyBindMap.put(COPY, "ctrl C");
126+
keyBindMap.put(PASTE, "ctrl V");
127+
keyBindMap.put(UNDO, "ctrl Z");
128+
keyBindMap.put(REDO, "ctrl Y");
129+
keyBindMap.put(HELP, "F1");
130+
keyBindMap.put(NEW_ARTICLE, "ctrl shift A");
131+
keyBindMap.put(NEW_BOOK, "ctrl shift B");
132+
keyBindMap.put(NEW_PHDTHESIS, "ctrl shift T");
133+
keyBindMap.put(NEW_INBOOK, "ctrl shift I");
134+
keyBindMap.put(NEW_MASTERSTHESIS, "ctrl shift M");
135+
keyBindMap.put(NEW_PROCEEDINGS, "ctrl shift P");
136+
keyBindMap.put(NEW_UNPUBLISHED, "ctrl shift U");
137+
keyBindMap.put(EDIT_STRINGS, "ctrl T");
138+
keyBindMap.put(EDIT_PREAMBLE, "ctrl P");
139+
keyBindMap.put(SELECT_ALL, "ctrl A");
140+
keyBindMap.put(TOGGLE_GROUPS_INTERFACE, "ctrl shift G");
141+
keyBindMap.put(AUTOGENERATE_BIB_TE_X_KEYS, "ctrl G");
142+
keyBindMap.put(SEARCH, "ctrl F");
143+
keyBindMap.put(INCREMENTAL_SEARCH, "ctrl shift F");
144+
keyBindMap.put(REPEAT_INCREMENTAL_SEARCH, "ctrl shift F");
145+
keyBindMap.put(CLOSE_DIALOG, "ESCAPE");
146+
keyBindMap.put(CLOSE_ENTRY_EDITOR, "ESCAPE");
147+
keyBindMap.put(CLOSE_PREAMBLE_EDITOR, "ESCAPE");
148+
keyBindMap.put(BACK_HELP_DIALOG, "LEFT");
149+
keyBindMap.put(FORWARD_HELP_DIALOG, "RIGHT");
150+
keyBindMap.put(PREAMBLE_EDITOR_STORE_CHANGES, "alt S");
151+
keyBindMap.put(CLEAR_SEARCH, "ESCAPE");
152+
keyBindMap.put(ENTRY_EDITOR_NEXT_PANEL, "ctrl TAB");//"ctrl PLUS");//"shift Right");
153+
keyBindMap.put(ENTRY_EDITOR_PREVIOUS_PANEL, "ctrl shift TAB");//"ctrl MINUS");
154+
keyBindMap.put(ENTRY_EDITOR_NEXT_PANEL_2, "ctrl PLUS");//"ctrl PLUS");//"shift Right");
155+
keyBindMap.put(ENTRY_EDITOR_PREVIOUS_PANEL_2, "ctrl MINUS");//"ctrl MINUS");
156+
keyBindMap.put(ENTRY_EDITOR_NEXT_ENTRY, "ctrl shift DOWN");
157+
keyBindMap.put(ENTRY_EDITOR_PREVIOUS_ENTRY, "ctrl shift UP");
158+
keyBindMap.put(ENTRY_EDITOR_STORE_FIELD, "alt S");
159+
keyBindMap.put(STRING_DIALOG_ADD_STRING, "ctrl N");
160+
keyBindMap.put(STRING_DIALOG_REMOVE_STRING, "shift DELETE");
161+
keyBindMap.put(STRING_DIALOG_MOVE_STRING_UP, "ctrl UP");
162+
keyBindMap.put(STRING_DIALOG_MOVE_STRING_DOWN, "ctrl DOWN");
163+
keyBindMap.put(SAVE_SESSION, "F11");
164+
keyBindMap.put(LOAD_SESSION, "F12");
165+
keyBindMap.put(COPY_CITE_BIB_TE_X_KEY, "ctrl K");
166+
keyBindMap.put(COPY_BIB_TE_X_KEY, "ctrl shift K");
167+
keyBindMap.put(COPY_BIB_TE_X_KEY_AND_TITLE, "ctrl shift alt K");
168+
keyBindMap.put(NEXT_TAB, "ctrl PAGE_DOWN");
169+
keyBindMap.put(PREVIOUS_TAB, "ctrl PAGE_UP");
170+
keyBindMap.put(REPLACE_STRING, "ctrl R");
171+
keyBindMap.put(DELETE, "DELETE");
172+
keyBindMap.put(OPEN_FILE, "F4");
173+
keyBindMap.put(OPEN_FOLDER, "ctrl shift O");
174+
keyBindMap.put(OPEN_PDF_OR_PS, "shift F5");
175+
keyBindMap.put(OPEN_URL_OR_DOI, "F3");
176+
keyBindMap.put(OPEN_SPIRES_ENTRY, "ctrl F3");
177+
keyBindMap.put(TOGGLE_ENTRY_PREVIEW, "ctrl F9");
178+
keyBindMap.put(SWITCH_PREVIEW_LAYOUT, "F9");
179+
keyBindMap.put(EDIT_ENTRY, "ctrl E");
180+
keyBindMap.put(MARK_ENTRIES, "ctrl M");
181+
keyBindMap.put(UNMARK_ENTRIES, "ctrl shift M");
182+
keyBindMap.put(FETCH_MEDLINE, "F5");
183+
keyBindMap.put(SEARCH_SCIENCE_DIRECT, "ctrl F5");
184+
keyBindMap.put(SEARCH_ADS, "ctrl shift F6");
185+
keyBindMap.put(NEW_FROM_PLAIN_TEXT, "ctrl shift N");
186+
keyBindMap.put(SYNCHRONIZE_FILES, "ctrl F4");
187+
keyBindMap.put(SYNCHRONIZE_PDF, "shift F4");
188+
keyBindMap.put(SYNCHRONIZE_PS, "ctrl shift F4");
189+
keyBindMap.put(FOCUS_ENTRY_TABLE, "ctrl shift E");
190+
keyBindMap.put(ABBREVIATE, "ctrl alt A");
191+
keyBindMap.put(UNABBREVIATE, "ctrl alt shift A");
192+
keyBindMap.put(SEARCH_IEEE_XPLORE, "alt F8");
193+
keyBindMap.put(SEARCH_ACM_PORTAL, "ctrl shift F8");
194+
keyBindMap.put(FETCH_AR_XIV_ORG, "shift F8");
195+
keyBindMap.put(SEARCH_JSTOR, "shift F9");
196+
keyBindMap.put(CLEANUP, "ctrl shift F7");
197+
keyBindMap.put(WRITE_XMP, "ctrl F7");
198+
keyBindMap.put(NEW_FILE_LINK, "ctrl N");
199+
keyBindMap.put(FETCH_SPIRES, "ctrl F8");
200+
keyBindMap.put(FETCH_INSPIRE, "ctrl F2");
201+
keyBindMap.put(BACK, "alt LEFT");
202+
keyBindMap.put(FORWARD, "alt RIGHT");
203+
keyBindMap.put(IMPORT_INTO_CURRENT_DATABASE, "ctrl I");
204+
keyBindMap.put(IMPORT_INTO_NEW_DATABASE, "ctrl alt I");
205+
keyBindMap.put(FindUnlinkedFilesDialog.ACTION_KEYBINDING_ACTION, "shift F7");
206+
keyBindMap.put(INCREASE_TABLE_FONT_SIZE, "ctrl PLUS");
207+
keyBindMap.put(DECREASE_TABLE_FONT_SIZE, "ctrl MINUS");
208+
keyBindMap.put(AUTOMATICALLY_LINK_FILES, "alt F");
209+
keyBindMap.put(RESOLVE_DUPLICATE_BIB_TE_X_KEYS, "ctrl shift D");
210+
keyBindMap.put(REFRESH_OO, "ctrl alt O");
211+
keyBindMap.put(FILE_LIST_EDITOR_MOVE_ENTRY_UP, "ctrl UP");
212+
keyBindMap.put(FILE_LIST_EDITOR_MOVE_ENTRY_DOWN, "ctrl DOWN");
213+
keyBindMap.put(MINIMIZE_TO_SYSTEM_TRAY, "ctrl alt W");
214+
keyBindMap.put(HIDE_SHOW_TOOLBAR, "ctrl alt T");
215+
}
216+
217+
public String get(String key) {
218+
return keyBindMap.get(key);
219+
}
220+
221+
public HashMap<String, String> getKeyBindings() {
222+
return new HashMap<String, String>(Collections.unmodifiableMap(keyBindMap));
223+
}
224+
225+
public void overwriteBindings(Map<String, String> newBindings) {
226+
keyBindMap.clear();
227+
keyBindMap.putAll(newBindings);
228+
}
229+
230+
public void put(String key, String value) {
231+
keyBindMap.put(key, value);
232+
}
233+
234+
}

src/test/java/net/sf/jabref/JabRefCLITest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ public void testCLIParsingShortOptions() {
3030
Assert.assertEquals("some/export/file", cli.getFileExport());
3131
}
3232

33+
@Test
34+
public void testPreferencesExport() {
35+
JabRefCLI cli = new JabRefCLI(new String[] {"-n", "-x=some/file"});
36+
37+
Assert.assertEquals("[]", Arrays.toString(cli.getLeftOver()));
38+
Assert.assertEquals("some/file", cli.getPreferencesExport());
39+
Assert.assertTrue(cli.isDisableGui());
40+
}
41+
3342
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package net.sf.jabref;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
11+
public class JabRefPreferencesTest {
12+
13+
private JabRefPreferences prefs;
14+
15+
16+
@Before
17+
public void setUp() {
18+
prefs = JabRefPreferences.getInstance();
19+
}
20+
21+
@Test
22+
public void testPreferencesImport() throws IOException {
23+
// the primary sort field has been changed to "editor" in this case
24+
File importFile = new File("src/test/resources/net/sf/jabref/customPreferences.xml");
25+
26+
prefs.importPreferences(importFile.getAbsolutePath());
27+
28+
String expected = "editor";
29+
String actual = prefs.get(JabRefPreferences.SAVE_PRIMARY_SORT_FIELD);
30+
31+
//clean up preferences to default state
32+
prefs.put(JabRefPreferences.SAVE_PRIMARY_SORT_FIELD, "author");
33+
34+
assertEquals(expected, actual);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)