Feature: Add "Copy Field Content" submenu to entry context menu#13280
Feature: Add "Copy Field Content" submenu to entry context menu#13280calixtus merged 18 commits intoJabRef:mainfrom
Conversation
…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")), |
There was a problem hiding this comment.
The label 'author' should be in sentence case, but it is already in lowercase. Ensure consistency with other labels which are in sentence case.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
What is this? Just remove the whole if block.
|
@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()) |
There was a problem hiding this comment.
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)
| .filter(bibEntry -> | ||
| bibEntry.getField(StandardField.JOURNAL).isPresent() || | ||
| bibEntry.getField(StandardField.JOURNALTITLE).isPresent()) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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")), |
There was a problem hiding this comment.
Is this ever displayed, the screenshots don't contain lower cased.
…ng and update required localization entries to JabRef_en.properties
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. |
|
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:
Examples
|
|
Copy operation should do latex2unicode using Future work could be to have a preference for it 😅 (but I think "raw" copy is not needed in 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! |
jabgui/src/test/java/org/jabref/gui/edit/CopyMoreActionTest.java
Outdated
Show resolved
Hide resolved
…e/copy-field-submenu # Conflicts: # jabgui/src/test/java/org/jabref/gui/edit/CopyMoreActionTest.java
|
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())
| 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 |
There was a problem hiding this comment.
This comment merely restates what is obvious from the code and doesn't provide additional insight or reasoning about the implementation.
|
@trag-bot didn't find any issues in the code! ✅✨ |
JabRef/jabref#13280 jabgui/src/main/java/org/jabref/gui/edit/CopyMoreAction.java


Summary of changes
This PR adds a new "Copy Field Content" submenu under the existing "Copy..." context menu option for bibliography entries.
Changes made:
StandardActionsenum values for field-specific copy operations (COPY_FIELD_CONTENT,COPY_FIELD_AUTHOR,COPY_FIELD_JOURNAL,COPY_FIELD_DATE,COPY_FIELD_KEYWORDS,COPY_FIELD_ABSTRACT)CopyMoreActionclass to handle new field copy operations with proper error handling and user feedbackcopyJournalField()method to handle bothjournalandjournaltitlefield compatibilityRightClickMenuto include the new submenuMenu structure:
Screenshots
Before:

After:

Steps to test
jabgui/src/test/java/org/jabref/gui/edit/CopyMoreActionTest.javaMandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if change is visible to the user)