Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "view as BibTeX" option before importing an entry from the cita… #11847

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

JamseBonde007
Copy link

@JamseBonde007 JamseBonde007 commented Sep 29, 2024

Add a "view as BibTeX" option before importing an entry from the cita…tion relation tab #11826

This PR implements the feature requested in issue #10869. It adds a button that allows users to display a dialog showing the full BibTeX entry when importing citations from the Citation Relation tab. This enhancement will help users decide whether to import a potentially "duplicate" record by allowing them to see the full details of the entry in BibTeX format.

image
image

Closes #11826

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

ca.appendText(getSourceString(entry, mode, fieldPreferences));
} catch (
IOException ex) {
ca = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never return null. Use Optional<CodeArea> or throw an exception: The caller should explicitly know that null is returned.

Reason: We do not rely on null annotations really.

Comment on lines 355 to 356
} catch (
IOException ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to keep it in one line. We know that IntelliJ outformats it like that - we did not find a way to fix this issue.

@@ -2782,3 +2782,8 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The
Currently\ selected\ JStyle\:\ '%0' = Currently selected JStyle: '%0'
Currently\ selected\ CSL\ Style\:\ '%0' = Currently selected CSL Style: '%0'
Store\ url\ for\ downloaded\ file=Store url for downloaded file
BibTeX\ of\ that\ entry=BibTeX of that entry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-use "Show BibTeX source" (or "Show %0 source". Just check the existing strings.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exits only "Show/edit %0 source"

BibTeX\ of\ that\ entry=BibTeX of that entry
Could\ not\ load\ %0\ source=Could not load %0 source
BibTeX\ source=BibTeX source
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the existing one. I think, it is %0 source.

@@ -2782,3 +2782,8 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The
Currently\ selected\ JStyle\:\ '%0' = Currently selected JStyle: '%0'
Currently\ selected\ CSL\ Style\:\ '%0' = Currently selected CSL Style: '%0'
Store\ url\ for\ downloaded\ file=Store url for downloaded file
BibTeX\ of\ that\ entry=BibTeX of that entry
Could\ not\ load\ %0\ source=Could not load %0 source
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not more information than "Error". Thus, please use "Error" as string - and not a new text.

private EntryEditor createEntryEditor() {
Supplier<LibraryTab> tabSupplier = () -> this.libraryTab;
return new EntryEditor(this.libraryTab,
// Actions are recreated here since this avoids passing more parameters and the amount of additional memory consumption is neglegtable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, the main reason is that undo and redo are independent here. Thus, these should be fake ones? -- The BibTeX is from the external service and NOT contained in the current library. Thus, it has NOTHING to do with the current library and thus no undo/redo relation with it.

Update: I think, this is not necessary at all. No entry editor is needed.

Comment on lines 305 to 306
if (codeArea == null) {
dialogService.showWarningDialogAndWait(Localization.lang("BibTeX source", databaseContext.getMode().getFormattedName()), Localization.lang("Could not load %0 source", databaseContext.getMode().getFormattedName()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How often does this occur? Bug in the code or real use? I think, its bug in the code. Thus, please use LOGGER.warn(...) instead of a dialog service.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just return then. #FailFast. Do not use } else { .

Button showEntrySource = IconTheme.JabRefIcons.SOURCE.asButton();
showEntrySource.setTooltip(new Tooltip(Localization.lang("Show %0 source", databaseContext.getMode().getFormattedName())));
showEntrySource.setOnMouseClicked(event -> {
this.entryEditor = createEntryEditor();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a full entry editor? I think, you can just show the source without full editing capabilities.

@JamseBonde007
Copy link
Author

Thank you for your feedback! I've addressed the issues you pointed out and made the necessary changes. Please take a look and let me know if everything looks good now.

StringWriter writer = new StringWriter();
BibWriter bibWriter = new BibWriter(writer, OS.NEWLINE);
FieldWriter fieldWriter = FieldWriter.buildIgnoreHashes(this.preferences.getFieldPreferences());
new BibEntryWriter(fieldWriter, new BibEntryTypesManager()).write(entry, bibWriter, type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try to get the BibEntryTypesManager be passed? It should be available "somewhere" in the call hierarchy. org.jabref.gui.collab.entrychange.PreviewWithSourceTab also has it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an @implNote that this code is similar to PreviewWithSourceTab#getSourceString.

@Siedlerchr I think it is OK to have code duplication here. Alternatively, we could introduce org.jabref.logic.exporter.BibEntryPrinter having a single method getAsString.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code is imho okay, just the EntryTypesManaager as constructor parameter

DialogPane dialogPane = new DialogPane();
dialogPane.setPrefSize(800, 400);
dialogPane.setContent(scrollPane);
String title = Localization.lang("%0 source", "Show BibTeX");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Show BibTeX" is not localized.

Suggested change
String title = Localization.lang("%0 source", "Show BibTeX");
String title = Localization.lang("Show BibTeX source");

@@ -254,6 +271,14 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> listView)
vContainer.getChildren().addLast(openWeb);
}

Button showEntrySource = IconTheme.JabRefIcons.SOURCE.asButton();
showEntrySource.setTooltip(new Tooltip(Localization.lang("%0 source", databaseContext.getMode().getFormattedName())));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it is really BibLaTeX in this case - the citatoin fetcher always uses the bibtex dialect? Can you check? If unsure, just always use "BibTeX".

@@ -74,6 +87,9 @@ public class CitationRelationsTab extends EntryEditorTab {
private final BibEntryRelationsRepository bibEntryRelationsRepository;
private final CitationsRelationsTabViewModel citationsRelationsTabViewModel;
private final DuplicateCheck duplicateCheck;
private EntryEditor entryEditor;

private StateManager stateManager;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used. Remove.

@@ -74,6 +87,9 @@ public class CitationRelationsTab extends EntryEditorTab {
private final BibEntryRelationsRepository bibEntryRelationsRepository;
private final CitationsRelationsTabViewModel citationsRelationsTabViewModel;
private final DuplicateCheck duplicateCheck;
private EntryEditor entryEditor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used. Please remove.

It would be really nice if you scrolled through your source code in IntelliJ. That variable should be in light gray meaning: not used. 😅

The thing is that we as reviewers could overlook things. Moreover, if we comment on these kind things, there is no time to check the harder questions... 😇

@JamseBonde007
Copy link
Author

Thank you for the feedback and the tips! I've addressed the comments and reviewed the code in IntelliJ. Please take a look at the updates and let me know if everything looks good.

this.taskExecutor = taskExecutor;
setText(Localization.lang("Citation relations"));
setTooltip(new Tooltip(Localization.lang("Show articles related by citation")));

this.duplicateCheck = new DuplicateCheck(new BibEntryTypesManager());
this.entryTypesManager = new BibEntryTypesManager();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass the instance from the caller (see EntryEditor.java)

Copy link
Author

@JamseBonde007 JamseBonde007 Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally in "this.duplicateCheck = new DuplicateCheck(new BibEntryTypesManager());" a new instance is created, if I take over the instance from EntryEditor should I leave the original solution for "DuplicateCheck" or move the instance from EntryEditor as well ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the instance from EntryEditor as well. Mabe, this will also fix some bugs...

@JamseBonde007
Copy link
Author

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a "view as BibTeX" option before importing an entry from the citation relation tab
3 participants