From edf940a5439833d01940e635194c551ad456da54 Mon Sep 17 00:00:00 2001 From: Griffith Zerk Date: Sat, 22 Oct 2022 23:36:50 +1100 Subject: [PATCH 1/9] Closes issue #1, opens issues #3, #4 --- .../org/jabref/gui/groups/GroupTreeView.java | 16 ++++++--- .../jabref/gui/groups/GroupTreeViewModel.java | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index fd3ab5c7614..987bd0b282b 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -403,7 +403,11 @@ private Optional> getTreeItemByValue(TreeItem viewModel.removeGroupNoSubgroups(group)); MenuItem editGroup = new MenuItem(Localization.lang("Edit group")); editGroup.setOnAction(event -> { @@ -439,9 +443,13 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { removeEntries.setOnAction(event -> viewModel.removeSelectedEntries(group)); menu.getItems().add(editGroup); - removeGroup.getItems().add(removeGroupKeepSubgroups); - removeGroup.getItems().add(removeGroupAndSubgroups); - menu.getItems().add(removeGroup); + if (group.getChildren().size() > 0) { + removeGroupWithSubgroups.getItems().add(removeGroupKeepSubgroups); + removeGroupWithSubgroups.getItems().add(removeGroupAndSubgroups); + menu.getItems().add(removeGroupWithSubgroups); + } else { + menu.getItems().add(removeGroupNoSubgroups); + } menu.getItems().add(new SeparatorMenuItem()); menu.getItems().add(addSubgroup); menu.getItems().add(removeSubgroups); diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index 8cf74178629..cb487dbd456 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -471,6 +471,40 @@ public void removeGroupAndSubgroups(GroupNodeViewModel group) { } } + /** + * Removes the specified group and its subgroups (after asking for confirmation). + */ + public void removeGroupNoSubgroups(GroupNodeViewModel group) { + boolean confirmed; + if (selectedGroups.size() <= 1) { + confirmed = dialogService.showConfirmationDialogAndWait( + Localization.lang("Remove group"), + Localization.lang("Remove group \"%0\"?", group.getDisplayName()), + Localization.lang("Remove")); + } else { + confirmed = dialogService.showConfirmationDialogAndWait( + Localization.lang("Remove groups and subgroups"), + Localization.lang("Remove all selected groups and their subgroups?"), + Localization.lang("Remove all")); + } + + if (confirmed) { + // TODO: Add undo + // final UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot, node, UndoableAddOrRemoveGroup.REMOVE_NODE_WITHOUT_CHILDREN); + // panel.getUndoManager().addEdit(undo); + + removeGroupsAndSubGroupsFromEntries(group); + group.getGroupNode().removeFromParent(); + + if (selectedGroups.size() > 1) { + dialogService.notify(Localization.lang("Removed all selected groups and their subgroups.")); + } else { + dialogService.notify(Localization.lang("Removed group \"%0\" and its subgroups.", group.getDisplayName())); + } + writeGroupChangesToMetaData(); + } + } + void removeGroupsAndSubGroupsFromEntries(GroupNodeViewModel group) { for (GroupNodeViewModel child : group.getChildren()) { removeGroupsAndSubGroupsFromEntries(child); From ec93249cb09df319752ae618ea64f14a30357aec Mon Sep 17 00:00:00 2001 From: Griffith Zerk Date: Sat, 22 Oct 2022 23:38:59 +1100 Subject: [PATCH 2/9] Adjusted removeGroupNoSubgroups to keep consistent with other removeGroup__ methods --- .../java/org/jabref/gui/groups/GroupTreeViewModel.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index cb487dbd456..e3f551d649b 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -493,10 +493,13 @@ public void removeGroupNoSubgroups(GroupNodeViewModel group) { // final UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot, node, UndoableAddOrRemoveGroup.REMOVE_NODE_WITHOUT_CHILDREN); // panel.getUndoManager().addEdit(undo); - removeGroupsAndSubGroupsFromEntries(group); - group.getGroupNode().removeFromParent(); + ArrayList selectedGroupNodes = new ArrayList<>(selectedGroups); + selectedGroupNodes.forEach(eachNode -> { + removeGroupsAndSubGroupsFromEntries(eachNode); + eachNode.getGroupNode().removeFromParent(); + }); - if (selectedGroups.size() > 1) { + if (selectedGroupNodes.size() > 1) { dialogService.notify(Localization.lang("Removed all selected groups and their subgroups.")); } else { dialogService.notify(Localization.lang("Removed group \"%0\" and its subgroups.", group.getDisplayName())); From 8e0d3b3f68d18b0f8af76fdf798f20d1541f44ad Mon Sep 17 00:00:00 2001 From: Griffith Zerk Date: Sun, 23 Oct 2022 15:05:22 +1100 Subject: [PATCH 3/9] Update context menu each time it is opened, to reflect any changes that may have been made to subgroups Adjusted removeSubgroups.setOnAction to be consistent with other action events --- .../org/jabref/gui/groups/GroupTreeView.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index 987bd0b282b..db32fbb182d 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -429,9 +429,7 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { }); MenuItem removeSubgroups = new MenuItem(Localization.lang("Remove subgroups")); - removeSubgroups.setOnAction(event -> { - viewModel.removeSubgroups(group); - }); + removeSubgroups.setOnAction(event -> viewModel.removeSubgroups(group)); MenuItem sortSubgroups = new MenuItem(Localization.lang("Sort subgroups")); sortSubgroups.setOnAction(event -> viewModel.sortAlphabeticallyRecursive(group.getGroupNode())); @@ -442,21 +440,26 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { MenuItem removeEntries = new MenuItem(Localization.lang("Remove selected entries from this group")); removeEntries.setOnAction(event -> viewModel.removeSelectedEntries(group)); - menu.getItems().add(editGroup); - if (group.getChildren().size() > 0) { - removeGroupWithSubgroups.getItems().add(removeGroupKeepSubgroups); - removeGroupWithSubgroups.getItems().add(removeGroupAndSubgroups); - menu.getItems().add(removeGroupWithSubgroups); - } else { - menu.getItems().add(removeGroupNoSubgroups); - } - menu.getItems().add(new SeparatorMenuItem()); - menu.getItems().add(addSubgroup); - menu.getItems().add(removeSubgroups); - menu.getItems().add(sortSubgroups); - menu.getItems().add(new SeparatorMenuItem()); - menu.getItems().add(addEntries); - menu.getItems().add(removeEntries); + menu.setOnShown(event -> { + menu.getItems().clear(); + menu.getItems().add(editGroup); + if (group.getChildren().size() > 0) { + removeGroupWithSubgroups.getItems().add(removeGroupKeepSubgroups); + removeGroupWithSubgroups.getItems().add(removeGroupAndSubgroups); + menu.getItems().add(removeGroupWithSubgroups); + } else { + menu.getItems().add(removeGroupNoSubgroups); + } + menu.getItems().add(new SeparatorMenuItem()); + menu.getItems().add(addSubgroup); + menu.getItems().add(removeSubgroups); + menu.getItems().add(sortSubgroups); + menu.getItems().add(new SeparatorMenuItem()); + menu.getItems().add(addEntries); + menu.getItems().add(removeEntries); + }); + + menu.getItems().add(new Menu()); // TODO: Disable some actions under certain conditions // if (group.canBeEdited()) { From 7754724028cbc10d078aaad869f9b960386e43fa Mon Sep 17 00:00:00 2001 From: Griffith Zerk Date: Sun, 23 Oct 2022 15:26:18 +1100 Subject: [PATCH 4/9] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ed74a68e2c..746d0830927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where a message about changed metadata would occur on saving although nothing changed. [#9159](https://github.com/JabRef/jabref/issues/9159) - When adding or editing a subgroup it is placed w.r.t. to alphabetical ordering rather than at the end. [koppor#577](https://github.com/koppor/jabref/issues/577) - We modified the Directory of Open Access Books (DOAB) fetcher so that it will now also fetch the ISBN when possible. [#8708](https://github.com/JabRef/jabref/issues/8708) +- Groups context menu now shows appropriate options depending on number of subgroups. [koppor#579](https://github.com/koppor/jabref/issues/579) ### Fixed From c5f7f3ffd0bfc2ab556bcad87a9db5516585f0e0 Mon Sep 17 00:00:00 2001 From: Griffith Zerk Date: Sun, 23 Oct 2022 15:37:55 +1100 Subject: [PATCH 5/9] Removed "Remove subgroups" and "Sort subgroups" options when no subgroups present --- src/main/java/org/jabref/gui/groups/GroupTreeView.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index db32fbb182d..2091a636e53 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -447,14 +447,16 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { removeGroupWithSubgroups.getItems().add(removeGroupKeepSubgroups); removeGroupWithSubgroups.getItems().add(removeGroupAndSubgroups); menu.getItems().add(removeGroupWithSubgroups); + menu.getItems().add(new SeparatorMenuItem()); + menu.getItems().add(addSubgroup); + menu.getItems().add(removeSubgroups); + menu.getItems().add(sortSubgroups); } else { menu.getItems().add(removeGroupNoSubgroups); + menu.getItems().add(new SeparatorMenuItem()); + menu.getItems().add(addSubgroup); } menu.getItems().add(new SeparatorMenuItem()); - menu.getItems().add(addSubgroup); - menu.getItems().add(removeSubgroups); - menu.getItems().add(sortSubgroups); - menu.getItems().add(new SeparatorMenuItem()); menu.getItems().add(addEntries); menu.getItems().add(removeEntries); }); From d337ca5bec6108c9b2a6f94532354361a2ee3a25 Mon Sep 17 00:00:00 2001 From: Griffith Zerk Date: Sun, 23 Oct 2022 15:41:59 +1100 Subject: [PATCH 6/9] Removed context submenu addition from event listener --- src/main/java/org/jabref/gui/groups/GroupTreeView.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index 2091a636e53..39e3b068317 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -444,8 +444,6 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { menu.getItems().clear(); menu.getItems().add(editGroup); if (group.getChildren().size() > 0) { - removeGroupWithSubgroups.getItems().add(removeGroupKeepSubgroups); - removeGroupWithSubgroups.getItems().add(removeGroupAndSubgroups); menu.getItems().add(removeGroupWithSubgroups); menu.getItems().add(new SeparatorMenuItem()); menu.getItems().add(addSubgroup); @@ -462,6 +460,8 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { }); menu.getItems().add(new Menu()); + removeGroupWithSubgroups.getItems().add(removeGroupKeepSubgroups); + removeGroupWithSubgroups.getItems().add(removeGroupAndSubgroups); // TODO: Disable some actions under certain conditions // if (group.canBeEdited()) { From 2a592a8f3d932bbdfca399c807b1b8bd4390418f Mon Sep 17 00:00:00 2001 From: Griffith Zerk Date: Sun, 23 Oct 2022 15:48:01 +1100 Subject: [PATCH 7/9] Fixed JavaDoc for removeGroupNoSubgroups --- src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index e3f551d649b..21e10852e3c 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -472,7 +472,7 @@ public void removeGroupAndSubgroups(GroupNodeViewModel group) { } /** - * Removes the specified group and its subgroups (after asking for confirmation). + * Removes the specified group (after asking for confirmation). */ public void removeGroupNoSubgroups(GroupNodeViewModel group) { boolean confirmed; From f823668e3634e384473fd92c3a4b1a2f1a2fc4b0 Mon Sep 17 00:00:00 2001 From: Griffith Zerk Date: Sun, 23 Oct 2022 16:00:24 +1100 Subject: [PATCH 8/9] Added remove text to language file --- src/main/resources/l10n/JabRef_en.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 2ac871e6ecc..ae769b7b6a1 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -707,6 +707,8 @@ Remove\ all\ selected\ groups\ and\ their\ subgroups?=Remove all selected groups Removed\ all\ selected\ groups\ and\ their\ subgroups.=Removed all selected groups and their subgroups. +Remove\ group\ "%0"?=Remove group "%0"? + Remove\ link=Remove link Remove\ string\ %0=Remove string %0 From 846b7a6c293686148bf5bf048137bc2daf958817 Mon Sep 17 00:00:00 2001 From: Griffith Zerk Date: Sun, 23 Oct 2022 17:12:39 +1100 Subject: [PATCH 9/9] Fixed popup when deleting group with no subgroups --- src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index 21e10852e3c..08a9465b2cf 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -500,9 +500,9 @@ public void removeGroupNoSubgroups(GroupNodeViewModel group) { }); if (selectedGroupNodes.size() > 1) { - dialogService.notify(Localization.lang("Removed all selected groups and their subgroups.")); + dialogService.notify(Localization.lang("Removed all selected groups.")); } else { - dialogService.notify(Localization.lang("Removed group \"%0\" and its subgroups.", group.getDisplayName())); + dialogService.notify(Localization.lang("Removed group \"%0\".", group.getDisplayName())); } writeGroupChangesToMetaData(); }