diff --git a/CHANGELOG.md b/CHANGELOG.md index 9750cc68786..f4d0ac9e617 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Added +- We added the ability to sort subgroups in Z-A order, as well as by ascending and descending number of subgroups. [#10249](https://github.com/JabRef/jabref/issues/10249) - We added the possibility to find (and add) papers that cite or are cited by a given paper. [#6187](https://github.com/JabRef/jabref/issues/6187) - We added an error-specific message for when a download from a URL fails. [#9826](https://github.com/JabRef/jabref/issues/9826) - We added support for customizing the citation command (e.g., `[@key1,@key2]`) when [pushing to external applications](https://docs.jabref.org/cite/pushtoapplications). [#10133](https://github.com/JabRef/jabref/issues/10133) diff --git a/src/main/java/org/jabref/gui/actions/StandardActions.java b/src/main/java/org/jabref/gui/actions/StandardActions.java index be26487c333..4053cdc7ea1 100644 --- a/src/main/java/org/jabref/gui/actions/StandardActions.java +++ b/src/main/java/org/jabref/gui/actions/StandardActions.java @@ -188,6 +188,9 @@ public enum StandardActions implements Action { GROUP_SUBGROUP_ADD(Localization.lang("Add subgroup")), GROUP_SUBGROUP_REMOVE(Localization.lang("Remove subgroups")), GROUP_SUBGROUP_SORT(Localization.lang("Sort subgroups A-Z")), + GROUP_SUBGROUP_SORT_REVERSE(Localization.lang("Sort subgroups Z-A")), + GROUP_SUBGROUP_SORT_ENTRIES(Localization.lang("Sort subgroups by # of entries (Descending)")), + GROUP_SUBGROUP_SORT_ENTRIES_REVERSE(Localization.lang("Sort subgroups by # of entries (Ascending)")), GROUP_ENTRIES_ADD(Localization.lang("Add selected entries to this group")), GROUP_ENTRIES_REMOVE(Localization.lang("Remove selected entries from this group")); diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index 7973561491b..3e175bdcbc5 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -509,6 +509,9 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { factory.createMenuItem(StandardActions.GROUP_SUBGROUP_ADD, new ContextAction(StandardActions.GROUP_SUBGROUP_ADD, group)), factory.createMenuItem(StandardActions.GROUP_SUBGROUP_REMOVE, new ContextAction(StandardActions.GROUP_SUBGROUP_REMOVE, group)), factory.createMenuItem(StandardActions.GROUP_SUBGROUP_SORT, new ContextAction(StandardActions.GROUP_SUBGROUP_SORT, group)), + factory.createMenuItem(StandardActions.GROUP_SUBGROUP_SORT_REVERSE, new ContextAction(StandardActions.GROUP_SUBGROUP_SORT_REVERSE, group)), + factory.createMenuItem(StandardActions.GROUP_SUBGROUP_SORT_ENTRIES, new ContextAction(StandardActions.GROUP_SUBGROUP_SORT_ENTRIES, group)), + factory.createMenuItem(StandardActions.GROUP_SUBGROUP_SORT_ENTRIES_REVERSE, new ContextAction(StandardActions.GROUP_SUBGROUP_SORT_ENTRIES_REVERSE, group)), new SeparatorMenuItem(), factory.createMenuItem(StandardActions.GROUP_ENTRIES_ADD, new ContextAction(StandardActions.GROUP_ENTRIES_ADD, group)), factory.createMenuItem(StandardActions.GROUP_ENTRIES_REMOVE, new ContextAction(StandardActions.GROUP_ENTRIES_REMOVE, group)) @@ -620,6 +623,12 @@ public void execute() { viewModel.removeSubgroups(group); case GROUP_SUBGROUP_SORT -> viewModel.sortAlphabeticallyRecursive(group.getGroupNode()); + case GROUP_SUBGROUP_SORT_REVERSE -> + viewModel.sortReverseAlphabeticallyRecursive(group.getGroupNode()); + case GROUP_SUBGROUP_SORT_ENTRIES -> + viewModel.sortEntriesRecursive(group.getGroupNode()); + case GROUP_SUBGROUP_SORT_ENTRIES_REVERSE -> + viewModel.sortReverseEntriesRecursive(group.getGroupNode()); case GROUP_ENTRIES_ADD -> viewModel.addSelectedEntries(group); case GROUP_ENTRIES_REMOVE -> diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index 8877939df48..1c720457053 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -57,6 +57,19 @@ public class GroupTreeViewModel extends AbstractViewModel { private final Comparator compAlphabetIgnoreCase = (GroupTreeNode v1, GroupTreeNode v2) -> v1 .getName() .compareToIgnoreCase(v2.getName()); + private final Comparator compAlphabetIgnoreCaseReverse = (GroupTreeNode v1, GroupTreeNode v2) -> v2 + .getName() + .compareToIgnoreCase(v1.getName()); + private final Comparator compEntries = (GroupTreeNode v1, GroupTreeNode v2) -> { + int numChildren1 = v1.getEntriesInGroup(this.currentDatabase.get().getEntries()).size(); + int numChildren2 = v2.getEntriesInGroup(this.currentDatabase.get().getEntries()).size(); + return Integer.compare(numChildren2, numChildren1); + }; + private final Comparator compEntriesReverse = (GroupTreeNode v1, GroupTreeNode v2) -> { + int numChildren1 = v1.getEntriesInGroup(this.currentDatabase.get().getEntries()).size(); + int numChildren2 = v2.getEntriesInGroup(this.currentDatabase.get().getEntries()).size(); + return Integer.compare(numChildren1, numChildren2); + }; private Optional currentDatabase = Optional.empty(); public GroupTreeViewModel(StateManager stateManager, DialogService dialogService, PreferencesService preferencesService, TaskExecutor taskExecutor, CustomLocalDragboard localDragboard) { @@ -560,4 +573,16 @@ public void removeSelectedEntries(GroupNodeViewModel group) { public void sortAlphabeticallyRecursive(GroupTreeNode group) { group.sortChildren(compAlphabetIgnoreCase, true); } + + public void sortReverseAlphabeticallyRecursive(GroupTreeNode group) { + group.sortChildren(compAlphabetIgnoreCaseReverse, true); + } + + public void sortEntriesRecursive(GroupTreeNode group) { + group.sortChildren(compEntries, true); + } + + public void sortReverseEntriesRecursive(GroupTreeNode group) { + group.sortChildren(compEntriesReverse, true); + } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index af568f745cb..89407c66944 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -886,6 +886,9 @@ SourceTab\ error=SourceTab error User\ input\ via\ entry-editor\ in\ `{}bibtex\ source`\ tab\ led\ to\ failure.=User input via entry-editor in `{}bibtex source` tab led to failure. Sort\ subgroups\ A-Z=Sort subgroups A-Z +Sort\ subgroups\ Z-A=Sort subgroups Z-A +Sort\ subgroups\ by\ #\ of\ entries\ (Descending)=Sort subgroups by # of entries (Descending) +Sort\ subgroups\ by\ #\ of\ entries\ (Ascending)=Sort subgroups by # of entries (Ascending) source\ edit=source edit Special\ name\ formatters=Special name formatters