Skip to content

Reset canceled state in GenerateCitationKeyAction on execute - #17787

Merged
koppor merged 8 commits into
JabRef:mainfrom
SachinyadavAug20:fix-citation-key-toolbar-cancel-17748
Nov 23, 2026
Merged

koppor merged 8 commits into
JabRef:mainfrom
SachinyadavAug20:fix-citation-key-toolbar-cancel-17748

Conversation

@SachinyadavAug20

@SachinyadavAug20 SachinyadavAug20 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When clicking the "Generate citation keys" toolbar button and choosing "Cancel" on the overwrite confirmation dialog, isCanceled was left as true. Since MainToolBar retains the same GenerateCitationKeyAction instance for its lifetime, any later clicks on the toolbar button were ignored because isCanceled remained true.

Reset isCanceled = false; at the start of execute() so each click starts with a clean state.

jabref-contrib-policy:4.2:reviewed:ok

Steps to test

  1. Open a library with at least one entry having a citation key and another entry without a key.
  2. Select the entry with a citation key and click the "Generate citation keys" toolbar button (key icon).
  3. When the overwrite confirmation dialog appears, click Cancel.
  4. Now select the entry without a citation key and click the "Generate citation keys" toolbar button again.
  5. The citation key is generated for the entry (previously nothing happened).

Testing video

2026-11-11.20-17-47.mp4

Related issues and pull requests

Closes #17748

AI usage

Used Antigravity CLI for locating the action instantiation and unit test scaffolding. Verified manually in running JabRef and added test in GenerateCitationKeyActionTest.

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • If AI tools were used, I disclosed them in the "AI usage" section and reviewed, understood, and take full ownership of all AI-generated code
  • 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 one sentence (max 20 words) to CHANGELOG.md describing the change from the user's point of view (if the 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

@jabref-machine jabref-machine added the dev: send-to-black-forest Port to the black-forest branch of JabRef/jabref-black-forest after merging (ADR-0073) label Nov 11, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Restore citation-key toolbar action after canceling an overwrite

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 Less than 10 minutes

Grey Divider

AI Description

• Reset cancellation state on each citation-key generation attempt so later toolbar clicks work.
• Add a regression test for canceling an overwrite, then generating a key for another entry.
• Document the user-visible fix in the changelog.
Diagram

graph TD
  T["Toolbar click"] --> A["Reset cancellation"] --> C{"Overwrite confirmation"} -->|Proceed| B["Generate keys"] --> E["Selected entries"]
  C -->|Cancel, then retry| T
  A -->|No overwrite needed| B
Loading
High-Level Assessment

Resetting the flag at the start of execute is the smallest fix for an action retained by the toolbar. Recreating the action for every click would change toolbar wiring unnecessarily.

Files changed (3) +28 / -0

Bug fix (1) +1 / -0
GenerateCitationKeyAction.javaClear cancellation state on each execution +1/-0

Clear cancellation state on each execution

• Resets isCanceled before reading the selection so canceling one overwrite confirmation cannot suppress a subsequent generation attempt on the same action instance.

jabgui/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java

Tests (1) +26 / -0
GenerateCitationKeyActionTest.javaCover generation after a canceled overwrite +26/-0

Cover generation after a canceled overwrite

• Reuses one action across two executions: the first cancels an overwrite and preserves the existing key; the second generates a key for a newly selected entry.

jabgui/src/test/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyActionTest.java

Documentation (1) +1 / -0
CHANGELOG.mdDocument the restored toolbar behavior +1/-0

Document the restored toolbar behavior

• Adds a Fixed entry explaining that generating citation keys still works after an overwrite is canceled, with a link to issue #17748.

CHANGELOG.md

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

qodo-free-for-open-source-projects Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

Grey Divider

Resolved findings
1. A predicate-named helper silently empties the caller's list ✓ Resolved Medium
Description
hasUserCanceledOverwrite is named as a yes/no query about the user's cancel choice, but on the
shouldAvoidOverwriteCiteKey path it calls entries.removeIf(BibEntry::hasCitationKey), which
mutates the list passed in from generateKeysIn. The caller then relies on that side effect for the
keys it later generates and for the entries.size() counts in the progress and notification
messages. A later maintainer who treats the method as a pure check, or reorders the isEmpty()
guard relative to it, will get wrong behaviour, such as a task that runs over zero entries.

2. A comment ends up after an early return and reads as dead code ✓ Resolved Medium
Description
In hasUserCanceledOverwrite, the comment about warning the user before overriding keys was left
below return false; inside the first branch, so it now sits in the wrong place and describes the
else if branch. A later reader may take it for dead or misplaced code and move or remove it while
editing this method.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions github-actions Bot added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Nov 11, 2026

@doraem-on doraem-on left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice work , some changes needed

@github-actions github-actions Bot added status: changes-required Pull requests that are not yet complete and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Nov 12, 2026
@github-actions github-actions Bot added size: medium component: entry-editor status: changes-required Pull requests that are not yet complete and removed size: small component: entry-editor status: changes-required Pull requests that are not yet complete labels Nov 12, 2026

@doraem-on doraem-on left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good , awaiting second review

@SachinyadavAug20

Copy link
Copy Markdown
Contributor Author

Hi @doraem-on / maintainers, the changes have been approved by @doraem-on. Could a maintainer please update the label from status: changes-required to status: awaiting-second-review?

The Windows jablib and JBang CI checks are upstream flakes (all jabgui tests pass), and the black-forest port conflict is ready to be handled as a draft port PR upon merge per JabRef guidelines. Thank you!

@github-actions github-actions Bot added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: changes-required Pull requests that are not yet complete labels Nov 14, 2026
@koppor
koppor added this pull request to the merge queue Nov 23, 2026
@github-actions github-actions Bot added status: to-be-merged PRs which are accepted and should go into the merge-queue. and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Nov 23, 2026
Merged via the queue into JabRef:main with commit 01dff97 Nov 23, 2026
75 of 76 checks passed
@jabref-machine

Copy link
Copy Markdown
Collaborator

Created backport PR for black-forest:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin port-17787-to-black-forest
git worktree add --checkout .worktree/port-17787-to-black-forest port-17787-to-black-forest
cd .worktree/port-17787-to-black-forest
git reset --hard HEAD^
git cherry-pick -x 01dff979299e1c9fc36ace8c33290f2f6ef3dbba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: citationkey-generator component: entry-editor dev: send-to-black-forest Port to the black-forest branch of JabRef/jabref-black-forest after merging (ADR-0073) size: medium 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.

Generate citation keys toolbar button stops working after canceling an overwrite

4 participants