From 2bdaba6750b7ac6bd6cbb79cbdea4dc83fcd0859 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 4 Nov 2018 17:31:33 +0100 Subject: [PATCH 1/2] Fix move to group always moves first entry --- CHANGELOG.md | 2 +- src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2119c71557..9a526106f81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,7 +76,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) diff --git a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java b/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java index 9cfc6d32bef..c5e8fe18a05 100644 --- a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java @@ -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; @@ -166,7 +167,8 @@ private boolean doAddOrRemove() { GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent(); if (checkGroupEnable(node)) { - List entries = Globals.stateManager.getSelectedEntries(); + List entries = new ArrayList<>(Globals.stateManager.getSelectedEntries()); //we need to copy the contents of the oversable list here, because when remove is called, + //the selected entries is empty and the first wil be selecteds if (move) { recuriveRemoveFromNode((GroupTreeNodeViewModel) tree.getModel().getRoot(), entries); From a5ad2ff6b1e91bd8860999824314a9772e09de7b Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 9 Nov 2018 17:30:25 +0100 Subject: [PATCH 2/2] clarify comment a bit better --- .../jabref/gui/groups/GroupAddRemoveDialog.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java b/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java index c5e8fe18a05..870af219e7b 100644 --- a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java @@ -58,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())); @@ -167,8 +167,9 @@ private boolean doAddOrRemove() { GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent(); if (checkGroupEnable(node)) { - List entries = new ArrayList<>(Globals.stateManager.getSelectedEntries()); //we need to copy the contents of the oversable list here, because when remove is called, - //the selected entries is empty and the first wil be selecteds + //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 entries = new ArrayList<>(Globals.stateManager.getSelectedEntries()); if (move) { recuriveRemoveFromNode((GroupTreeNodeViewModel) tree.getModel().getRoot(), entries); @@ -177,7 +178,7 @@ private boolean doAddOrRemove() { if (add) { node.addEntriesToGroup(entries); } else { - node.removeEntriesFromGroup(Globals.stateManager.getSelectedEntries()); + node.removeEntriesFromGroup(entries); } return true; @@ -189,7 +190,7 @@ private boolean doAddOrRemove() { private void recuriveRemoveFromNode(GroupTreeNodeViewModel node, List entries) { node.removeEntriesFromGroup(entries); - for (GroupTreeNodeViewModel child: node.getChildren()) { + for (GroupTreeNodeViewModel child : node.getChildren()) { recuriveRemoveFromNode(child, entries); } } @@ -209,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;