Skip to content

Commit

Permalink
Fix move to group always moves first entry (#4457)
Browse files Browse the repository at this point in the history
* Fix move to group always moves first entry

* clarify comment a bit better
  • Loading branch information
Siedlerchr authored Nov 9, 2018
1 parent 144522d commit bab9ae8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
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();
//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

0 comments on commit bab9ae8

Please sign in to comment.