-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added keybinding for renaming group with F2 #12159
base: main
Are you sure you want to change the base?
Changes from 7 commits
42616e2
ea811f1
8144433
20c387a
67a5d5f
5dcc5a2
487754a
a3e8599
bfa8228
645693b
75f84bc
068253c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,6 +260,50 @@ boolean onlyMinorChanges(AbstractGroup oldGroup, AbstractGroup newGroup) { | |
return true; | ||
} | ||
|
||
/** | ||
* Opens "Rename Group Dialog" and change name of group | ||
*/ | ||
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()) { | ||
return; | ||
} | ||
|
||
if (newGroupName.contains(",")) { | ||
return; | ||
} | ||
Comment on lines
+284
to
+286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't JabRef have a check for new group names? What about the dialog to add new groups? If the check is also in there, maybe, the method can be extracted? |
||
|
||
if (oldGroupName.equals(newGroupName)) { | ||
return; | ||
} | ||
Comment on lines
+288
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should go first. |
||
|
||
int groupsWithSameName = 0; | ||
Optional<GroupTreeNode> databaseRootGroup = currentDatabase.get().getMetaData().getGroups(); | ||
if (databaseRootGroup.isPresent()) { | ||
groupsWithSameName = databaseRootGroup.get().findChildrenSatisfying(g -> g.getName().equals(newGroupName)).size(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There needs to be comment why this is necessary. At first guess, I would have thought that there must not be any other group with the same name. Why is one other group with the same name OK? |
||
} | ||
|
||
if (groupsWithSameName < 2) { | ||
oldGroup.getGroupNode().setGroup(group, true, true, database.getEntries()); | ||
writeGroupChangesToMetaData(); | ||
refresh(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Opens "Edit Group Dialog" and changes the given group to the edited one. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.jabref.gui.groups; | ||
|
||
import java.util.Optional; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.layout.VBox; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.util.BaseDialog; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.groups.AbstractGroup; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
public class RenameGroupView extends BaseDialog<AbstractGroup> { | ||
|
||
@FXML | ||
private TextField nameField; | ||
|
||
@Inject | ||
private DialogService dialogService; | ||
|
||
|
||
private final BibDatabaseContext currentDatabase; | ||
private final AbstractGroup editedGroup; | ||
|
||
public RenameGroupView(BibDatabaseContext currentDatabase, | ||
AbstractGroup editedGroup) { | ||
this.currentDatabase = currentDatabase; | ||
this.editedGroup = editedGroup; | ||
|
||
setWidth(400); | ||
setHeight(150); | ||
|
||
setTitle(Localization.lang("Rename group")); | ||
|
||
getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL); | ||
|
||
nameField = new TextField(); | ||
nameField.setPromptText(Localization.lang("Enter new group name")); | ||
|
||
VBox vbox = new VBox(new Label(Localization.lang("New group name")), nameField); | ||
getDialogPane().setContent(vbox); | ||
|
||
setResultConverter(buttonType -> { | ||
if (buttonType == ButtonType.OK) { | ||
return resultConverter(ButtonType.OK).orElse(null); | ||
} else { | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
protected Optional<AbstractGroup> resultConverter(ButtonType button) { | ||
if (button != ButtonType.OK) { | ||
return Optional.empty(); | ||
} | ||
|
||
try { | ||
String newGroupName = nameField.getText().trim(); | ||
|
||
if (editedGroup != null) { | ||
editedGroup.nameProperty().setValue(newGroupName); | ||
return Optional.of(editedGroup); | ||
} | ||
|
||
return Optional.empty(); | ||
} catch (Exception exception) { | ||
dialogService.showErrorDialogAndWait(exception.getLocalizedMessage(), exception); | ||
return Optional.empty(); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pleaase - not that many empty lines. Especially not after
{
.