Skip to content

Commit

Permalink
Update GroupTreeViewModel.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Rydzard authored Dec 16, 2024
1 parent 8bb211e commit 27f5690
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,43 +267,47 @@ public void renameGroup(GroupNodeViewModel oldGroup) {
currentDatabase.ifPresent(database -> {
AbstractGroup oldGroupDef = oldGroup.getGroupNode().getGroup();
String oldGroupName = oldGroupDef.getName();

Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(
new RenameGroupView(database,
oldGroup.getGroupNode().getGroup())
);

newGroup.ifPresent(group -> {

String newGroupName = group.getName();

if (newGroupName.trim().isEmpty()) {
if (oldGroupName.equals(newGroupName)) {
dialogService.notify(Localization.lang("Same name as old group"));
renameGroup(oldGroup);
return;
}

if (newGroupName.contains(",")) {
if (newGroupName.trim().isEmpty()) {
dialogService.notify(Localization.lang("Empty name for group"));
renameGroup(oldGroup);
return;
}

if (oldGroupName.equals(newGroupName)) {
if (newGroupName.contains(Character.toString(preferences.getBibEntryPreferences().getKeywordSeparator()))) {
dialogService.notify(Localization.lang("You had some special symbol in name of group"));
renameGroup(oldGroup);
return;
}

int groupsWithSameName = 0;
Optional<GroupTreeNode> databaseRootGroup = currentDatabase.get().getMetaData().getGroups();
if (databaseRootGroup.isPresent()) {
groupsWithSameName = databaseRootGroup.get().findChildrenSatisfying(g -> g.getName().equals(newGroupName)).size();
}

if (groupsWithSameName < 2) {
oldGroup.getGroupNode().setGroup(group, true, true, database.getEntries());
writeGroupChangesToMetaData();
refresh();
} else {
dialogService.notify(Localization.lang("Some group have this name"));
renameGroup(oldGroup);
}
});
});
}

/**
* Opens "Edit Group Dialog" and changes the given group to the edited one.
*/
Expand Down

0 comments on commit 27f5690

Please sign in to comment.