Skip to content

Commit

Permalink
Group context menu presents relevant options depending on number of s…
Browse files Browse the repository at this point in the history
…ubgroups (#9286)

* Closes issue #1, opens issues #3, #4

* Adjusted removeGroupNoSubgroups to keep consistent with other removeGroup__ methods

* 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

* Update CHANGELOG.md

* Removed "Remove subgroups" and "Sort subgroups" options when no subgroups present

* Removed context submenu addition from event listener

* Fixed JavaDoc for removeGroupNoSubgroups

* Added remove text to language file

* Fixed popup when deleting group with no subgroups

Co-authored-by: Christoph <[email protected]>
  • Loading branch information
Gpax971 and Siedlerchr authored Oct 30, 2022
1 parent 259eb0e commit 079c27b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 28 additions & 15 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ private Optional<TreeItem<GroupNodeViewModel>> getTreeItemByValue(TreeItem<Group

private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
ContextMenu menu = new ContextMenu();
Menu removeGroup = new Menu(Localization.lang("Remove group"));

Menu removeGroupWithSubgroups = new Menu(Localization.lang("Remove group"));

MenuItem removeGroupNoSubgroups = new MenuItem(Localization.lang("Remove group"));
removeGroupNoSubgroups.setOnAction(event -> viewModel.removeGroupNoSubgroups(group));

MenuItem editGroup = new MenuItem(Localization.lang("Edit group"));
editGroup.setOnAction(event -> {
Expand All @@ -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()));
Expand All @@ -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()) {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupNodeViewModel> 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);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 079c27b

Please sign in to comment.