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

Fix move to group always moves first entry #4457

Merged
merged 3 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where the list of XMP Exclusion fields in the preferences was not be saved [#4072](https://github.com/JabRef/jabref/issues/4072)
- We fixed an issue where the ArXiv Fetcher did not support HTTP URLs [koppor#328](https://github.com/koppor/jabref/issues/328)
- We fixed an issue where only one PDF file could be imported [#4422](https://github.com/JabRef/jabref/issues/4422)

- We fixed an issue where "Move to group" would always move the first entry in the library and not the selected [#4414](https://github.com/JabRef/jabref/issues/4414)



Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -57,9 +58,9 @@ public void action() throws Exception {
selection = panel.getSelectedEntries();

final JDialog diag = new JDialog((JFrame) null,
(add ? (move ? Localization.lang("Move to group") : Localization.lang("Add to group")) : Localization
.lang("Remove from group")),
true);
(add ? (move ? Localization.lang("Move to group") : Localization.lang("Add to group")) : Localization
.lang("Remove from group")),
true);
JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(Localization.lang("Cancel"));
tree = new JTree(new GroupTreeNodeViewModel(groups.get()));
Expand Down Expand Up @@ -166,7 +167,9 @@ private boolean doAddOrRemove() {
GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent();
if (checkGroupEnable(node)) {

List<BibEntry> entries = Globals.stateManager.getSelectedEntries();
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
//we need to copy the contents of the observable list here, because when removeFromEntries is called,
//probably the focus changes to the first entry in the all entries group and thus getSelectedEntries() no longer contains our entry we want to move
List<BibEntry> entries = new ArrayList<>(Globals.stateManager.getSelectedEntries());

if (move) {
recuriveRemoveFromNode((GroupTreeNodeViewModel) tree.getModel().getRoot(), entries);
Expand All @@ -175,7 +178,7 @@ private boolean doAddOrRemove() {
if (add) {
node.addEntriesToGroup(entries);
} else {
node.removeEntriesFromGroup(Globals.stateManager.getSelectedEntries());
node.removeEntriesFromGroup(entries);
}

return true;
Expand All @@ -187,7 +190,7 @@ private boolean doAddOrRemove() {

private void recuriveRemoveFromNode(GroupTreeNodeViewModel node, List<BibEntry> entries) {
node.removeEntriesFromGroup(entries);
for (GroupTreeNodeViewModel child: node.getChildren()) {
for (GroupTreeNodeViewModel child : node.getChildren()) {
recuriveRemoveFromNode(child, entries);
}
}
Expand All @@ -207,7 +210,7 @@ class AddRemoveGroupTreeCellRenderer extends GroupTreeCellRenderer {

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
boolean leaf, int row, boolean hasFocus) {
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) value;
Expand Down