Skip to content

Commit

Permalink
feat: Add string constant validity checker and dialog messages #9
Browse files Browse the repository at this point in the history
Check that a pasted string constant is valid using the
ConstantsItemModel class.

Add diagnostic messages notifying users when adding a string constant
fails while pasting.
  • Loading branch information
hanstig committed Mar 3, 2024
1 parent 5129ae9 commit dd821b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jabref.gui.StateManager;
import org.jabref.gui.duplicationFinder.DuplicateResolverDialog;
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
import org.jabref.gui.libraryproperties.constants.ConstantsItemModel;
import org.jabref.gui.undo.UndoableInsertEntries;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DefaultTaskExecutor;
Expand Down Expand Up @@ -326,13 +327,14 @@ public List<BibEntry> handleBibTeXData(String entries) {
public void importStringConstantsWithDuplicateCheck(List<BibtexString> stringConstants) {
for(BibtexString stringConstantToAdd : stringConstants) {
try {
bibDatabaseContext.getDatabase().addString(stringConstantToAdd);
ConstantsItemModel checker = new ConstantsItemModel(stringConstantToAdd.getName(), stringConstantToAdd.getContent());
if(checker.combinedValidationValidProperty().get()) {
bibDatabaseContext.getDatabase().addString(stringConstantToAdd);
} else {
dialogService.showErrorDialogAndWait(Localization.lang("Pasted string constant \"%0\" was not added because it is not a valid string constant", stringConstantToAdd.getName()));
}
} catch (KeyCollisionException ex) {
LOGGER.debug("Collision when inserting constants");
// TODO: Handle collision with merge window.

// TODO: Use ConstantsItemModel(?) to validate string constants
// In the same way as when adding them manually in library properties
dialogService.showErrorDialogAndWait(Localization.lang("Pasted string constant %0 was not imported because it already exists in this library", stringConstantToAdd.getName()));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2643,3 +2643,7 @@ Source\ URL=Source URL
Redownload\ file=Redownload file
Redownload\ missing\ files=Redownload missing files
Redownload\ missing\ files\ for\ current\ library?=Redownload missing files for current library?
Pasted\ string\ constant\ "%0"\ was\ not\ added\ because\ it\ is\ not\ a\ valid\ string\ constant=Pasted string constant "%0" was not added because it is not a valid string constant
Pasted\ string\ constant\ %0\ was\ not\ imported\ because\ it\ already\ exists\ in\ this\ library=Pasted string constant %0 was not imported because it already exists in this library

0 comments on commit dd821b9

Please sign in to comment.