Skip to content

Feature: Add "Copy Field Content" submenu to entry context menu#13280

Merged
calixtus merged 18 commits intoJabRef:mainfrom
yoasaaa:feature/copy-field-submenu
Aug 24, 2025
Merged

Feature: Add "Copy Field Content" submenu to entry context menu#13280
calixtus merged 18 commits intoJabRef:mainfrom
yoasaaa:feature/copy-field-submenu

Conversation

@yoasaaa
Copy link
Copy Markdown
Contributor

@yoasaaa yoasaaa commented Jun 9, 2025

Summary of changes

This PR adds a new "Copy Field Content" submenu under the existing "Copy..." context menu option for bibliography entries.

Changes made:

  • Added new StandardActions enum values for field-specific copy operations (COPY_FIELD_CONTENT, COPY_FIELD_AUTHOR, COPY_FIELD_JOURNAL, COPY_FIELD_DATE, COPY_FIELD_KEYWORDS, COPY_FIELD_ABSTRACT)
  • Extended CopyMoreAction class to handle new field copy operations with proper error handling and user feedback
  • Added specialized copyJournalField() method to handle both journal and journaltitle field compatibility
  • Modified RightClickMenu to include the new submenu
  • Implemented test coverage for all new field copy operations

Menu structure:

Copy...
├── Copy title
├── Copy field content →
│ ├── Author
│ ├── Journal
│ ├── Date
│ ├── Keywords
│ └── Abstract
├── ─────────────────────────
├── Copy citation key
├── ...

Screenshots

Before:
image

After:
image

Steps to test

  • Unit tests were added to verify the functionality of each new "Copy Field Content" option:
    • Copy Author
    • Copy Journal
    • Copy Date
    • Copy Keywords
    • Copy Abstract
  • All test cases are located in: jabgui/src/test/java/org/jabref/gui/edit/CopyMoreActionTest.java

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.

yoasaaa added 3 commits June 8, 2025 17:42
…r in tests, add null safety check for createCopyFieldContentSubMenu method and use Localization.lang() for internationalization of field display names
COPY_CITATION_TEXT(Localization.lang("Copy citation (text)")),
COPY_CITATION_PREVIEW(Localization.lang("Copy preview"), KeyBinding.COPY_PREVIEW),
COPY_FIELD_CONTENT(Localization.lang("Copy field content")),
COPY_FIELD_AUTHOR(Localization.lang("author")),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The label 'author' should be in sentence case, but it is already in lowercase. Ensure consistency with other labels which are in sentence case.

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.

Is this ever displayed, the screenshots don't contain lower cased.

Menu copyFieldContentMenu = factory.createMenu(StandardActions.COPY_FIELD_CONTENT);

// Ensure we never return null
if (copyFieldContentMenu == null) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using exceptions for normal control flow is not recommended. Instead of checking for null and throwing an exception, ensure that the method creating the menu never returns 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.

What is this? Just remove the whole if block.

@koppor
Copy link
Copy Markdown
Member

koppor commented Jun 9, 2025

@yoasaaa This is not an issue, but an idea of you? The new sub menu adds new fields, which it is OK. However, could you more elaborate on the "why" of this change, please?

List<BibEntry> selectedBibEntries = stateManager.getSelectedEntries();

List<String> fieldValues = selectedBibEntries.stream()
.filter(bibEntry -> bibEntry.getField(field).isPresent())
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.

You need to du getFieldOrAlias IMHO.

Did you check for date handling? You know, there is year, month, day, and also date. If only year is present, what does date copy do? (It should copy the year -and I hope that getFieldOrAlias supports that)

Comment on lines +311 to +313
.filter(bibEntry ->
bibEntry.getField(StandardField.JOURNAL).isPresent() ||
bibEntry.getField(StandardField.JOURNALTITLE).isPresent())
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.

Use getFieldOrAlias instead of this hack. - I think, the method can be removed completely

Menu copyFieldContentMenu = factory.createMenu(StandardActions.COPY_FIELD_CONTENT);

