Skip to content

Commit

Permalink
Add a "view as BibTeX" option before importing an entry from the cita…
Browse files Browse the repository at this point in the history
…tion relation tab JabRef#11826
  • Loading branch information
Martin Mochnacký committed Sep 29, 2024
1 parent bd5439a commit c6b6275
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added a "view as BibTeX" option before importing an entry from the citation relation tab. [#11826](https://github.com/JabRef/jabref/issues/11826)
- We added probable search hits instead of exact matches. Sorting by hit score can be done by the new score table column. [#11542](https://github.com/JabRef/jabref/pull/11542)
- We added support finding LaTeX-encoded special characters based on plain Unicode and vice versa. [#11542](https://github.com/JabRef/jabref/pull/11542)
- When a search hits a file, the file icon of that entry is changed accordingly. [#11542](https://github.com/JabRef/jabref/pull/11542)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.Subscription;
import jakarta.inject.Inject;
import org.fxmisc.richtext.CodeArea;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -474,4 +475,8 @@ public void nextPreviewStyle() {
public void previousPreviewStyle() {
this.previewTabs.forEach(OffersPreview::previousPreviewStyle);
}

public CodeArea getEntrySource(BibEntry entry) {
return sourceTab.getEntryCodeArea(entry);
}
}
32 changes: 26 additions & 6 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ public EditAction(StandardActions command) {
@Override
public void execute() {
switch (command) {
case COPY -> codeArea.copy();
case CUT -> codeArea.cut();
case PASTE -> codeArea.paste();
case SELECT_ALL -> codeArea.selectAll();
case COPY ->
codeArea.copy();
case CUT ->
codeArea.cut();
case PASTE ->
codeArea.paste();
case SELECT_ALL ->
codeArea.selectAll();
}
codeArea.requestFocus();
}
Expand Down Expand Up @@ -237,7 +241,8 @@ private void updateCodeArea() {
codeArea.appendText(getSourceString(currentEntry, mode, fieldPreferences));
codeArea.setEditable(true);
highlightSearchPattern();
} catch (IOException ex) {
} catch (
IOException ex) {
codeArea.setEditable(false);
codeArea.appendText(ex.getMessage() + "\n\n" +
Localization.lang("Correct the entry, and reopen editor to display/edit source."));
Expand Down Expand Up @@ -331,7 +336,10 @@ private void storeSource(BibEntry outOfFocusEntry, String text) {
undoManager.addEdit(compound);

sourceIsValid.setValue(null);
} catch (InvalidFieldValueException | IllegalStateException | IOException ex) {
} catch (
InvalidFieldValueException |
IllegalStateException |
IOException ex) {
sourceIsValid.setValue(ValidationMessage.error(Localization.lang("Problem with parsing entry") + ": " + ex.getMessage()));
LOGGER.debug("Incorrect source", ex);
}
Expand All @@ -347,4 +355,16 @@ private void listenForSaveKeybinding(KeyEvent event) {
}
});
}

public CodeArea getEntryCodeArea(BibEntry entry) {
CodeArea ca = new CodeArea();
try {
ca.appendText(getSourceString(entry, mode, fieldPreferences));
} catch (
IOException ex) {
ca = null;
LOGGER.debug("Incorrect entry", ex);
}
return ca;
}
}
Loading

0 comments on commit c6b6275

Please sign in to comment.