Skip to content

Preventing library disappearing when closing tab #12909

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 10 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where valid DOI could not be imported if it had special characters like `<` or `>`. [#12434](https://github.com/JabRef/jabref/issues/12434)
- We fixed an issue where the tooltip only displayed the first linked file when hovering. [#12470](https://github.com/JabRef/jabref/issues/12470)
- We fixed an issue where some texts in the "Citation Information" tab and the "Preferences" dialog could not be translated. [#12883](https://github.com/JabRef/jabref/pull/12883)
- We fixed an issue where libraries would sometimes be hidden when closing tabs with the Welcome tab open. [#12894](https://github.com/JabRef/jabref/issues/12894)

### Removed

Expand Down
23 changes: 19 additions & 4 deletions src/main/java/org/jabref/gui/frame/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void initKeyBindings() {
case FOCUS_GROUP_LIST:
sidePane.getSidePaneComponent(SidePaneType.GROUPS).requestFocus();
event.consume();
break;
break;
case NEXT_LIBRARY:
tabbedPane.getSelectionModel().selectNext();
event.consume();
Expand Down Expand Up @@ -344,6 +344,21 @@ private void initBindings() {
stateManager.setActiveDatabase(libraryTab.getBibDatabaseContext());
stateManager.activeTabProperty().set(Optional.of(libraryTab));
} else if (selectedTab == null || selectedTab instanceof WelcomeTab) {
if (stateManager.getActiveDatabase().isPresent()) {
String activeUID = stateManager.getActiveDatabase().get().getUid();

// Check if the previously active database was closed
boolean wasClosed = tabbedPane.getTabs().stream()
.filter(tab -> tab instanceof LibraryTab)
.noneMatch(ltab -> ((LibraryTab) ltab).getBibDatabaseContext().getUid().equals(activeUID));

// Select the next tab, instead of the Home page
if (wasClosed) {
tabbedPane.getSelectionModel().selectNext();
return;
}
}

// All databases are closed or {@link WelcomeTab} is open
stateManager.setActiveDatabase(null);
stateManager.activeTabProperty().set(Optional.empty());
Expand Down Expand Up @@ -520,9 +535,9 @@ public boolean closeTab(LibraryTab tab) {
public boolean closeTabs(@NonNull List<LibraryTab> tabs) {
// Only accept library tabs that are shown in the tab container
List<LibraryTab> toClose = tabs.stream()
.distinct()
.filter(getLibraryTabs()::contains)
.toList();
.distinct()
.filter(getLibraryTabs()::contains)
.toList();

if (toClose.isEmpty()) {
// Nothing to do
Expand Down
Loading