-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
base: main
Are you sure you want to change the base?
Conversation
…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")), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@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.
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()); |
There was a problem hiding this comment.
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.
.filter(bibEntry -> | ||
bibEntry.getField(StandardField.JOURNAL).isPresent() || | ||
bibEntry.getField(StandardField.JOURNALTITLE).isPresent()) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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")), |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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.
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
|
@trag-bot didn't find any issues in the code! ✅✨ |
Summary of changes
This PR adds a new "Copy Field Content" submenu under the existing "Copy..." context menu option for bibliography entries.
Changes made:
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
)CopyMoreAction
class to handle new field copy operations with proper error handling and user feedbackcopyJournalField()
method to handle bothjournal
andjournaltitle
field compatibilityRightClickMenu
to include the new submenuMenu structure:
Screenshots
Before:

After:

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