Skip to content

Add context menu entry to sort tabs alphabetically#15425

Merged
Siedlerchr merged 15 commits into
JabRef:mainfrom
DarkMysterio:fix-15423-sort-tabs
Apr 7, 2026
Merged

Add context menu entry to sort tabs alphabetically#15425
Siedlerchr merged 15 commits into
JabRef:mainfrom
DarkMysterio:fix-15423-sort-tabs

Conversation

@DarkMysterio

@DarkMysterio DarkMysterio commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

fixes #15423

Related issues and pull requests

Closes #15423

PR Description

This PR introduces a "Sort tabs alphabetically" option to the context menu of the library tabs, positioned directly below "Open terminal here". The intent is to help users who manage multiple open libraries easily organize and navigate their workspace. The tabs are sorted case-insensitively, keeping the UI clean and improving overall usability when dealing with cluttered tab bars.

Steps to test

  1. Open JabRef.
  2. Create multiple new libraries (e.g., File -> New library) and save them with names that are not in alphabetical order (for example: Zebra.bib, Apple.bib, Monkey.bib).
  3. Look at the tab bar at the top and ensure you have multiple tabs open.
  4. Right-click on any of the library tabs to open the context menu.
  5. Verify that the new option "Sort tabs alphabetically" appears exactly below the "Open terminal here" option.
  6. Click on "Sort tabs alphabetically".
  7. Verify that all the open tabs immediately reorder themselves in alphabetical order from left to right (e.g., Apple.bib, Monkey.bib, Zebra.bib), ignoring case sensitivity.

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef (always required)
  • [/] I added JUnit tests for changes (if applicable)
  • I added screenshots in the PR description (if change is visible to the user)
  • I added a screenshot in the PR description showing a library with a single entry with me as author and as title the issue number
  • I described the change in CHANGELOG.md in a way that can be understood by the average user (if change is visible to the user)
  • [/] I checked the user documentation for up to dateness and submitted a pull request to our user documentation repository
t1 {EC23BE04-8622-4B6F-BBE6-A043FC305147}

@github-actions

Copy link
Copy Markdown
Contributor

Hey @DarkMysterio! 👋

Thank you for contributing to JabRef!

We have automated checks in place, based on which you will soon get feedback if any of them are failing. We also use Qodo for review assistance. It will update your pull request description with a review help and offer suggestions to improve the pull request.

After all automated checks pass, a maintainer will also review your contribution. Once that happens, you can go through their comments in the "Files changed" tab and act on them, or reply to the conversation if you have further inputs. You can read about the whole pull request process in our contribution guide.

Please ensure that your pull request is in line with our AI Usage Policy and make necessary disclosures.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Add context menu entry to sort tabs alphabetically

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Adds context menu entry to sort library tabs alphabetically
• Implements tab sorting functionality in JabRefFrame
• Updates localization and changelog documentation
Diagram
flowchart LR
  A["StandardActions enum"] -- "adds SORT_TABS_ALPHABETICALLY action" --> B["JabRefFrame context menu"]
  B -- "executes sort command" --> C["Sorted library tabs"]
  D["Localization properties"] -- "provides UI text" --> B
  E["CHANGELOG.md"] -- "documents feature" --> F["Release notes"]
Loading

Grey Divider

File Changes

1. jabgui/src/main/java/org/jabref/gui/actions/StandardActions.java ✨ Enhancement +1/-0

Add SORT_TABS_ALPHABETICALLY action enum

• Adds new SORT_TABS_ALPHABETICALLY enum constant with display text
• Positioned after OPEN_CONSOLE action in the enum

jabgui/src/main/java/org/jabref/gui/actions/StandardActions.java


2. jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java ✨ Enhancement +8/-0

Implement tab sorting in context menu

• Adds menu item for SORT_TABS_ALPHABETICALLY action to tab context menu
• Implements SimpleCommand that sorts tabs case-insensitively by text
• Sorts tabbedPane.getTabs() using compareToIgnoreCase() comparator

jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java


3. CHANGELOG.md 📝 Documentation +1/-0

Document sort tabs feature

• Documents new "Sort tabs alphabetically" feature in unreleased changes section

CHANGELOG.md


View more (1)
4. jablib/src/main/resources/l10n/JabRef_en.properties Localization +2/-0

Add English localization for sort action

• Adds English localization entry for "Sort tabs alphabetically" text
• Positioned after "Open terminal here" property

jablib/src/main/resources/l10n/JabRef_en.properties


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX Issues (0)

Grey Divider


Action required

1. Hardcoded SORT_TABS_ALPHABETICALLY label📘
Description
The new StandardActions.SORT_TABS_ALPHABETICALLY uses a hardcoded user-facing string instead of
Localization.lang(...), so it will not be translated. This violates the requirement that all
UI-visible text be localized.
Code

jabgui/src/main/java/org/jabref/gui/actions/StandardActions.java[127]

+    SORT_TABS_ALPHABETICALLY("Sort tabs alphabetically"),
Evidence
PR Compliance ID 18 requires user-facing UI strings to be localized via Localization.lang(...).
The new action is defined with the raw string "Sort tabs alphabetically" even though a
localization entry was added.

