-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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?
Changes from all commits
9687367
38a72ce
56cb497
e07c314
578c2bb
63f0037
31383f4
ca0b2fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,16 @@ public void execute() { | |
copyKeyAndLink(); | ||
case COPY_DOI, COPY_DOI_URL -> | ||
copyDoi(); | ||
case COPY_FIELD_AUTHOR -> | ||
copyField(StandardField.AUTHOR, Localization.lang("Author")); | ||
calixtus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case COPY_FIELD_JOURNAL -> | ||
copyField(StandardField.JOURNAL, Localization.lang("Journal")); | ||
calixtus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case COPY_FIELD_DATE -> | ||
copyField(StandardField.DATE, Localization.lang("Date")); | ||
calixtus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case COPY_FIELD_KEYWORDS -> | ||
copyField(StandardField.KEYWORDS, Localization.lang("Keywords")); | ||
calixtus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case COPY_FIELD_ABSTRACT -> | ||
copyField(StandardField.ABSTRACT, Localization.lang("Abstract")); | ||
calixtus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default -> | ||
LOGGER.info("Unknown copy command."); | ||
} | ||
|
@@ -264,4 +274,33 @@ private void copyKeyAndLink() { | |
Long.toString(entries.size() - entriesWithKey.size()), Integer.toString(entries.size()))); | ||
} | ||
} | ||
|
||
private void copyField(StandardField field, String fieldDisplayName) { | ||
List<BibEntry> selectedBibEntries = stateManager.getSelectedEntries(); | ||
|
||
List<String> fieldValues = selectedBibEntries.stream() | ||
.filter(bibEntry -> bibEntry.getFieldOrAlias(field).isPresent()) | ||
.map(bibEntry -> bibEntry.getFieldOrAlias(field).orElse("")) | ||
.filter(value -> !value.isEmpty()) | ||
.collect(Collectors.toList()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
|
||
if (fieldValues.isEmpty()) { | ||
dialogService.notify(Localization.lang("None of the selected entries have %0.", fieldDisplayName)); | ||
return; | ||
} | ||
|
||
final String copiedContent = fieldValues.stream().collect(Collectors.joining("\n")); | ||
clipBoardManager.setContent(copiedContent); | ||
|
||
if (fieldValues.size() == selectedBibEntries.size()) { | ||
// All entries had the field. | ||
dialogService.notify(Localization.lang("Copied '%0' to clipboard.", | ||
JabRefDialogService.shortenDialogMessage(copiedContent))); | ||
} else { | ||
dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined %2.", | ||
Integer.toString(selectedBibEntries.size() - fieldValues.size()), | ||
Integer.toString(selectedBibEntries.size()), | ||
fieldDisplayName)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
new SeparatorMenuItem(), | ||
factory.createMenuItem(StandardActions.COPY_KEY, new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository)), | ||
factory.createMenuItem(StandardActions.COPY_CITE_KEY, new CopyMoreAction(StandardActions.COPY_CITE_KEY, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository)), | ||
factory.createMenuItem(StandardActions.COPY_KEY_AND_TITLE, new CopyMoreAction(StandardActions.COPY_KEY_AND_TITLE, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository)), | ||
|
@@ -204,6 +206,25 @@ private static Menu createCopySubMenu(ActionFactory factory, | |
return copySpecialMenu; | ||
} | ||
|
||
private static Menu createCopyFieldContentSubMenu(ActionFactory factory, | ||
DialogService dialogService, | ||
StateManager stateManager, | ||
ClipBoardManager clipBoardManager, | ||
GuiPreferences preferences, | ||
JournalAbbreviationRepository abbreviationRepository) { | ||
Menu copyFieldContentMenu = factory.createMenu(StandardActions.COPY_FIELD_CONTENT); | ||
|
||
copyFieldContentMenu.getItems().addAll( | ||
factory.createMenuItem(StandardActions.COPY_FIELD_AUTHOR, new CopyMoreAction(StandardActions.COPY_FIELD_AUTHOR, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository)), | ||
factory.createMenuItem(StandardActions.COPY_FIELD_JOURNAL, new CopyMoreAction(StandardActions.COPY_FIELD_JOURNAL, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository)), | ||
factory.createMenuItem(StandardActions.COPY_FIELD_DATE, new CopyMoreAction(StandardActions.COPY_FIELD_DATE, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository)), | ||
factory.createMenuItem(StandardActions.COPY_FIELD_KEYWORDS, new CopyMoreAction(StandardActions.COPY_FIELD_KEYWORDS, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository)), | ||
factory.createMenuItem(StandardActions.COPY_FIELD_ABSTRACT, new CopyMoreAction(StandardActions.COPY_FIELD_ABSTRACT, dialogService, stateManager, clipBoardManager, preferences, abbreviationRepository)) | ||
); | ||
|
||
return copyFieldContentMenu; | ||
} | ||
|
||
private static Menu createSendSubMenu(ActionFactory factory, | ||
DialogService dialogService, | ||
StateManager stateManager, | ||
|
Uh oh!
There was an error while loading. Please reload this page.