// Ensure we never return null
if (copyFieldContentMenu == 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.

What is this? Just remove the whole if block.

COPY_CITATION_TEXT(Localization.lang("Copy citation (text)")),
COPY_CITATION_PREVIEW(Localization.lang("Copy preview"), KeyBinding.COPY_PREVIEW),
COPY_FIELD_CONTENT(Localization.lang("Copy field content")),
COPY_FIELD_AUTHOR(Localization.lang("author")),
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.

Is this ever displayed, the screenshots don't contain lower cased.

…ng and update required localization entries to JabRef_en.properties
@yoasaaa
Copy link
Copy Markdown
Contributor Author

yoasaaa commented Jun 10, 2025

@yoasaaa This is not an issue, but an idea of you? The new sub menu adds new fields, which it is OK. However, could you more elaborate on the "why" of this change, please?

Yes, it’s not an existing issue. It is a small usability improvement I thought could be helpful. JabRef currently allows copying the title, but not other commonly used fields. From my experience, users often need to copy author names to search for their other publications, or copy keywords and abstracts for note-taking. I selected these fields (Author, Journal, Date, Keywords, Abstract) based on what I found most useful in my own experience.

Also, this is part of a university assignment where we're required to add a new feature to an open-source project.

@jabref-machine
Copy link
Copy Markdown
Collaborator

Your pull request needs to link an issue correctly.

To ease organizational workflows, please link this pull-request to the issue with syntax as described in https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue:

Linking a pull request to an issue using a keyword

You can link a pull request to an issue by using a supported keyword in the pull request's description or in a commit message.

Examples

  • Fixes #xyz links pull-request to issue. Merging the PR will close the issue.
  • Fixes https://github.com/JabRef/jabref/issues/xyz links pull-request to issue. Merging the PR will close the issue.
  • Fixes https://github.com/Koppor/jabref/issues/xyz links pull-request to issue. Merging the PR will close the issue.
  • Fixes [#xyz](https://github.com/JabRef/jabref/issues/xyz) links pull-request to issue. Merging the PR will NOT close the issue.

@koppor
Copy link
Copy Markdown
Member

koppor commented Jul 5, 2025

Copy operation should do latex2unicode using org.jabref.model.strings.LatexToUnicodeAdapter#format to make the experience maybe even more user-friendly?

Future work could be to have a preference for it 😅 (but I think "raw" copy is not needed in 2025)

@koppor
Copy link
Copy Markdown
Member

koppor commented Jul 5, 2025

@yoasaaa May I ask if you intend to work on this one? Seem only small comments left to get this in.

@yoasaaa
Copy link
Copy Markdown
Contributor Author

yoasaaa commented Jul 14, 2025

@yoasaaa May I ask if you intend to work on this one? Seem only small comments left to get this in.

Sorry for the late response! I've just updated the code. Please let me know if there's anything else I should adjust!

@yoasaaa yoasaaa requested a review from koppor July 16, 2025 16:34
…e/copy-field-submenu

# Conflicts:
#	jabgui/src/test/java/org/jabref/gui/edit/CopyMoreActionTest.java
@calixtus
Copy link
Copy Markdown
Member

I experimented a little bit with AI on parameterizing the tests. Looks fine as far as i can see. Wdyt?

Additionally:

- Fix enablemenet of "Copy to"
- Rename variables
- Use "toList()" instead of collect(Collectors.toList())
@koppor
Copy link
Copy Markdown
Member

koppor commented Aug 23, 2025

I refined

  • Moved "Title" to sub menu, too
  • Made Edit/Copy and Context menu consistent

Before

image

After

image

verify(clipBoardManager, times(0)).setContent(any(String.class));
verify(dialogService, times(1)).notify(Localization.lang("None of the selected entries have titles."));
static Stream<Arguments> getTestParams() {
// Given is a list with 2 entries with 1 with an undefined field
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This comment merely restates what is obvious from the code and doesn't provide additional insight or reasoning about the implementation.

@koppor koppor added the status: awaiting-second-review For non-trivial changes label Aug 23, 2025
@koppor koppor requested a review from calixtus August 23, 2025 12:22
koppor
koppor previously approved these changes Aug 23, 2025
@calixtus calixtus enabled auto-merge August 24, 2025 18:23
@trag-bot
Copy link
Copy Markdown

trag-bot bot commented Aug 24, 2025

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

@calixtus calixtus added this pull request to the merge queue Aug 24, 2025
Merged via the queue into JabRef:main with commit 1f8876e Aug 24, 2025
1 check passed
tsantalis added a commit to tsantalis/RefactoringMiner that referenced this pull request Aug 25, 2025
tsantalis added a commit to tsantalis/RefactoringMiner that referenced this pull request Aug 26, 2025
JabRef/jabref#13280
jabgui/src/main/java/org/jabref/gui/edit/CopyMoreAction.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: awaiting-second-review For non-trivial changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants