Skip to content

Commit 404e781

Browse files
authored
[Copy] Copy referenced constant strings to clipboard (#16)
* feat: Add parsed serialized string when cloning * feat: Add sanity check for null in ClipBoardManager * closes #15
1 parent ea946c4 commit 404e781

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

src/main/java/org/jabref/gui/ClipBoardManager.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ public void setContent(List<BibEntry> entries, BibEntryTypesManager entryTypesMa
171171
final ClipboardContent content = new ClipboardContent();
172172
BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), entryTypesManager);
173173
StringBuilder builder = new StringBuilder();
174-
for (BibtexString strConst : stringConstants) {
175-
if (strConst.getParsedSerialization() != null) {
176-
builder.append(strConst.getParsedSerialization());
177-
}
178-
}
174+
stringConstants.forEach(strConst -> builder.append(strConst.getParsedSerialization() == null ? "" : strConst.getParsedSerialization()));
179175
String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX);
180176
builder.append(serializedEntries);
181177
// BibEntry is not Java serializable. Thus, we need to do the serialization manually

src/main/java/org/jabref/gui/maintable/MainTable.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ public void copy() {
258258
List<BibEntry> selectedEntries = getSelectedEntries();
259259

260260
if (!selectedEntries.isEmpty()) {
261-
List<BibtexString> stringConstants = getStringValues();
262-
261+
List<BibtexString> stringConstants = getUsedStringValues(selectedEntries);
263262
try {
264263
if (!stringConstants.isEmpty()) {
265264
clipBoardManager.setContent(selectedEntries, entryTypesManager, stringConstants);
@@ -497,10 +496,7 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
497496
.findFirst();
498497
}
499498

500-
private List<BibtexString> getStringValues() {
501-
return database.getDatabase()
502-
.getStringValues()
503-
.stream()
504-
.toList();
499+
private List<BibtexString> getUsedStringValues(List<BibEntry> entries) {
500+
return database.getDatabase().getUsedStrings(entries).stream().toList();
505501
}
506502
}

src/main/java/org/jabref/model/entry/BibtexString.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ public String getUserComments() {
158158
public Object clone() {
159159
BibtexString clone = new BibtexString(name, content);
160160
clone.setId(id);
161+
if (parsedSerialization != null) {
162+
clone.setParsedSerialization(parsedSerialization);
163+
}
161164

162165
return clone;
163166
}

0 commit comments

Comments
 (0)