Skip to content

Commit 5e98a05

Browse files
[Copy] New method for serializing string constants (#12)
Signed-off-by: Anders Blomqvist <anders@minaemail.se>
1 parent a0d6f72 commit 5e98a05

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.jabref.model.database.BibDatabaseMode;
2222
import org.jabref.model.entry.BibEntry;
2323
import org.jabref.model.entry.BibEntryTypesManager;
24+
import org.jabref.model.entry.BibtexString;
2425
import org.jabref.preferences.PreferencesService;
2526

2627
import org.slf4j.Logger;
@@ -165,4 +166,19 @@ public void setContent(List<BibEntry> entries, BibEntryTypesManager entryTypesMa
165166
clipboard.setContent(content);
166167
setPrimaryClipboardContent(content);
167168
}
169+
170+
public void setContent(List<BibEntry> entries, BibEntryTypesManager entryTypesManager, List<BibtexString> stringConstants) throws IOException {
171+
final ClipboardContent content = new ClipboardContent();
172+
BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), entryTypesManager);
173+
StringBuilder builder = new StringBuilder();
174+
stringConstants.forEach(strConst -> builder.append(strConst.getParsedSerialization()));
175+
String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX);
176+
builder.append(serializedEntries);
177+
// BibEntry is not Java serializable. Thus, we need to do the serialization manually
178+
// At reading of the clipboard in JabRef, we parse the plain string in all cases, so we don't need to flag we put BibEntries here
179+
// Furthermore, storing a string also enables other applications to work with the data
180+
content.putString(builder.toString());
181+
clipboard.setContent(content);
182+
setPrimaryClipboardContent(content);
183+
}
168184
}

0 commit comments

Comments
 (0)