Skip to content

Commit

Permalink
[Copy] New method for serializing string constants (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Blomqvist <[email protected]>
  • Loading branch information
andersblomqvist authored Mar 1, 2024
1 parent a0d6f72 commit 5e98a05
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,4 +166,19 @@ public void setContent(List<BibEntry> entries, BibEntryTypesManager entryTypesMa
clipboard.setContent(content);
setPrimaryClipboardContent(content);
}

public void setContent(List<BibEntry> entries, BibEntryTypesManager entryTypesManager, List<BibtexString> 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);
}
}

0 comments on commit 5e98a05

Please sign in to comment.