AGENTS.md
jabgui/src/main/java/org/jabref/gui/actions/StandardActions.java[127-127]
jablib/src/main/resources/l10n/JabRef_en.properties[536-537]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`StandardActions.SORT_TABS_ALPHABETICALLY` introduces a hardcoded, user-facing label (`"Sort tabs alphabetically"`) instead of using `Localization.lang(...)`, preventing translation.
## Issue Context
A corresponding localization key was added to `JabRef_en.properties`, so the action label should reference it via `Localization.lang("Sort tabs alphabetically")` (or reuse an existing localization key if one already exists).
## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/actions/StandardActions.java[127-127]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Tab sort can NPE🐞
Description
The new tab-sorting command calls compareToIgnoreCase on tab text without null-handling, which will
throw a NullPointerException if any tab’s text is still null. LibraryTab text is not set in the
constructor and is only set later via a deferred Platform.runLater update, so sorting soon after
opening/loading a tab can crash the UI.
Code

jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java[R612-618]

+                factory.createMenuItem(StandardActions.SORT_TABS_ALPHABETICALLY, new SimpleCommand() {
+                    @Override
+                    public void execute() {
+                        tabbedPane.getTabs().sort((tab1, tab2) ->
+                                tab1.getText().compareToIgnoreCase(tab2.getText())
+                        );
+                    }
Evidence
JabRefFrame sorts using tab1.getText().compareToIgnoreCase(tab2.getText()) with no null checks.
LibraryTab does not set any initial tab text in its constructor; instead it schedules updateTabTitle
via Platform.runLater, and updateTabTitle later sets textProperty(). This creates a window where
getText() can be null, leading to a NullPointerException during sorting.

jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java[598-619]
jabgui/src/main/java/org/jabref/gui/LibraryTab.java[175-265]
jabgui/src/main/java/org/jabref/gui/LibraryTab.java[391-449]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The tab sort comparator dereferences `Tab#getText()` without null handling, so sorting can crash with an NPE when a tab’s text hasn’t been initialized yet.
### Issue Context
`LibraryTab` updates its title asynchronously (scheduled via `Platform.runLater`), which means newly opened/loading tabs can temporarily have `null` text.
### Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java[612-618]
### Suggested fix
- Replace the lambda comparator with a null-safe comparator, e.g. compare on `Optional.ofNullable(tab.getText()).orElse("")`.
- (Optional but recommended) Keep non-`LibraryTab` tabs (e.g., `WelcomeTab`) in place by sorting only library tabs or by using a comparator that orders non-library tabs consistently and uses a stable tie-break (return 0 for non-library vs non-library).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@github-actions github-actions Bot added the good first issue An issue intended for project-newcomers. Varies in difficulty. label Mar 25, 2026
Comment thread jabgui/src/main/java/org/jabref/gui/actions/StandardActions.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java
@testlens-app

This comment has been minimized.

@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Mar 25, 2026
@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@github-actions github-actions Bot added status: no-bot-comments and removed status: changes-required Pull requests that are not yet complete labels Mar 27, 2026
@github-actions github-actions Bot added status: changes-required Pull requests that are not yet complete and removed status: no-bot-comments labels Mar 27, 2026
@testlens-app

This comment has been minimized.

@github-actions github-actions Bot added status: no-bot-comments and removed status: changes-required Pull requests that are not yet complete labels Mar 27, 2026
Comment thread CHANGELOG.md Outdated
@testlens-app

This comment has been minimized.

Updated the changelog to include new features and changes.
@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@github-actions github-actions Bot added status: no-bot-comments and removed status: no-bot-comments status: changes-required Pull requests that are not yet complete labels Mar 28, 2026
@DarkMysterio DarkMysterio requested a review from subhramit March 31, 2026 15:57
@testlens-app

This comment has been minimized.

@testlens-app

testlens-app Bot commented Apr 1, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: c029ac3
▶️ Tests: 8467 executed
⚪️ Checks: 50/50 completed


Learn more about TestLens at testlens.app.

@DarkMysterio

Copy link
Copy Markdown
Contributor Author

Hello i think my PR is ready for review

Siedlerchr
Siedlerchr previously approved these changes Apr 7, 2026
Siedlerchr
Siedlerchr previously approved these changes Apr 7, 2026
@github-actions github-actions Bot added status: changes-required Pull requests that are not yet complete and removed status: no-bot-comments labels Apr 7, 2026
@Siedlerchr Siedlerchr disabled auto-merge April 7, 2026 20:30
@Siedlerchr Siedlerchr enabled auto-merge April 7, 2026 20:32
@github-actions github-actions Bot added status: no-bot-comments and removed status: changes-required Pull requests that are not yet complete labels Apr 7, 2026
@Siedlerchr Siedlerchr added this pull request to the merge queue Apr 7, 2026
@github-actions github-actions Bot added the status: to-be-merged PRs which are accepted and should go into the merge-queue. label Apr 7, 2026
Merged via the queue into JabRef:main with commit bc61022 Apr 7, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first contrib good first issue An issue intended for project-newcomers. Varies in difficulty. status: no-bot-comments status: to-be-merged PRs which are accepted and should go into the merge-queue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add context menu entry "Sort tabs alphabetically"

3 participants