Skip to content

Add 'Open example library' button to Welcome Tab #13068

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

Merged
merged 15 commits into from
May 15, 2025

Conversation

khushp3
Copy link
Contributor

@khushp3 khushp3 commented May 6, 2025

Closes #13014

  • Moved Chocolate.bib to jabgui/src/main/resources
  • Added an "Open example library" button
  • Loads Chocolate.bib from resources
  • Saves it as a temp file
  • Opens it as a new library
  • Deletes it when the VM terminates

PR image

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • [/] Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (if change is visible to the user)
  • 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.

- Moved Chocolate.bib to jabgui/src/main/resources
- Added an "Open example library" button
- Loads Chocolate.bib from resources
- Saves it as a temp file
- Opens it as a new library
- Deletes it when the VM terminates
taskExecutor).openFiles(List.of(tmpFile));
tmpFile.toFile().deleteOnExit();
} catch (IOException ex) {
throw new RuntimeException(ex);
Copy link

Choose a reason for hiding this comment

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

Using exceptions for control flow is not recommended. Exceptions should be used for exceptional states, not for normal control flow.

Copy link
Member

Choose a reason for hiding this comment

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

Just add a logger statement here or show an errror dialog
dialogService.showEror...

@khushp3 khushp3 changed the title Changes: Changes: #13014 May 6, 2025
@khushp3 khushp3 changed the title Changes: #13014 Changes: May 6, 2025
@khushp3 khushp3 changed the title Changes: Added 'Open example library' button to Welcome Tab May 6, 2025
}
}
} catch (IOException ex) {
throw new RuntimeException(ex);
Copy link
Member

Choose a reason for hiding this comment

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

same here

@koppor koppor changed the title Added 'Open example library' button to Welcome Tab Add 'Open example library' button to Welcome Tab May 8, 2025
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

tmp file is not the right approach.

if (in != null) {
Path tmpFile = Files.createTempFile("example-library", ".bib");
try {
Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING);
Copy link
Member

Choose a reason for hiding this comment

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

Wrong approach.

  1. Create a new library
  2. Fill it with contents of Chocolate.bib. For that, you need to use org.jabref.logic.importer.fileformat.BibtexParser#BibtexParser(org.jabref.logic.importer.ImportFormatPreferences). Then you can call org.jabref.model.database.BibDatabase#insertEntries(java.util.List<org.jabref.model.entry.BibEntry>) - similar to addExampleButton.setOnAction(...

Copy link
Member

Choose a reason for hiding this comment

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

Please try to keep the file in jablib. Report back if you cannot load it.

khushp3 added 3 commits May 11, 2025 12:29
- Passes each entry in "Chocolate.bib"
- Creates an empty database object
- Inserts the entries into the database
- Wraps the database in BibDatabaseContext
- Creates a new library tab with the data loaded from "Chocolate.bib"
@khushp3 khushp3 requested a review from koppor May 12, 2025 14:42
@koppor
Copy link
Member

koppor commented May 12, 2025

@khushp3 please do not request a review before you have addressed the issues risen by the tests

Comment on lines 146 to 152
BibtexParser bibtexParser = new BibtexParser(preferences.getImportFormatPreferences(), fileUpdateMonitor);
List<BibEntry> entries = bibtexParser.parseEntries(in);

BibDatabase database = new BibDatabase();
database.insertEntries(entries);

BibDatabaseContext databaseContext = new BibDatabaseContext(database);
Copy link
Member

Choose a reason for hiding this comment

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

Seeing this, there is a more simpler way:

Suggested change
BibtexParser bibtexParser = new BibtexParser(preferences.getImportFormatPreferences(), fileUpdateMonitor);
List<BibEntry> entries = bibtexParser.parseEntries(in);
BibDatabase database = new BibDatabase();
database.insertEntries(entries);
BibDatabaseContext databaseContext = new BibDatabaseContext(database);
reader = Importer.getReader(inputStream);
BibtexParser bibtexParser = new BibtexParser(preferences.getImportFormatPreferences(), fileUpdateMonitor);
ParserResult result = bibtexParser.parse(reader);
BibDatabaseContext databaseContext = result.getDatabaseContext();

I found simlar code in org.jabref.logic.importer.fileformat.BibtexParser

Comment on lines 137 to 171
fileHistoryMenu.getItems().addListener((ListChangeListener<MenuItem>) _ -> updateWelcomeRecentLibraries());
fileHistoryMenu.getItems().addListener((ListChangeListener<MenuItem>) e -> updateWelcomeRecentLibraries());
Copy link
Member

Choose a reason for hiding this comment

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

Is this change AI generated? Please keep _

@koppor koppor mentioned this pull request May 15, 2025
1 task
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.util.FileUpdateMonitor;

import static org.jabref.gui.edit.automaticfiededitor.AbstractAutomaticFieldEditorTabViewModel.LOGGER;
Copy link
Member

Choose a reason for hiding this comment

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

Copy and paste issue - see https://devdocs.jabref.org/code-howtos/logging.html how to initialize the logger

Comment on lines 145 to 146
Reader reader;
reader = Importer.getReader(in);
Copy link
Member

Choose a reason for hiding this comment

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

Merge in one line; you can even move it up into the try braces

@@ -124,7 +134,28 @@ private VBox createWelcomeStartBox() {
stateManager, fileUpdateMonitor, entryTypesManager, undoManager, clipBoardManager,
taskExecutor).execute());

return createVBoxContainer(startLabel, newLibraryLink, openLibraryLink);
Hyperlink openExampleLibraryLink = new Hyperlink(Localization.lang("Open example library"));
Copy link
Member

Choose a reason for hiding this comment

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

  1. The string should be New example library
  2. Rename "New library" to "New empty library"
  3. position it one above, so that the order is
  • New empty library
  • New example library
  • Open library

…d JabRef_en.properties

- Correctly imported LOGGER
@@ -62,7 +62,7 @@ public enum StandardActions implements Action {
SKIMMED(Localization.lang("Set read status to skimmed"), IconTheme.JabRefIcons.READ_STATUS_SKIMMED, KeyBinding.SKIMMED),
RELEVANCE(Localization.lang("Relevance"), IconTheme.JabRefIcons.RELEVANCE),
RELEVANT(Localization.lang("Toggle relevance"), IconTheme.JabRefIcons.RELEVANCE),
NEW_LIBRARY(Localization.lang("New library"), IconTheme.JabRefIcons.NEW),
NEW_LIBRARY(Localization.lang("New empty library"), IconTheme.JabRefIcons.NEW),
Copy link

Choose a reason for hiding this comment

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

The change from 'New library' to 'New empty library' should be consistent with other strings and grouped semantically. Ensure that similar actions use consistent terminology.

@koppor koppor marked this pull request as ready for review May 15, 2025 15:01
@koppor koppor enabled auto-merge May 15, 2025 15:01
@koppor
Copy link
Member

koppor commented May 15, 2025

I fixed the small test issues (wrong variable order and translation strings)

Now, it is good to go.

Thank you for the efforts!

Copy link

trag-bot bot commented May 15, 2025

@trag-bot didn't find any issues in the code! ✅✨

1 similar comment
Copy link

trag-bot bot commented May 15, 2025

@trag-bot didn't find any issues in the code! ✅✨

@koppor koppor added this pull request to the merge queue May 15, 2025
Merged via the queue into JabRef:main with commit dca5cd5 May 15, 2025
1 check passed
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.

Welcome Tab: "Open example library"
3 participants