Skip to content

Commit

Permalink
Fix for BibTex source tab parsing issue if field contains {} (#4581)
Browse files Browse the repository at this point in the history
* Cleanup interfaces (#4553)

* improve styling of preferences side menu (#4556)

* Added extra stats to be sent with MrDLib recommendations (#4452)

* Refactor BibEntry deprecated method (#4554)

* Refactor BibEntry deprecated method

* Fixed error

* More on checkstyle fixing

* Fixed checkstyle issues

* Added custom entrytype for types not registered in the enumerator.

* Added getTypeOrDefault method refactor code to use it and fix NPE problem

* Fixing checkstyle rules

* More on checkstyle

* More on getType getTypeOrDefault replacement

* Revert Article EntryType into Electronic

* Added break line between different packages

* Refactor BibtextEntryTypes.getTypeOrDefault method

* Removed unused import

* Removed extra new line, checkstyle error fixing

* Delete the deprecated BibEntry Constructor (#4560)

* Bump xmpbox from 2.0.12 to 2.0.13 (#4561)

Bumps xmpbox from 2.0.12 to 2.0.13.

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Bump checkstyle from 8.15 to 8.16 (#4562)

Bumps [checkstyle](https://github.com/checkstyle/checkstyle) from 8.15 to 8.16.
- [Release notes](https://github.com/checkstyle/checkstyle/releases)
- [Commits](checkstyle/checkstyle@checkstyle-8.15...checkstyle-8.16)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Do not extract file ending from Urls (#4547)

* Fixes #4544 Do not extract file ending from Urls

* Add tests

* file type for any resource type

* Keep simple file name extraction for files

* checkstyle

* Converts integrity check dialog to JavaFX (#4559)

* Converts integrity check dialog to JavaFX

Moreover:
- Show entry by reference and not by id. Fixes #2181.
- Fixes a few issues that occurred when opening the entry editor by code from the integrity dialog
- Reuse gridpane in entry editor (should have a slightly superior performance)
- Improve display of progress dialog
- Invoke copy files task using central task executor

* fix l10n
fix aborting of copy files task and showing of integrity check dialog

* fix l10n

* Add uncaught exception message (#4565)

* Add error message for uncaught exceptions

Added a new view to the project. It's shown after the uncaught exception is logged.

* Add simple text to fallback error view

Added a label asking the user to look into the logfiles for more details.

* Add error message to language files

Added the error message to the german and english language files.

* Add ErrorDialogAndWait

Removed the FallbackErrorView. Added the showErrorDialogAndWait call instead.

* BibTex parser triggered on focus out of the text area instead of on value change event

* BibTex parser triggered on focus out of the text area instead of on value change event

* Added a post-parsing validation to be sure there's no relevant unconsidered content into epilog.
Added DialogService in SourceTab as current NotificationPane seems not working.

* Added a post-parsing validation to be sure there's no relevant unconsidered content into epilog.
Added DialogService in SourceTab as current NotificationPane seems not working.

* Codacy/PR Quality Review change.

* Codacy/PR Quality Review change.
  • Loading branch information
frasca80 authored and Siedlerchr committed Jan 25, 2019
1 parent 18aba35 commit aa3657c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ private List<EntryEditorTab> createTabs() {
tabs.add(new RelatedArticlesTab(preferences, dialogService));

// Source tab
sourceTab = new SourceTab(databaseContext, undoManager, preferences.getLatexFieldFormatterPreferences(), preferences.getImportFormatPreferences(), fileMonitor);
sourceTab = new SourceTab(databaseContext, undoManager, preferences.getLatexFieldFormatterPreferences(), preferences.getImportFormatPreferences(), fileMonitor, dialogService);
tabs.add(sourceTab);
return tabs;
}
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javafx.collections.ListChangeListener;
import javafx.scene.control.Tooltip;

import org.jabref.gui.DialogService;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.undo.NamedCompound;
Expand Down Expand Up @@ -53,8 +54,9 @@ public class SourceTab extends EntryEditorTab {
private final ObservableRuleBasedValidator sourceValidator = new ObservableRuleBasedValidator(sourceIsValid);
private final ImportFormatPreferences importFormatPreferences;
private final FileUpdateMonitor fileMonitor;
private final DialogService dialogService;

public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, LatexFieldFormatterPreferences fieldFormatterPreferences, ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor) {
public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, LatexFieldFormatterPreferences fieldFormatterPreferences, ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor, DialogService dialogService) {
this.mode = bibDatabaseContext.getMode();
this.setText(Localization.lang("%0 source", mode.getFormattedName()));
this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName())));
Expand All @@ -63,6 +65,7 @@ public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undo
this.fieldFormatterPreferences = fieldFormatterPreferences;
this.importFormatPreferences = importFormatPreferences;
this.fileMonitor = fileMonitor;
this.dialogService = dialogService;

}

Expand Down Expand Up @@ -95,22 +98,29 @@ protected void bindToEntry(BibEntry entry) {
if (sourceValidator.getValidationStatus().isValid()) {
notificationPane.hide();
} else {
sourceValidator.getValidationStatus().getHighestMessage().ifPresent(validationMessage -> notificationPane.show(validationMessage.getMessage()));
sourceValidator.getValidationStatus().getHighestMessage().ifPresent(validationMessage -> {
notificationPane.show(validationMessage.getMessage());//this seems not working
dialogService.showErrorDialogAndWait(validationMessage.getMessage());
});
}
});
this.setContent(codeArea);

// Store source for every change in the source code
// Store source for on focus out event in the source code (within its text area)
// and update source code for every change of entry field values
BindingsHelper.bindContentBidirectional(entry.getFieldsObservable(), codeArea.textProperty(), this::storeSource, fields -> {
BindingsHelper.bindContentBidirectional(entry.getFieldsObservable(), codeArea.focusedProperty(), onFocus -> {
if (!onFocus) {
storeSource(codeArea.textProperty().getValue());
}
}, fields -> {
DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> {
codeArea.clear();
try {
codeArea.appendText(getSourceString(entry, mode, fieldFormatterPreferences));
} catch (IOException ex) {
codeArea.setEditable(false);
codeArea.appendText(ex.getMessage() + "\n\n" +
Localization.lang("Correct the entry, and reopen editor to display/edit source."));
Localization.lang("Correct the entry, and reopen editor to display/edit source."));
LOGGER.debug("Incorrect entry", ex);
}
});
Expand Down Expand Up @@ -141,6 +151,12 @@ private void storeSource(String text) {
}
}

if (parserResult.hasWarnings()) {
// put the warning into as exception text -> it will be displayed to the user

throw new IllegalStateException(parserResult.getErrorMessage());
}

NamedCompound compound = new NamedCompound(Localization.lang("source edit"));
BibEntry newEntry = database.getEntries().get(0);
String newKey = newEntry.getCiteKeyOptional().orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;

import org.jabref.logic.bibtex.FieldContentParser;
import org.jabref.logic.exporter.BibtexDatabaseWriter;
Expand Down Expand Up @@ -70,7 +71,7 @@ public class BibtexParser implements Parser {
private boolean eof;
private int line = 1;
private ParserResult parserResult;
private MetaDataParser metaDataParser;
private final MetaDataParser metaDataParser;

public BibtexParser(ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor) {
this.importFormatPreferences = Objects.requireNonNull(importFormatPreferences);
Expand Down Expand Up @@ -211,9 +212,20 @@ private ParserResult parseFileContent() throws IOException {

parseRemainingContent();

checkEpilog();

return parserResult;
}

private void checkEpilog() {
// This is an incomplete and inaccurate try to verify if something went wrong with previous parsing activity even though there were no warnings so far
// regex looks for something like 'identifier = blabla ,'
if (!parserResult.hasWarnings() && Pattern.compile("\\w+\\s*=.*,").matcher(database.getEpilog()).find()) {
parserResult.addWarning("following BibTex fragment has not been parsed:\n" + database.getEpilog());
}

}

private void parseRemainingContent() {
database.setEpilog(dumpTextReadSoFarToString().trim());
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javafx.scene.control.TabPane;
import javafx.stage.Stage;

import org.jabref.gui.FXDialogService;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import org.jabref.logic.importer.ImportFormatPreferences;
Expand Down Expand Up @@ -35,7 +36,7 @@ public class SourceTabTest {
public void onStart(Stage stage) {
area = new CodeArea();
area.appendText("some example\n text to go here\n across a couple of \n lines....");
sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), mock(ImportFormatPreferences.class), new DummyFileUpdateMonitor());
sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), mock(ImportFormatPreferences.class), new DummyFileUpdateMonitor(), new FXDialogService());
pane = new TabPane(
new Tab("main area", area),
new Tab("other tab", new Label("some text")),
Expand Down

0 comments on commit aa3657c

Please sign in to comment.