Skip to content

Commit

Permalink
Improvement on check for missing commas when importing or opening a .…
Browse files Browse the repository at this point in the history
…bib file (#8840)

* Change from error dialog to warning dialog when no suitable import format. Also add more meaningful message when warning occurred.

* remove Localization.lang() on parserResult.getErrorMessage()

* Update error messages for source tab and importing library file

* Update error message for opening library file

* Update Localization lang
  • Loading branch information
LIM0000 authored Jul 9, 2022
1 parent 17f0120 commit 8bd1845
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,12 @@ private void setupSourceEditor() {
sourceValidator.getValidationStatus().getMessages().addListener((InvalidationListener) c -> {
ValidationStatus sourceValidationStatus = sourceValidator.getValidationStatus();
if (!sourceValidationStatus.isValid()) {
sourceValidationStatus.getHighestMessage().ifPresent(message ->
dialogService.showErrorDialogAndWait(message.getMessage()));
sourceValidationStatus.getHighestMessage().ifPresent(message -> {
String content = Localization.lang("User input via entry-editor in `{}bibtex source` tab led to failure.")
+ "\n" + Localization.lang("Please check your library file for wrong syntax.")
+ "\n\n" + message.getMessage();
dialogService.showWarningDialogAndWait(Localization.lang("SourceTab error"), content);
});
}
});

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/importer/ImportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public void automatedImport(List<String> filenames) {
if (importError == null) {
// TODO: No control flow using exceptions
throw new JabRefException(Localization.lang("No entries found. Please make sure you are using the correct import filter."));
} else if (importError instanceof ImportException) {
String content = Localization.lang("Please check your library file for wrong syntax.") + "\n\n"
+ importError.getLocalizedMessage();
DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> dialogService.showWarningDialogAndWait(Localization.lang("Import error"), content));
} else {
throw importError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jabref.gui.shared.SharedDatabaseUIManager;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.autosaveandbackup.BackupManager;
import org.jabref.logic.importer.OpenDatabase;
Expand Down Expand Up @@ -200,6 +201,12 @@ private ParserResult loadDatabase(Path file) throws Exception {
result = OpenDatabase.loadDatabase(fileToLoad,
preferencesService.getImportFormatPreferences(),
Globals.getFileUpdateMonitor());
if (result.hasWarnings()) {
String content = Localization.lang("Please check your library file for wrong syntax.")
+ "\n\n" + result.getErrorMessage();
DefaultTaskExecutor.runInJavaFXThread(() ->
dialogService.showWarningDialogAndWait(Localization.lang("Open library error"), content));
}
} catch (IOException e) {
result = ParserResult.fromError(e);
LOGGER.error("Error opening file '{}'", fileToLoad, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public UnknownFormatImport importUnknownFormat(Path filePath, FileUpdateMonitor
parserResult.setPath(filePath);
return new UnknownFormatImport(ImportFormatReader.BIBTEX_FORMAT, parserResult);
} else {
throw new ImportException(Localization.lang("Could not find a suitable import format."));
throw new ImportException(parserResult.getErrorMessage());
}
} catch (IOException ignore) {
// Ignored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private void parseAndAddEntry(String type) {

LOGGER.debug("Could not parse entry", ex);
parserResult.addWarning(Localization.lang("Error occurred when parsing entry") + ": '" + ex.getMessage()
+ "'. " + Localization.lang("Skipped entry."));
+ "'. " + "\n\n" + Localization.lang("JabRef skipped the entry."));
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,12 @@ Size=Size
Skipped\ -\ No\ PDF\ linked=Skipped - No PDF linked
Skipped\ -\ PDF\ does\ not\ exist=Skipped - PDF does not exist

Skipped\ entry.=Skipped entry.
JabRef\ skipped\ the\ entry.=JabRef skipped the entry.
Import\ error=Import error
Open\ library\ error=Open library error
Please\ check\ your\ library\ file\ for\ wrong\ syntax.=Please check your library file for wrong syntax.
SourceTab\ error=SourceTab error
User\ input\ via\ entry-editor\ in\ `{}bibtex\ source`\ tab\ led\ to\ failure.=User input via entry-editor in `{}bibtex source` tab led to failure.

Sort\ subgroups=Sort subgroups

Expand Down

0 comments on commit 8bd1845

Please sign in to comment.