Skip to content

Fix issue where "Close library" menu item is not disabled correctly#10950

Merged
calixtus merged 8 commits into
JabRef:mainfrom
martinctl:fix-issue-10948
Mar 3, 2024
Merged

Fix issue where "Close library" menu item is not disabled correctly#10950
calixtus merged 8 commits into
JabRef:mainfrom
martinctl:fix-issue-10948

Conversation

@martinctl

Copy link
Copy Markdown
Contributor

Fixed a bug that allowed you to click on the File -> Close library menu item even if no library was open. When the button was pressed in this situation, the following error was uncaught.

image

This PR prevents the closeCurrentTab method from calling closeTab with null as a parameter, and disables the menu item (and its associated shortcut) when there is no library tab open.

Screen.Recording.2024-02-29.at.18.10.12.mov

Closes #10948

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.

@calixtus calixtus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, thanks for your interest in JabRef and Open Source programming.
The changes you made look really good and i think codewise they are already pretty good. I just have a suggestion of placement of the null check.

Comment on lines +755 to +759
LibraryTab currentTab = getCurrentLibraryTab();
if (currentTab == null) {
return false;
}
return closeTab(currentTab);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would suggest moving this check on null to CloseDatabaseAction#execute, then this will be consistent with other actions and we keep the view (yes i know, right now according to the mvvm pattern, jabrefframe is still way off a pure view, but it gets there eventually).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. But in this case, do you suggest to call the getCurrentLibraryTab on tabContainer before calling closeCurrentTab ? That would make two calls to getCurrentLibraryTab.
Or maybe I should implement a method getTabCount to know if there is at least one tab.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, just return from the execute method (fail fast) with a log message if the the library tab and the currently opened tab is null.

@martinctl martinctl requested a review from calixtus March 2, 2024 18:12
koppor
koppor previously approved these changes Mar 3, 2024

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tried out, looks good:

image

Comment thread CHANGELOG.md Outdated
- We fixed an issue where the `File -> Close library` menu item was not disabled when no library was open. [#10948](https://github.com/JabRef/jabref/issues/10948)
- We fixed an issue where the Document Viewer would show the PDF in only half the window when maximized. [#10934](https://github.com/JabRef/jabref/issues/10934)


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the next PR: Please no additional empty lines in CHANGELOG.md. This will lead to merge conflicts.

public void execute() {
Platform.runLater(() -> {
if (libraryTab == null) {
if (tabContainer.getCurrentLibraryTab() == null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think, this code will never be reached, but good to be defensive.

@koppor koppor added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Mar 3, 2024
@calixtus calixtus enabled auto-merge March 3, 2024 21:54
@calixtus calixtus added this pull request to the merge queue Mar 3, 2024
Merged via the queue into JabRef:main with commit 3c632e3 Mar 3, 2024
@martinctl martinctl deleted the fix-issue-10948 branch March 4, 2024 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught exception when closing a library that does not exists

4 participants