Skip to content

Commit

Permalink
Place subgroups w.r.t. alphabetical ordering (#9228)
Browse files Browse the repository at this point in the history
* Place subgroups w.r.t. alphabetical ordering

* Fix changelog

* Fix checkstyle

* Update CHANGELOG.md
  • Loading branch information
0x002A authored Oct 12, 2022
1 parent d3ad678 commit fe2ceef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We call backup files `.bak` and temporary writing files now `.sav`.
- JabRef keeps 10 older versions of a `.bib` file in the [user data dir](https://github.com/harawata/appdirs#supported-directories) (instead of a single `.sav` (now: `.bak`) file in the directory of the `.bib` file)
- We changed the button label from "Return to JabRef" to "Return to library" to better indicate the purpose of the action.
- We removed "last-search-date" from the SLR feature, because the last-search-date can be deducted from the git logs. [#9116](https://github.com/JabRef/jabref/pull/9116)
- A user can now add arbitrary data into `study.yml`. JabRef just ignores this data. [#9124](https://github.com/JabRef/jabref/pull/9124)
- We reworked the External Changes Resolver dialog. [#9021](https://github.com/JabRef/jabref/pull/9021)
- The fallback directory of the file folder now is the general file directory. In case there was a directory configured for a library and this directory was not found, JabRef placed the PDF next to the .bib file and not into the general file directory.
- The global default directory for storing PDFs is now the subdirectory "JabRef" in the user's home.
- We reworked the Define study parameters dialog. [#9123](https://github.com/JabRef/jabref/pull/9123)
- We simplified the actions to fast-resolve duplicates to 'Keep Left', 'Keep Right', 'Keep Both' and 'Keep Merged'. [#9056](https://github.com/JabRef/jabref/issues/9056)
- 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)

### Fixed
Expand Down Expand Up @@ -72,6 +72,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Removed

- We removed "last-search-date" from the SLR feature, because the last-search-date can be deducted from the git logs. [#9116](https://github.com/JabRef/jabref/pull/9116)



Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
});

MenuItem sortSubgroups = new MenuItem(Localization.lang("Sort subgroups"));
sortSubgroups.setOnAction(event -> viewModel.sortAlphabeticallyRecursive(group));
sortSubgroups.setOnAction(event -> viewModel.sortAlphabeticallyRecursive(group.getGroupNode()));

MenuItem addEntries = new MenuItem(Localization.lang("Add selected entries to this group"));
addEntries.setOnAction(event -> viewModel.addSelectedEntries(group));
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ private void onActiveDatabaseChanged(Optional<BibDatabaseContext> newDatabase) {
}

/**
* Opens "New Group Dialog" and add the resulting group to the specified group
* Opens "New Group Dialog" and adds the resulting group as subgroup to the specified group while maintaining the
* alphabetical order
*/
public void addNewSubgroup(GroupNodeViewModel parent, GroupDialogHeader groupDialogHeader) {
currentDatabase.ifPresent(database -> {
Expand All @@ -175,6 +176,8 @@ public void addNewSubgroup(GroupNodeViewModel parent, GroupDialogHeader groupDia
// TODO: Expand parent to make new group visible
// parent.expand();

sortAlphabeticallyRecursive(parent.getGroupNode());

dialogService.notify(Localization.lang("Added group \"%0\".", group.getName()));
writeGroupChangesToMetaData();
});
Expand Down Expand Up @@ -364,6 +367,11 @@ public void editGroup(GroupNodeViewModel oldGroup) {
// if (!addChange.isEmpty()) {
// undoAddPreviousEntries = UndoableChangeEntriesOfGroup.getUndoableEdit(null, addChange);
// }

oldGroup.getParent().ifPresent(parent -> {
sortAlphabeticallyRecursive(parent);
});

dialogService.notify(Localization.lang("Modified group \"%0\".", group.getName()));
writeGroupChangesToMetaData();
// This is ugly but we have no proper update mechanism in place to propagate the changes, so redraw everything
Expand Down Expand Up @@ -523,7 +531,7 @@ public void removeSelectedEntries(GroupNodeViewModel group) {
// mPanel.getUndoManager().addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(mNode, undo));
}

public void sortAlphabeticallyRecursive(GroupNodeViewModel group) {
group.getGroupNode().sortChildren(compAlphabetIgnoreCase, true);
public void sortAlphabeticallyRecursive(GroupTreeNode group) {
group.sortChildren(compAlphabetIgnoreCase, true);
}
}

0 comments on commit fe2ceef

Please sign in to comment.