diff --git a/CHANGELOG.md b/CHANGELOG.md index 66c8989828f..70d21c25422 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) - We changed the color of found text from red to high-contrast colors (background: yellow; font color: purple). [koppor#552](https://github.com/koppor/jabref/issues/552) - We modified the "Delete file" dialog and add the full file path to the dialog text. The file path in the title was changed to file name only. [koppor#534](https://github.com/koppor/jabref/issues/534) - Download from URL now automatically fills with URL from clipboard. [koppor#535](https://github.com/koppor/jabref/issues/535) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index 81510b3199c..53495ff6bda 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 -> { @@ -425,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 A-Z")); sortSubgroups.setOnAction(event -> viewModel.sortAlphabeticallyRecursive(group.getGroupNode())); @@ -438,17 +440,28 @@ 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); - removeGroup.getItems().add(removeGroupKeepSubgroups); - removeGroup.getItems().add(removeGroupAndSubgroups); - menu.getItems().add(removeGroup); - 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) { + 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(addEntries); + menu.getItems().add(removeEntries); + }); + + menu.getItems().add(new Menu()); + removeGroupWithSubgroups.getItems().add(removeGroupKeepSubgroups); + removeGroupWithSubgroups.getItems().add(removeGroupAndSubgroups); // TODO: Disable some actions under certain conditions // if (group.canBeEdited()) { diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index 8cf74178629..08a9465b2cf 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -471,6 +471,43 @@ public void removeGroupAndSubgroups(GroupNodeViewModel group) { } } + /** + * Removes the specified group (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); + + ArrayList selectedGroupNodes = new ArrayList<>(selectedGroups); + selectedGroupNodes.forEach(eachNode -> { + removeGroupsAndSubGroupsFromEntries(eachNode); + eachNode.getGroupNode().removeFromParent(); + }); + + if (selectedGroupNodes.size() > 1) { + dialogService.notify(Localization.lang("Removed all selected groups.")); + } else { + dialogService.notify(Localization.lang("Removed group \"%0\".", group.getDisplayName())); + } + writeGroupChangesToMetaData(); + } + } + void removeGroupsAndSubGroupsFromEntries(GroupNodeViewModel group) { for (GroupNodeViewModel child : group.getChildren()) { removeGroupsAndSubGroupsFromEntries(child); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index bd40ee3d0f1..c355aecce47 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