From 42616e24b8d86198eb9cb8c563d52eb1dddbdb88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Dul=C3=A1k?= Date: Tue, 5 Nov 2024 12:31:58 +0100 Subject: [PATCH 1/6] Added keybinding for renaming group with F2 --- .../jabref/gui/actions/StandardActions.java | 1 + .../jabref/gui/groups/GroupDialogView.java | 3 + .../org/jabref/gui/groups/GroupTreeView.java | 12 +++ .../jabref/gui/groups/GroupTreeViewModel.java | 59 +++++++++++++ .../jabref/gui/groups/RenameGroupView.java | 83 +++++++++++++++++++ .../org/jabref/gui/keyboard/KeyBinding.java | 3 +- 6 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/jabref/gui/groups/RenameGroupView.java diff --git a/src/main/java/org/jabref/gui/actions/StandardActions.java b/src/main/java/org/jabref/gui/actions/StandardActions.java index df789a51733..303cca6ecc2 100644 --- a/src/main/java/org/jabref/gui/actions/StandardActions.java +++ b/src/main/java/org/jabref/gui/actions/StandardActions.java @@ -192,6 +192,7 @@ public enum StandardActions implements Action { GROUP_REMOVE_KEEP_SUBGROUPS(Localization.lang("Keep subgroups")), GROUP_REMOVE_WITH_SUBGROUPS(Localization.lang("Also remove subgroups")), GROUP_CHAT(Localization.lang("Chat with group")), + GROUP_RENAME(Localization.lang("Rename group"),KeyBinding.RENAME_GROUP), GROUP_EDIT(Localization.lang("Edit group")), GROUP_GENERATE_SUMMARIES(Localization.lang("Generate summaries for entries in the group")), GROUP_GENERATE_EMBEDDINGS(Localization.lang("Generate embeddings for linked files in the group")), diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogView.java b/src/main/java/org/jabref/gui/groups/GroupDialogView.java index c1f537248ea..f3553411845 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogView.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogView.java @@ -118,6 +118,7 @@ public GroupDialogView(BibDatabaseContext currentDatabase, @Nullable GroupTreeNode parentNode, @Nullable AbstractGroup editedGroup, GroupDialogHeader groupDialogHeader) { + this.currentDatabase = currentDatabase; this.parentNode = parentNode; this.editedGroup = editedGroup; @@ -158,6 +159,8 @@ public GroupDialogView(BibDatabaseContext currentDatabase, confirmDialogButton.disableProperty().bind(viewModel.validationStatus().validProperty().not()); // handle validation before closing dialog and calling resultConverter confirmDialogButton.addEventFilter(ActionEvent.ACTION, viewModel::validationHandler); + + } private @Nullable AbstractGroup parentGroup() { diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index 7b6efa2ecdd..f53d001b9ca 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -10,6 +10,11 @@ import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; +import javafx.scene.control.ContextMenu; +import javafx.scene.control.MenuItem; +import javafx.scene.control.Button; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; import javafx.application.Platform; import javafx.beans.binding.Bindings; @@ -538,6 +543,7 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { ActionFactory factory = new ActionFactory(); MenuItem removeGroup; + if (group.hasSubgroups() && group.canAddGroupsIn() && !group.isRoot()) { removeGroup = new Menu(Localization.lang("Remove group"), null, factory.createMenuItem(StandardActions.GROUP_REMOVE_KEEP_SUBGROUPS, @@ -557,6 +563,7 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { factory.createMenuItem(StandardActions.GROUP_EDIT, new ContextAction(StandardActions.GROUP_EDIT, group)), factory.createMenuItem(StandardActions.GROUP_GENERATE_EMBEDDINGS, new ContextAction(StandardActions.GROUP_GENERATE_EMBEDDINGS, group)), factory.createMenuItem(StandardActions.GROUP_GENERATE_SUMMARIES, new ContextAction(StandardActions.GROUP_GENERATE_SUMMARIES, group)), + factory.createMenuItem(StandardActions.GROUP_RENAME, new ContextAction(StandardActions.GROUP_RENAME, group)), removeGroup, new SeparatorMenuItem(), factory.createMenuItem(StandardActions.GROUP_SUBGROUP_ADD, new ContextAction(StandardActions.GROUP_SUBGROUP_ADD, group)), @@ -639,6 +646,8 @@ public ContextAction(StandardActions command, GroupNodeViewModel group) { switch (command) { case GROUP_EDIT -> group.isEditable(); + case GROUP_RENAME -> + group.isEditable(); case GROUP_REMOVE, GROUP_REMOVE_WITH_SUBGROUPS, GROUP_REMOVE_KEEP_SUBGROUPS -> group.isEditable() && group.canRemove(); case GROUP_SUBGROUP_ADD -> @@ -662,6 +671,9 @@ public void execute() { switch (command) { case GROUP_REMOVE -> viewModel.removeGroupNoSubgroups(group); + case GROUP_RENAME -> { + viewModel.renameGroup(group); + } case GROUP_REMOVE_KEEP_SUBGROUPS -> viewModel.removeGroupKeepSubgroups(group); case GROUP_REMOVE_WITH_SUBGROUPS -> diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index 48def6325c8..82c02da015f 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -260,9 +260,68 @@ 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(); // Zachytenie starého názvu pred otvorením dialógu + + + Optional newGroup = dialogService.showCustomDialogAndWait( + new RenameGroupView(database, + oldGroup.getGroupNode().getGroup()) + ); + + newGroup.ifPresent(group -> { + + String newGroupName = group.getName(); + + + //check if it´s empty new string + if (newGroupName.trim().isEmpty()) { + dialogService.notify(Localization.lang("The new group name cannot be empty or consist only of spaces.")); + return; + } + + // check if is not include "," + if (newGroupName.contains(",")) { + dialogService.notify(Localization.lang("The new group name cannot contain commas.")); + return; + } + + // chceck if old group name dont equels with new group name + if (oldGroupName.equals(newGroupName)) { + dialogService.notify(Localization.lang("The new group name is the same as the old one. No changes made.")); + return; + } + + + // check if other groups name are not same + int groupsWithSameName = 0; + Optional databaseRootGroup = currentDatabase.get().getMetaData().getGroups(); + if (databaseRootGroup.isPresent()) { + groupsWithSameName = databaseRootGroup.get().findChildrenSatisfying(g -> g.getName().equals(newGroupName)).size(); + } + + // then change name + if (groupsWithSameName < 2) { + oldGroup.getGroupNode().setGroup(group, true, true, database.getEntries()); + dialogService.notify(Localization.lang("Renamed group from \"%0\" to \"%1\".", oldGroupName, newGroupName)); + writeGroupChangesToMetaData(); + refresh(); + } + }); + }); + } + + /** * Opens "Edit Group Dialog" and changes the given group to the edited one. */ + public void editGroup(GroupNodeViewModel oldGroup) { currentDatabase.ifPresent(database -> { Optional newGroup = dialogService.showCustomDialogAndWait(new GroupDialogView( diff --git a/src/main/java/org/jabref/gui/groups/RenameGroupView.java b/src/main/java/org/jabref/gui/groups/RenameGroupView.java new file mode 100644 index 00000000000..c21e2647067 --- /dev/null +++ b/src/main/java/org/jabref/gui/groups/RenameGroupView.java @@ -0,0 +1,83 @@ +package org.jabref.gui.groups; + +import jakarta.inject.Inject; +import javafx.fxml.FXML; +import javafx.scene.control.*; +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.*; +import org.jspecify.annotations.Nullable; + +import java.util.Optional; + +public class RenameGroupView extends BaseDialog { + + @FXML + private TextField nameField; + + @Inject + private DialogService dialogService; + + + private final BibDatabaseContext currentDatabase; + private final @Nullable AbstractGroup editedGroup; + + public RenameGroupView(BibDatabaseContext currentDatabase, + @Nullable AbstractGroup editedGroup) { + this.currentDatabase = currentDatabase; + this.editedGroup = editedGroup; + + // set Width and Height + setWidth(400); + setHeight(150); + + // set Title name + setTitle(Localization.lang("Rename group")); + + // add OK and Cancel buttons + getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL); + + nameField = new TextField(); + nameField.setPromptText("Enter new group name"); + + // add Input + VBox vbox = new VBox(new Label("New group name:"), nameField); + getDialogPane().setContent(vbox); + + // If press OK change name else return null + setResultConverter(buttonType -> { + if (buttonType == ButtonType.OK) { + return resultConverter(ButtonType.OK).orElse(null); + } else { + // Ak sa zvolí Cancel alebo sa dialóg zavrie cez X + return null; + } + }); + } + + protected Optional resultConverter(ButtonType button) { + if (button != ButtonType.OK) { + return Optional.empty(); + } + + try { + // Get new name from Input + String newGroupName = nameField.getText().trim(); + + if (editedGroup != null) { + //set new input + editedGroup.nameProperty().set(newGroupName); + return Optional.of(editedGroup); + } + + return Optional.empty(); + } catch (Exception exception) { + dialogService.showErrorDialogAndWait(exception.getLocalizedMessage(), exception); + return Optional.empty(); + } + } +} + diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java index d0cb6100338..cd6666a80ca 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java @@ -6,7 +6,8 @@ * @implNote Cannot be sorted alphabetically, as {@link KeyBindingRepository#getKeyCombination(KeyBinding)} iterates over the enum in order and returns the first match. */ public enum KeyBinding { - EDITOR_DELETE("Delete", Localization.lang("Delete text"), "", KeyBindingCategory.EDITOR), + EDITOR_DELETE("Delete", Localization.lang("Delete text"), "",KeyBindingCategory.EDITOR ), + RENAME_GROUP("Rename Group",Localization.lang("Rename group"),"R", KeyBindingCategory.EDIT), // DELETE BACKWARDS = Rubout EDITOR_BACKWARD("Move caret left", Localization.lang("Move caret left"), "", KeyBindingCategory.EDITOR), EDITOR_FORWARD("Move caret right", Localization.lang("Move caret right"), "", KeyBindingCategory.EDITOR), From ea811f193c6d48aa975773c8e0e523f824669135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Dul=C3=A1k?= Date: Mon, 11 Nov 2024 23:26:21 +0100 Subject: [PATCH 2/6] fix group size changes --- src/main/java/org/jabref/gui/DialogService.java | 2 ++ .../org/jabref/gui/groups/GroupTreeView.java | 6 +----- .../jabref/gui/groups/GroupTreeViewModel.java | 10 +--------- .../org/jabref/gui/groups/RenameGroupView.java | 17 ++++++++++------- .../org/jabref/gui/keyboard/KeyBinding.java | 4 ++-- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/jabref/gui/DialogService.java b/src/main/java/org/jabref/gui/DialogService.java index 7248be47511..d2460f0fd71 100644 --- a/src/main/java/org/jabref/gui/DialogService.java +++ b/src/main/java/org/jabref/gui/DialogService.java @@ -27,9 +27,11 @@ import org.controlsfx.control.textfield.CustomPasswordField; import org.controlsfx.dialog.ProgressDialog; + /** * This interface provides methods to create dialogs and show them to the user. */ +@SuppressWarnings("checkstyle:EmptyLineSeparator") public interface DialogService extends NotificationService { /** diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index f53d001b9ca..c8c621756de 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -10,11 +10,6 @@ import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; -import javafx.scene.control.ContextMenu; -import javafx.scene.control.MenuItem; -import javafx.scene.control.Button; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.HBox; import javafx.application.Platform; import javafx.beans.binding.Bindings; @@ -673,6 +668,7 @@ public void execute() { viewModel.removeGroupNoSubgroups(group); case GROUP_RENAME -> { viewModel.renameGroup(group); + groupTree.refresh(); } case GROUP_REMOVE_KEEP_SUBGROUPS -> viewModel.removeGroupKeepSubgroups(group); diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index 82c02da015f..fe55099b7a4 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -269,7 +269,6 @@ public void renameGroup(GroupNodeViewModel oldGroup) { AbstractGroup oldGroupDef = oldGroup.getGroupNode().getGroup(); String oldGroupName = oldGroupDef.getName(); // Zachytenie starého názvu pred otvorením dialógu - Optional newGroup = dialogService.showCustomDialogAndWait( new RenameGroupView(database, oldGroup.getGroupNode().getGroup()) @@ -279,27 +278,20 @@ public void renameGroup(GroupNodeViewModel oldGroup) { String newGroupName = group.getName(); - - //check if it´s empty new string if (newGroupName.trim().isEmpty()) { - dialogService.notify(Localization.lang("The new group name cannot be empty or consist only of spaces.")); return; } // check if is not include "," if (newGroupName.contains(",")) { - dialogService.notify(Localization.lang("The new group name cannot contain commas.")); return; } // chceck if old group name dont equels with new group name if (oldGroupName.equals(newGroupName)) { - dialogService.notify(Localization.lang("The new group name is the same as the old one. No changes made.")); return; } - - // check if other groups name are not same int groupsWithSameName = 0; Optional databaseRootGroup = currentDatabase.get().getMetaData().getGroups(); if (databaseRootGroup.isPresent()) { @@ -309,7 +301,6 @@ public void renameGroup(GroupNodeViewModel oldGroup) { // then change name if (groupsWithSameName < 2) { oldGroup.getGroupNode().setGroup(group, true, true, database.getEntries()); - dialogService.notify(Localization.lang("Renamed group from \"%0\" to \"%1\".", oldGroupName, newGroupName)); writeGroupChangesToMetaData(); refresh(); } @@ -322,6 +313,7 @@ public void renameGroup(GroupNodeViewModel oldGroup) { * Opens "Edit Group Dialog" and changes the given group to the edited one. */ + @SuppressWarnings("checkstyle:EmptyLineSeparator") public void editGroup(GroupNodeViewModel oldGroup) { currentDatabase.ifPresent(database -> { Optional newGroup = dialogService.showCustomDialogAndWait(new GroupDialogView( diff --git a/src/main/java/org/jabref/gui/groups/RenameGroupView.java b/src/main/java/org/jabref/gui/groups/RenameGroupView.java index c21e2647067..08b0a785a76 100644 --- a/src/main/java/org/jabref/gui/groups/RenameGroupView.java +++ b/src/main/java/org/jabref/gui/groups/RenameGroupView.java @@ -1,17 +1,21 @@ package org.jabref.gui.groups; -import jakarta.inject.Inject; +import java.util.Optional; + import javafx.fxml.FXML; -import javafx.scene.control.*; +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.*; -import org.jspecify.annotations.Nullable; +import org.jabref.model.groups.AbstractGroup; -import java.util.Optional; +import jakarta.inject.Inject; +import org.jspecify.annotations.Nullable; public class RenameGroupView extends BaseDialog { @@ -68,8 +72,7 @@ protected Optional resultConverter(ButtonType button) { String newGroupName = nameField.getText().trim(); if (editedGroup != null) { - //set new input - editedGroup.nameProperty().set(newGroupName); + editedGroup.nameProperty().setValue(newGroupName); return Optional.of(editedGroup); } diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java index cd6666a80ca..f36be28585f 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java @@ -6,11 +6,11 @@ * @implNote Cannot be sorted alphabetically, as {@link KeyBindingRepository#getKeyCombination(KeyBinding)} iterates over the enum in order and returns the first match. */ public enum KeyBinding { - EDITOR_DELETE("Delete", Localization.lang("Delete text"), "",KeyBindingCategory.EDITOR ), - RENAME_GROUP("Rename Group",Localization.lang("Rename group"),"R", KeyBindingCategory.EDIT), // DELETE BACKWARDS = Rubout EDITOR_BACKWARD("Move caret left", Localization.lang("Move caret left"), "", KeyBindingCategory.EDITOR), EDITOR_FORWARD("Move caret right", Localization.lang("Move caret right"), "", KeyBindingCategory.EDITOR), + EDITOR_DELETE("Delete", Localization.lang("Delete text"), "", KeyBindingCategory.EDITOR), + RENAME_GROUP("Rename Group", Localization.lang("Rename group"), "F2", KeyBindingCategory.EDIT), EDITOR_WORD_BACKWARD("Move caret to previous word", Localization.lang("Move caret to previous word"), "", KeyBindingCategory.EDITOR), EDITOR_WORD_FORWARD("Move caret to next word", Localization.lang("Move caret to next word"), "", KeyBindingCategory.EDITOR), EDITOR_BEGINNING("Move caret to beginning of line", Localization.lang("Move caret to beginning of line"), "", KeyBindingCategory.EDITOR), From 8144433b001eafe1948e8a75885a3f678ea286ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Dul=C3=A1k?= Date: Mon, 11 Nov 2024 23:43:59 +0100 Subject: [PATCH 3/6] fix checkstyleTest --- src/main/java/org/jabref/gui/actions/StandardActions.java | 2 +- src/main/java/org/jabref/gui/groups/GroupDialogView.java | 3 --- src/main/java/org/jabref/gui/groups/RenameGroupView.java | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/actions/StandardActions.java b/src/main/java/org/jabref/gui/actions/StandardActions.java index 303cca6ecc2..9ebdf89bf6b 100644 --- a/src/main/java/org/jabref/gui/actions/StandardActions.java +++ b/src/main/java/org/jabref/gui/actions/StandardActions.java @@ -192,7 +192,7 @@ public enum StandardActions implements Action { GROUP_REMOVE_KEEP_SUBGROUPS(Localization.lang("Keep subgroups")), GROUP_REMOVE_WITH_SUBGROUPS(Localization.lang("Also remove subgroups")), GROUP_CHAT(Localization.lang("Chat with group")), - GROUP_RENAME(Localization.lang("Rename group"),KeyBinding.RENAME_GROUP), + GROUP_RENAME(Localization.lang("Rename group"), KeyBinding.RENAME_GROUP), GROUP_EDIT(Localization.lang("Edit group")), GROUP_GENERATE_SUMMARIES(Localization.lang("Generate summaries for entries in the group")), GROUP_GENERATE_EMBEDDINGS(Localization.lang("Generate embeddings for linked files in the group")), diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogView.java b/src/main/java/org/jabref/gui/groups/GroupDialogView.java index f3553411845..455f719d686 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogView.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogView.java @@ -102,7 +102,6 @@ public class GroupDialogView extends BaseDialog { private final EnumMap hierarchyToolTip = new EnumMap<>(GroupHierarchyType.class); private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); - private final BibDatabaseContext currentDatabase; private final @Nullable GroupTreeNode parentNode; private final @Nullable AbstractGroup editedGroup; @@ -159,8 +158,6 @@ public GroupDialogView(BibDatabaseContext currentDatabase, confirmDialogButton.disableProperty().bind(viewModel.validationStatus().validProperty().not()); // handle validation before closing dialog and calling resultConverter confirmDialogButton.addEventFilter(ActionEvent.ACTION, viewModel::validationHandler); - - } private @Nullable AbstractGroup parentGroup() { diff --git a/src/main/java/org/jabref/gui/groups/RenameGroupView.java b/src/main/java/org/jabref/gui/groups/RenameGroupView.java index 08b0a785a76..83dfa3c7cc9 100644 --- a/src/main/java/org/jabref/gui/groups/RenameGroupView.java +++ b/src/main/java/org/jabref/gui/groups/RenameGroupView.java @@ -10,7 +10,6 @@ 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; @@ -39,7 +38,7 @@ public RenameGroupView(BibDatabaseContext currentDatabase, setHeight(150); // set Title name - setTitle(Localization.lang("Rename group")); + setTitle("Rename group"); // add OK and Cancel buttons getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL); From 20c387a7c790a67356c90b289feca7d7c601285c Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Tue, 12 Nov 2024 00:12:55 +0100 Subject: [PATCH 4/6] Discard changes to src/main/java/org/jabref/gui/DialogService.java --- src/main/java/org/jabref/gui/DialogService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/DialogService.java b/src/main/java/org/jabref/gui/DialogService.java index d2460f0fd71..7248be47511 100644 --- a/src/main/java/org/jabref/gui/DialogService.java +++ b/src/main/java/org/jabref/gui/DialogService.java @@ -27,11 +27,9 @@ import org.controlsfx.control.textfield.CustomPasswordField; import org.controlsfx.dialog.ProgressDialog; - /** * This interface provides methods to create dialogs and show them to the user. */ -@SuppressWarnings("checkstyle:EmptyLineSeparator") public interface DialogService extends NotificationService { /** From 67a5d5f1615c3a496c91f294bd573faec38ae3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Dul=C3=A1k?= Date: Mon, 18 Nov 2024 21:35:54 +0100 Subject: [PATCH 5/6] remove comments etc. --- .../jabref/gui/groups/GroupTreeViewModel.java | 9 +-------- .../jabref/gui/groups/RenameGroupView.java | 19 ++++++------------- src/main/resources/l10n/JabRef_en.properties | 4 ++++ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index fe55099b7a4..68ad674234e 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -263,11 +263,10 @@ boolean onlyMinorChanges(AbstractGroup oldGroup, AbstractGroup newGroup) { /** * 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(); // Zachytenie starého názvu pred otvorením dialógu + String oldGroupName = oldGroupDef.getName(); Optional newGroup = dialogService.showCustomDialogAndWait( new RenameGroupView(database, @@ -282,12 +281,10 @@ public void renameGroup(GroupNodeViewModel oldGroup) { return; } - // check if is not include "," if (newGroupName.contains(",")) { return; } - // chceck if old group name dont equels with new group name if (oldGroupName.equals(newGroupName)) { return; } @@ -298,7 +295,6 @@ public void renameGroup(GroupNodeViewModel oldGroup) { groupsWithSameName = databaseRootGroup.get().findChildrenSatisfying(g -> g.getName().equals(newGroupName)).size(); } - // then change name if (groupsWithSameName < 2) { oldGroup.getGroupNode().setGroup(group, true, true, database.getEntries()); writeGroupChangesToMetaData(); @@ -308,12 +304,9 @@ public void renameGroup(GroupNodeViewModel oldGroup) { }); } - /** * Opens "Edit Group Dialog" and changes the given group to the edited one. */ - - @SuppressWarnings("checkstyle:EmptyLineSeparator") public void editGroup(GroupNodeViewModel oldGroup) { currentDatabase.ifPresent(database -> { Optional newGroup = dialogService.showCustomDialogAndWait(new GroupDialogView( diff --git a/src/main/java/org/jabref/gui/groups/RenameGroupView.java b/src/main/java/org/jabref/gui/groups/RenameGroupView.java index 83dfa3c7cc9..165b7a73de9 100644 --- a/src/main/java/org/jabref/gui/groups/RenameGroupView.java +++ b/src/main/java/org/jabref/gui/groups/RenameGroupView.java @@ -10,11 +10,11 @@ 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; -import org.jspecify.annotations.Nullable; public class RenameGroupView extends BaseDialog { @@ -26,36 +26,30 @@ public class RenameGroupView extends BaseDialog { private final BibDatabaseContext currentDatabase; - private final @Nullable AbstractGroup editedGroup; + private final AbstractGroup editedGroup; public RenameGroupView(BibDatabaseContext currentDatabase, - @Nullable AbstractGroup editedGroup) { + AbstractGroup editedGroup) { this.currentDatabase = currentDatabase; this.editedGroup = editedGroup; - // set Width and Height setWidth(400); setHeight(150); - // set Title name - setTitle("Rename group"); + setTitle(Localization.lang("Rename group")); - // add OK and Cancel buttons getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL); nameField = new TextField(); - nameField.setPromptText("Enter new group name"); + nameField.setPromptText(Localization.lang("Enter new group name")); - // add Input - VBox vbox = new VBox(new Label("New group name:"), nameField); + VBox vbox = new VBox(new Label(Localization.lang("New group name")), nameField); getDialogPane().setContent(vbox); - // If press OK change name else return null setResultConverter(buttonType -> { if (buttonType == ButtonType.OK) { return resultConverter(ButtonType.OK).orElse(null); } else { - // Ak sa zvolí Cancel alebo sa dialóg zavrie cez X return null; } }); @@ -67,7 +61,6 @@ protected Optional resultConverter(ButtonType button) { } try { - // Get new name from Input String newGroupName = nameField.getText().trim(); if (editedGroup != null) { diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 0d980636e73..e143163c079 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2797,3 +2797,7 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The Currently\ selected\ JStyle\:\ '%0' = Currently selected JStyle: '%0' Currently\ selected\ CSL\ Style\:\ '%0' = Currently selected CSL Style: '%0' Store\ url\ for\ downloaded\ file=Store url for downloaded file + +Enter\ new\ group\ name=Enter new group name +New\ group\ name=New group name +Rename\ group=Rename group From 487754a6989916d0238410aa4011c04cef70bb37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Dul=C3=A1k?= Date: Mon, 18 Nov 2024 22:57:48 +0100 Subject: [PATCH 6/6] remove comments etc. --- src/main/resources/l10n/JabRef_en.properties | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index e143163c079..0d980636e73 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2797,7 +2797,3 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The Currently\ selected\ JStyle\:\ '%0' = Currently selected JStyle: '%0' Currently\ selected\ CSL\ Style\:\ '%0' = Currently selected CSL Style: '%0' Store\ url\ for\ downloaded\ file=Store url for downloaded file - -Enter\ new\ group\ name=Enter new group name -New\ group\ name=New group name -Rename\ group=Rename group