Skip to content
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

Add Add To Group action to context menu of entries #12368

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/main/java/org/jabref/gui/groups/AddToGroupAction.java
Original file line number Diff line number Diff line change
@@ -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));
Copy link
Member

Choose a reason for hiding this comment

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

Should this action be disabled if entries cannot be added to the selected groups (All entries group/Search group)?
org.jabref.gui.groups.GroupNodeViewModel#canAddEntriesIn

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this is what I thought as well. Needs some more adjustments. Was just a first quick hack yesterday evening so that the user can test

}

@Override
public void execute() {
stateManager.getActiveDatabase().ifPresent(databaseContext -> {
List<GroupTreeNode> 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(","))));
});
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void removeGroupsAndSubGroupsFromEntries(GroupNodeViewModel group) {
if (group.getGroupNode().getGroup() instanceof ExplicitGroup) {
int groupsWithSameName = 0;
String name = group.getGroupNode().getGroup().getName();
Optional<GroupTreeNode> rootGroup = currentDatabase.get().getMetaData().getGroups();
Optional<GroupTreeNode> rootGroup = currentDatabase.flatMap(g-> g.getMetaData().getGroups());
if (rootGroup.isPresent()) {
groupsWithSameName = rootGroup.get().findChildrenSatisfying(g -> g.getName().equals(name)).size();
}
Expand All @@ -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"));
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading