|
21 | 21 | import org.jabref.model.database.BibDatabaseMode; |
22 | 22 | import org.jabref.model.entry.BibEntry; |
23 | 23 | import org.jabref.model.entry.BibEntryTypesManager; |
| 24 | +import org.jabref.model.entry.BibtexString; |
24 | 25 | import org.jabref.preferences.PreferencesService; |
25 | 26 |
|
26 | 27 | import org.slf4j.Logger; |
@@ -165,4 +166,19 @@ public void setContent(List<BibEntry> entries, BibEntryTypesManager entryTypesMa |
165 | 166 | clipboard.setContent(content); |
166 | 167 | setPrimaryClipboardContent(content); |
167 | 168 | } |
| 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 | + } |
168 | 184 | } |
0 commit comments