Skip to content

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

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

yoasaaa
Copy link
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
@@ -20,6 +20,12 @@ public enum StandardActions implements Action {
COPY_CITATION_HTML(Localization.lang("Copy citation (html)"), KeyBinding.COPY_PREVIEW),
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

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
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

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
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
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
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)

.filter(bibEntry -> bibEntry.getField(field).isPresent())
.map(bibEntry -> bibEntry.getField(field).orElse(""))
.filter(value -> !value.isEmpty())
.collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

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

Use Collectors.joining instead of String.join("\n", fieldValues); below.

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

@@ -20,6 +20,12 @@ public enum StandardActions implements Action {
COPY_CITATION_HTML(Localization.lang("Copy citation (html)"), KeyBinding.COPY_PREVIEW),
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
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
@@ -178,6 +178,8 @@ private static Menu createCopySubMenu(ActionFactory factory,

copySpecialMenu.getItems().addAll(
factory.createMenuItem(StandardActions.COPY_TITLE, new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository)),
createCopyFieldContentSubMenu(factory, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository),
Copy link

Choose a reason for hiding this comment

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

The method createCopyFieldContentSubMenu is added but lacks any null checks or use of Optional for its parameters, which could lead to NullPointerExceptions if any parameter is null.

@yoasaaa
Copy link
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
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.

Copy link

trag-bot bot commented Jun 10, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants