Skip to content

Commit

Permalink
[Copy] Copy referenced constant strings to clipboard (#16)
Browse files Browse the repository at this point in the history
* feat: Add parsed serialized string when cloning
* feat: Add sanity check for null in ClipBoardManager
* closes #15
  • Loading branch information
JXNCTED authored Mar 4, 2024
1 parent ea946c4 commit 404e781
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ public void setContent(List<BibEntry> entries, BibEntryTypesManager entryTypesMa
final ClipboardContent content = new ClipboardContent();
BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), entryTypesManager);
StringBuilder builder = new StringBuilder();
for (BibtexString strConst : stringConstants) {
if (strConst.getParsedSerialization() != null) {
builder.append(strConst.getParsedSerialization());
}
}
stringConstants.forEach(strConst -> builder.append(strConst.getParsedSerialization() == null ? "" : 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
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ public void copy() {
List<BibEntry> selectedEntries = getSelectedEntries();

if (!selectedEntries.isEmpty()) {
List<BibtexString> stringConstants = getStringValues();

List<BibtexString> stringConstants = getUsedStringValues(selectedEntries);
try {
if (!stringConstants.isEmpty()) {
clipBoardManager.setContent(selectedEntries, entryTypesManager, stringConstants);
Expand Down Expand Up @@ -497,10 +496,7 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
.findFirst();
}

private List<BibtexString> getStringValues() {
return database.getDatabase()
.getStringValues()
.stream()
.toList();
private List<BibtexString> getUsedStringValues(List<BibEntry> entries) {
return database.getDatabase().getUsedStrings(entries).stream().toList();
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/model/entry/BibtexString.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public String getUserComments() {
public Object clone() {
BibtexString clone = new BibtexString(name, content);
clone.setId(id);
if (parsedSerialization != null) {
clone.setParsedSerialization(parsedSerialization);
}

return clone;
}
Expand Down

0 comments on commit 404e781

Please sign in to comment.