Skip to content

Commit cf781bc

Browse files
committed
Merge branch 'master' into implement-1356
# Conflicts: # CHANGELOG.md
2 parents 7c1afff + c32a3a1 commit cf781bc

File tree

68 files changed

+879
-613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+879
-613
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
1919
- Updated German translation
2020
- When resolving duplicate BibTeX-keys there is now an "Ignore" button. "Cancel" and close key now quits the resolving.
2121
- The [online forum](http://discourse.jabref.org/) is now directly accessible via the "Help" menu
22+
- Implemented [#1338](https://github.com/JabRef/jabref/issues/1338): clicking on a crossref in the main table selects the parent entry and added a button in the entry editor to select the parent entry.
2223

2324
### Fixed
2425
- Fixed [#1530](https://github.com/JabRef/jabref/issues/1530): Unescaped hashes in the url field are ignored by the integrity checker
@@ -34,6 +35,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
3435
- Fixed [#1507](https://github.com/JabRef/jabref/issues/1507): Keywords are now separated by the delimiter specified in the preferences
3536
- Fixed [#1484](https://github.com/JabRef/jabref/issues/1484): HTML export handles some UTF characters wrong
3637
- Fixed [#1534](https://github.com/JabRef/jabref/issues/1534): "Mark entries imported into database" does not work correctly
38+
- Fixed [#1500](https://github.com/JabRef/jabref/issues/1500): Renaming of explicit groups now changes entries accordingly
39+
- Fixed issue where field changes were not undoable if the time stamp was updated on editing
3740

3841
### Removed
3942

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ More information on this can be found via `man git-shortlog`.
4141

4242

4343
### Modify the header
44-
The headers of each `.java` file states "JabREf contributors".
44+
The headers of each `.java` file states "JabRef contributors".
4545
Author credits are given using the `AUTHORS` file and by using the `git blame` functionality.
4646

4747
For instance,

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package net.sf.jabref;
1717

18+
import java.util.Optional;
19+
1820
import net.sf.jabref.collab.FileUpdateMonitor;
1921
import net.sf.jabref.exporter.AutoSaveManager;
2022
import net.sf.jabref.gui.GlobalFocusListener;
@@ -64,8 +66,18 @@ public class Globals {
6466
*/
6567
public static JournalAbbreviationLoader journalAbbreviationLoader;
6668

69+
// Key binding preferences
6770
private static KeyBindingPreferences keyPrefs;
6871

72+
// Background tasks
73+
private static GlobalFocusListener focusListener;
74+
private static FileUpdateMonitor fileUpdateMonitor;
75+
private static StreamEavesdropper streamEavesdropper;
76+
77+
// Autosave manager
78+
private static AutoSaveManager autoSaveManager;
79+
80+
// Key binding preferences
6981
public static KeyBindingPreferences getKeyPrefs() {
7082
if (keyPrefs == null) {
7183
keyPrefs = new KeyBindingPreferences(prefs);
@@ -75,23 +87,29 @@ public static KeyBindingPreferences getKeyPrefs() {
7587

7688

7789
// Background tasks
78-
public static GlobalFocusListener focusListener;
79-
public static FileUpdateMonitor fileUpdateMonitor;
80-
public static StreamEavesdropper streamEavesdropper;
81-
8290
public static void startBackgroundTasks() {
8391
Globals.focusListener = new GlobalFocusListener();
8492

8593
Globals.streamEavesdropper = StreamEavesdropper.eavesdropOnSystem();
8694

8795
Globals.fileUpdateMonitor = new FileUpdateMonitor();
88-
JabRefExecutorService.INSTANCE.executeWithLowPriorityInOwnThread(Globals.fileUpdateMonitor, "FileUpdateMonitor");
96+
JabRefExecutorService.INSTANCE.executeWithLowPriorityInOwnThread(Globals.fileUpdateMonitor,
97+
"FileUpdateMonitor");
98+
}
99+
100+
public static GlobalFocusListener getFocusListener() {
101+
return focusListener;
89102
}
90103

104+
public static FileUpdateMonitor getFileUpdateMonitor() {
105+
return fileUpdateMonitor;
106+
}
91107

92-
// Autosave manager
93-
public static AutoSaveManager autoSaveManager;
108+
public static StreamEavesdropper getStreamEavesdropper() {
109+
return streamEavesdropper;
110+
}
94111

112+
// Autosave manager
95113
public static void startAutoSaveManager(JabRefFrame frame) {
96114
Globals.autoSaveManager = new AutoSaveManager(frame);
97115
Globals.autoSaveManager.startAutoSaveTimer();
@@ -105,4 +123,8 @@ public static void stopAutoSaveManager() {
105123
Globals.autoSaveManager = null;
106124
}
107125
}
126+
127+
public static Optional<AutoSaveManager> getAutoSaveManager() {
128+
return Optional.ofNullable(Globals.autoSaveManager);
129+
}
108130
}

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.List;
3737
import java.util.Locale;
3838
import java.util.Map;
39+
import java.util.Optional;
3940
import java.util.Set;
4041
import java.util.prefs.BackingStoreException;
4142
import java.util.prefs.InvalidPreferencesFormatException;
@@ -1013,10 +1014,10 @@ public List<String> getStringList(String key) {
10131014

10141015
StringReader rd = new StringReader(names);
10151016
List<String> res = new ArrayList<>();
1016-
String rs;
1017+
Optional<String> rs;
10171018
try {
1018-
while ((rs = getNextUnit(rd)) != null) {
1019-
res.add(rs);
1019+
while ((rs = getNextUnit(rd)).isPresent()) {
1020+
res.add(rs.get());
10201021
}
10211022
} catch (IOException ignored) {
10221023
// Ignored
@@ -1205,7 +1206,7 @@ private Object getObject(String key) {
12051206
}
12061207

12071208

1208-
private static String getNextUnit(Reader data) throws IOException {
1209+
private static Optional<String> getNextUnit(Reader data) throws IOException {
12091210
// character last read
12101211
// -1 if end of stream
12111212
// initialization necessary, because of Java compiler
@@ -1240,12 +1241,12 @@ private static String getNextUnit(Reader data) throws IOException {
12401241
}
12411242
}
12421243
if (res.length() > 0) {
1243-
return res.toString();
1244+
return Optional.of(res.toString());
12441245
} else if (c == -1) {
12451246
// end of stream
1246-
return null;
1247+
return Optional.empty();
12471248
} else {
1248-
return "";
1249+
return Optional.of("");
12491250
}
12501251
}
12511252

@@ -1265,22 +1266,22 @@ public void storeCustomEntryType(CustomEntryType tp, int number) {
12651266
/**
12661267
* Retrieves all information about the entry type in preferences, with the tag given by number.
12671268
*/
1268-
public CustomEntryType getCustomEntryType(int number) {
1269+
public Optional<CustomEntryType> getCustomEntryType(int number) {
12691270
String nr = String.valueOf(number);
12701271
String name = get(JabRefPreferences.CUSTOM_TYPE_NAME + nr);
12711272
if (name == null) {
1272-
return null;
1273+
return Optional.empty();
12731274
}
12741275
List<String> req = getStringList(JabRefPreferences.CUSTOM_TYPE_REQ + nr);
12751276
List<String> opt = getStringList(JabRefPreferences.CUSTOM_TYPE_OPT + nr);
12761277
List<String> priOpt = getStringList(JabRefPreferences.CUSTOM_TYPE_PRIOPT + nr);
12771278
if (priOpt.isEmpty()) {
1278-
return new CustomEntryType(EntryUtil.capitalizeFirst(name), req, opt);
1279+
return Optional.of(new CustomEntryType(EntryUtil.capitalizeFirst(name), req, opt));
12791280
}
12801281
List<String> secondary = new ArrayList<>(opt);
12811282
secondary.removeAll(priOpt);
12821283

1283-
return new CustomEntryType(EntryUtil.capitalizeFirst(name), req, priOpt, secondary);
1284+
return Optional.of(new CustomEntryType(EntryUtil.capitalizeFirst(name), req, priOpt, secondary));
12841285

12851286
}
12861287

@@ -1297,17 +1298,6 @@ public void purgeCustomEntryTypes(int number) {
12971298
purgeSeries(JabRefPreferences.CUSTOM_TYPE_PRIOPT, number);
12981299
}
12991300

1300-
public void purgeCustomEntryTypes() {
1301-
int number = 0;
1302-
if(getCustomEntryType(number) != null) {
1303-
number++;
1304-
}
1305-
1306-
for(int i = 0; i < number; i++) {
1307-
purgeCustomEntryTypes(i);
1308-
}
1309-
}
1310-
13111301
/**
13121302
* Removes all entries keyed by prefix+number, where number is equal to or higher than the given number.
13131303
*

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ private MetaData(Map<String, String> inData) throws ParseException {
8585
List<String> orderedData = new ArrayList<>();
8686
// We must allow for ; and \ in escape sequences.
8787
try {
88-
String unit;
89-
while ((unit = getNextUnit(data)) != null) {
90-
orderedData.add(unit);
88+
Optional<String> unit;
89+
while ((unit = getNextUnit(data)).isPresent()) {
90+
orderedData.add(unit.get());
9191
}
9292
} catch (IOException ex) {
9393
LOGGER.error("Weird error while parsing meta data.", ex);
@@ -200,7 +200,7 @@ public void setGroups(GroupTreeNode root) {
200200
/**
201201
* Reads the next unit. Units are delimited by ';'.
202202
*/
203-
private static String getNextUnit(Reader reader) throws IOException {
203+
private static Optional<String> getNextUnit(Reader reader) throws IOException {
204204
int c;
205205
boolean escape = false;
206206
StringBuilder res = new StringBuilder();
@@ -217,9 +217,9 @@ private static String getNextUnit(Reader reader) throws IOException {
217217
}
218218
}
219219
if (res.length() > 0) {
220-
return res.toString();
220+
return Optional.of(res.toString());
221221
}
222-
return null;
222+
return Optional.empty();
223223
}
224224

225225
public DBStrings getDBStrings() {

src/main/java/net/sf/jabref/bst/BibtexCaseChanger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ private int convertCharIfBraceLevelIsZero(char[] c, int start, StringBuilder sb,
280280

281281
/**
282282
* Determine whether there starts a special char at pos (e.g., oe, AE). Return it as string.
283-
* If nothing found, return null
283+
* If nothing found, return Optional.empty()
284284
*
285285
* Also used by BibtexPurify
286286
*

src/main/java/net/sf/jabref/collab/ChangeScanner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void run() {
9595
try {
9696

9797
// Parse the temporary file.
98-
File tempFile = Globals.fileUpdateMonitor.getTempFile(panel.fileMonitorHandle());
98+
File tempFile = Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle());
9999
ParserResult pr = OpenDatabaseAction.loadDatabase(tempFile, Globals.prefs.getDefaultEncoding());
100100
inTemp = pr.getDatabase();
101101
mdInTemp = pr.getMetaData();
@@ -166,7 +166,7 @@ private void storeTempDatabase() {
166166
.fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE)));
167167
BibDatabaseWriter databaseWriter = new BibDatabaseWriter();
168168
SaveSession ss = databaseWriter.saveDatabase(new BibDatabaseContext(inTemp, mdInTemp, defaults), prefs);
169-
ss.commit(Globals.fileUpdateMonitor.getTempFile(panel.fileMonitorHandle()));
169+
ss.commit(Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle()));
170170
} catch (SaveException ex) {
171171
LOGGER.warn("Problem updating tmp file after accepting external changes", ex);
172172
}

src/main/java/net/sf/jabref/exporter/SaveDatabaseAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void run() {
132132
success = saveDatabase(panel.getBibDatabaseContext().getDatabaseFile(), false,
133133
panel.getBibDatabaseContext().getMetaData().getEncoding());
134134

135-
Globals.fileUpdateMonitor.updateTimeStamp(panel.getFileMonitorHandle());
135+
Globals.getFileUpdateMonitor().updateTimeStamp(panel.getFileMonitorHandle());
136136
} else {
137137
// No file lock
138138
success = false;
@@ -331,7 +331,7 @@ public void saveAs() throws Throwable {
331331
}
332332
// Register so we get notifications about outside changes to the file.
333333
try {
334-
panel.setFileMonitorHandle(Globals.fileUpdateMonitor.addUpdateListener(panel,
334+
panel.setFileMonitorHandle(Globals.getFileUpdateMonitor().addUpdateListener(panel,
335335
panel.getBibDatabaseContext().getDatabaseFile()));
336336
} catch (IOException ex) {
337337
LOGGER.error("Problem registering file change notifications", ex);
@@ -368,7 +368,7 @@ public boolean isCanceled() {
368368
*/
369369
private boolean checkExternalModification() {
370370
// Check for external modifications:
371-
if (panel.isUpdatedExternally() || Globals.fileUpdateMonitor.hasBeenModified(panel.getFileMonitorHandle())) {
371+
if (panel.isUpdatedExternally() || Globals.getFileUpdateMonitor().hasBeenModified(panel.getFileMonitorHandle())) {
372372
String[] opts = new String[] {Localization.lang("Review changes"), Localization.lang("Save"),
373373
Localization.lang("Cancel")};
374374
int answer = JOptionPane.showOptionDialog(panel.frame(),

src/main/java/net/sf/jabref/external/AutoSetLinks.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,26 @@ public static Runnable autoSetLinks(final Collection<BibEntry> entries, final Na
7878
diag.setTitle(Localization.lang("Automatically setting file links"));
7979
diag.getContentPane().add(prog, BorderLayout.CENTER);
8080
diag.getContentPane().add(label, BorderLayout.SOUTH);
81-
81+
8282
diag.pack();
8383
diag.setLocationRelativeTo(diag.getParent());
8484
}
85-
85+
8686
Runnable r = new Runnable() {
87-
87+
8888
@Override
8989
public void run() {
9090
// determine directories to search in
9191
List<File> dirs = new ArrayList<>();
9292
List<String> dirsS = databaseContext.getFileDirectory();
9393
dirs.addAll(dirsS.stream().map(File::new).collect(Collectors.toList()));
94-
94+
9595
// determine extensions
9696
Collection<String> extensions = new ArrayList<>();
9797
for (final ExternalFileType type : types) {
9898
extensions.add(type.getExtension());
9999
}
100-
100+
101101
// Run the search operation:
102102
Map<BibEntry, List<File>> result;
103103
if (Globals.prefs.getBoolean(JabRefPreferences.AUTOLINK_USE_REG_EXP_SEARCH_KEY)) {
@@ -106,17 +106,15 @@ public void run() {
106106
} else {
107107
result = FileUtil.findAssociatedFiles(entries, extensions, dirs);
108108
}
109-
109+
110110
boolean foundAny = false;
111111
// Iterate over the entries:
112112
for (Entry<BibEntry, List<File>> entryFilePair : result.entrySet()) {
113113
FileListTableModel tableModel;
114-
String oldVal = entryFilePair.getKey().getField(Globals.FILE_FIELD);
114+
Optional<String> oldVal = entryFilePair.getKey().getFieldOptional(Globals.FILE_FIELD);
115115
if (singleTableModel == null) {
116116
tableModel = new FileListTableModel();
117-
if (oldVal != null) {
118-
tableModel.setContent(oldVal);
119-
}
117+
oldVal.ifPresent(tableModel::setContent);
120118
} else {
121119
assert entries.size() == 1;
122120
tableModel = singleTableModel;
@@ -146,15 +144,15 @@ public void run() {
146144
}
147145
FileListEntry flEntry = new FileListEntry(f.getName(), f.getPath(), type);
148146
tableModel.addEntry(tableModel.getRowCount(), flEntry);
149-
147+
150148
String newVal = tableModel.getStringRepresentation();
151149
if (newVal.isEmpty()) {
152150
newVal = null;
153151
}
154152
if (ce != null) {
155153
// store undo information
156154
UndoableFieldChange change = new UndoableFieldChange(entryFilePair.getKey(),
157-
Globals.FILE_FIELD, oldVal, newVal);
155+
Globals.FILE_FIELD, oldVal.orElse(null), newVal);
158156
ce.addEdit(change);
159157
}
160158
// hack: if table model is given, do NOT modify entry
@@ -167,12 +165,12 @@ public void run() {
167165
}
168166
}
169167
}
170-
168+
171169
// handle callbacks and dialog
172170
// FIXME: The ID signals if action was successful :/
173171
final int id = foundAny ? 1 : 0;
174172
SwingUtilities.invokeLater(new Runnable() {
175-
173+
176174
@Override
177175
public void run() {
178176
if (diag != null) {

0 commit comments

Comments
 (0)