diff --git a/src/main/java/org/jabref/gui/groups/AddToGroupAction.java b/src/main/java/org/jabref/gui/groups/AddToGroupAction.java new file mode 100644 index 00000000000..f99621f9646 --- /dev/null +++ b/src/main/java/org/jabref/gui/groups/AddToGroupAction.java @@ -0,0 +1,35 @@ +package org.jabref.gui.groups; + +import java.util.List; +import java.util.stream.Collectors; + +import org.jabref.gui.DialogService; +import org.jabref.gui.StateManager; +import org.jabref.gui.actions.ActionHelper; +import org.jabref.gui.actions.SimpleCommand; +import org.jabref.logic.l10n.Localization; +import org.jabref.model.groups.GroupTreeNode; + +public class AddToGroupAction extends SimpleCommand { + + private final StateManager stateManager; + private final DialogService dialogService; + + public AddToGroupAction(StateManager stateManager, DialogService dialogService) { + this.stateManager = stateManager; + this.dialogService = dialogService; + + this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); + } + + @Override + public void execute() { + stateManager.getActiveDatabase().ifPresent(databaseContext -> { + List groups = stateManager.getSelectedGroups(databaseContext); + groups.forEach(groupTreeNode -> groupTreeNode.addEntriesToGroup(stateManager.getSelectedEntries())); + dialogService.notify(Localization.lang("Added %0 entries to group(s) \"%1\"", + stateManager.getSelectedEntries().size(), + groups.stream().map(GroupTreeNode::getName).collect(Collectors.joining(",")))); + }); + } +} diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index 48def6325c8..9a24aacbfe2 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -613,7 +613,7 @@ void removeGroupsAndSubGroupsFromEntries(GroupNodeViewModel group) { if (group.getGroupNode().getGroup() instanceof ExplicitGroup) { int groupsWithSameName = 0; String name = group.getGroupNode().getGroup().getName(); - Optional rootGroup = currentDatabase.get().getMetaData().getGroups(); + Optional rootGroup = currentDatabase.flatMap(g-> g.getMetaData().getGroups()); if (rootGroup.isPresent()) { groupsWithSameName = rootGroup.get().findChildrenSatisfying(g -> g.getName().equals(name)).size(); } @@ -630,6 +630,7 @@ public void addSelectedEntries(GroupNodeViewModel group) { // return; // user aborted operation group.getGroupNode().addEntriesToGroup(stateManager.getSelectedEntries()); + dialogService.notify(Localization.lang("Added %0 entries to group \"%1\"", stateManager.getSelectedEntries().size(), group.getDisplayName())); // TODO: Add undo // NamedCompound undoAll = new NamedCompound(Localization.lang("change assignment of entries")); diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index 66430e8770e..9fdb1748910 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -18,6 +18,7 @@ import org.jabref.gui.exporter.ExportToClipboardAction; import org.jabref.gui.frame.SendAsKindleEmailAction; import org.jabref.gui.frame.SendAsStandardEmailAction; +import org.jabref.gui.groups.AddToGroupAction; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.linkedfile.AttachFileAction; import org.jabref.gui.linkedfile.AttachFileFromURLAction; @@ -66,6 +67,7 @@ public static ContextMenu create(BibEntryTableViewModel entry, factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, undoManager, preferences)), factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, () -> libraryTab, stateManager, undoManager)), + factory.createMenuItem(StandardActions.GROUP_ENTRIES_ADD, new AddToGroupAction(stateManager, dialogService)), new SeparatorMenuItem(), createSendSubMenu(factory, dialogService, stateManager, preferences, entryTypesManager, taskExecutor), diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 52ffb629f5e..790612d7d99 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -42,6 +42,9 @@ Add\ a\ regular\ expression\ for\ the\ key\ pattern.=Add a regular expression fo Add\ entry\ manually=Add entry manually Add\ selected\ entries\ to\ this\ group=Add selected entries to this group +Added\ %0\ entries\ to\ group(s)\ "%1"=Added %0 entries to group(s) "%1" +Added\ %0\ entries\ to\ group\ "%1"=Added %0 entries to group "%1" + Add\ subgroup=Add subgroup