From 5e98a050b10abc0a9d2007e58be1e644feb86da8 Mon Sep 17 00:00:00 2001 From: Anders Blomqvist Date: Fri, 1 Mar 2024 13:47:20 +0100 Subject: [PATCH] [Copy] New method for serializing string constants (#12) Signed-off-by: Anders Blomqvist --- .../java/org/jabref/gui/ClipBoardManager.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 792c4733384..8b292853d1d 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -21,6 +21,7 @@ import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryTypesManager; +import org.jabref.model.entry.BibtexString; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -165,4 +166,19 @@ public void setContent(List entries, BibEntryTypesManager entryTypesMa clipboard.setContent(content); setPrimaryClipboardContent(content); } + + public void setContent(List entries, BibEntryTypesManager entryTypesManager, List stringConstants) throws IOException { + final ClipboardContent content = new ClipboardContent(); + BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), entryTypesManager); + StringBuilder builder = new StringBuilder(); + stringConstants.forEach(strConst -> builder.append(strConst.getParsedSerialization())); + String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX); + builder.append(serializedEntries); + // BibEntry is not Java serializable. Thus, we need to do the serialization manually + // 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 + // Furthermore, storing a string also enables other applications to work with the data + content.putString(builder.toString()); + clipboard.setContent(content); + setPrimaryClipboardContent(content); + } }