From 4dc86bbbbab442d6441188997e11945144dc6c4c Mon Sep 17 00:00:00 2001 From: ZOU Hetai <33616271+JXNCTED@users.noreply.github.com> Date: Fri, 1 Mar 2024 18:52:58 +0100 Subject: [PATCH 1/2] Add a sanity check for null for clipboard content Currenlty, the clipboard content can be null since the database does not seem to be updating. This is a sanity check to prevent the program from adding null to the clipboard. Link to DD2480-Group1/jabref#13 --- src/main/java/org/jabref/gui/ClipBoardManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 8b292853d1d..4adaca84236 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -171,7 +171,11 @@ public void setContent(List entries, BibEntryTypesManager entryTypesMa 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())); + for (BibtexString strConst : stringConstants) { + if (strConst.getParsedSerialization() != null) { + 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 From 765cb0e0fa1f6ed3ec5fec7d2948da6021ddd01a Mon Sep 17 00:00:00 2001 From: ZOU Hetai <33616271+JXNCTED@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:25:28 +0100 Subject: [PATCH 2/2] [Fix] Add parsed serilization when save settings When loading from existing files or libraries, the parser will set the serilization of the string constant to the correct value. However, when editing via the GUI, the serilization was not set and a new string constant list will be created without the serilization. This result in the serilization being null and when copying with the clipboard. Link to DD2480-Group1/jabref#13 --- .../constants/ConstantsPropertiesViewModel.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java index 36f4ddeff07..6241508f34f 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java @@ -1,6 +1,7 @@ package org.jabref.gui.libraryproperties.constants; import java.util.Comparator; +import java.util.List; import java.util.Locale; import java.util.Optional; import java.util.stream.Collectors; @@ -86,9 +87,12 @@ private ConstantsItemModel convertFromBibTexString(BibtexString bibtexString) { @Override public void storeSettings() { - databaseContext.getDatabase().setStrings(stringsListProperty.stream() - .map(this::fromBibtexStringViewModel) - .collect(Collectors.toList())); + List strings = stringsListProperty.stream() + .map(this::fromBibtexStringViewModel) + .toList(); + strings.forEach(string -> string.setParsedSerialization("@String{" + + string.getName() + " = " + string.getContent() + "}\n")); + databaseContext.getDatabase().setStrings(strings); } private BibtexString fromBibtexStringViewModel(ConstantsItemModel viewModel) {