Skip to content

Commit

Permalink
Add "Remove group and subgroups" option
Browse files Browse the repository at this point in the history
Issue #1407 is fixed in the process
  • Loading branch information
tobiasdiez committed Feb 24, 2017
1 parent 8321948 commit 18d7448
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- ArXiV fetcher now checks similarity of entry when using DOI retrieval to avoid false positives [#2575](https://github.com/JabRef/jabref/issues/2575)
- Sciencedirect/Elsevier fetcher is now able to scrape new HTML structure [#2576](https://github.com/JabRef/jabref/issues/2576)
- Fixed the synchronization logic of keywords and special fields and vice versa [#2580](https://github.com/JabRef/jabref/issues/2580)

- Fixed a display issue when removing a group with a long name [#1407](https://github.com/JabRef/jabref/issues/1407)

### Removed

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@ default void showErrorDialogAndWait(Exception exception) {
* a OK and Cancel Button. To create a confirmation dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)}
*
* @return Optional with the pressed Button as ButtonType
* @return true if the use clicked "OK" otherwise false
*/
boolean showConfirmationDialogAndWait(String title, String content);

/**
* Create and display a new confirmation dialog.
* It will include a blue question icon on the left and
* a OK (with given label) and Cancel Button. To create a confirmation dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)}
*
* @return true if the use clicked "OK" otherwise false
*/
Optional<ButtonType> showConfirmationDialogAndWait(String title, String content);
boolean showConfirmationDialogAndWait(String title, String content, String okButtonLabel);

/**
* This will create and display a new dialog of the specified
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/jabref/gui/FXDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;

import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.stage.FileChooser;
Expand Down Expand Up @@ -65,9 +66,17 @@ public void showErrorDialogAndWait(String message) {
}

@Override
public Optional<ButtonType> showConfirmationDialogAndWait(String title, String content) {
public boolean showConfirmationDialogAndWait(String title, String content) {
FXDialog alert = createDialog(AlertType.CONFIRMATION, title, content);
return alert.showAndWait();
return alert.showAndWait().filter(buttonType -> buttonType == ButtonType.OK).isPresent();
}

@Override
public boolean showConfirmationDialogAndWait(String title, String content, String okButtonLabel) {
FXDialog alert = createDialog(AlertType.CONFIRMATION, title, content);
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE);
alert.getButtonTypes().setAll(ButtonType.CANCEL, okButtonType);
return alert.showAndWait().filter(buttonType -> buttonType == okButtonType).isPresent();
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupTreeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
MenuItem addSubgroup = new MenuItem(Localization.lang("Add subgroup"));
addSubgroup.setOnAction(event -> viewModel.addNewSubgroup(group));

MenuItem removeGroupAndSubgroups = new MenuItem(Localization.lang("Remove group and subgroups"));
removeGroupAndSubgroups.setOnAction(event -> viewModel.removeGroupAndSubgroups(group));

menu.getItems().add(addSubgroup);
menu.getItems().add(removeGroupAndSubgroups);
return menu;
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,23 @@ public void addNewSubgroup(GroupNodeViewModel parent) {
dialogService.notify(Localization.lang("Added group \"%0\".", group.getName()));
});
}

/**
* Removes the specified group and its subgroups (after asking for confirmation).
*/
public void removeGroupAndSubgroups(GroupNodeViewModel group) {
boolean confirmed = dialogService.showConfirmationDialogAndWait(
Localization.lang("Remove group and subgroups"),
Localization.lang("Remove group \"%0\" and its subgroups?", group.getDisplayName()),
Localization.lang("Remove"));
if (confirmed) {
// TODO: Add undo
//final UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot, node, UndoableAddOrRemoveGroup.REMOVE_NODE_AND_CHILDREN);
//panel.getUndoManager().addEdit(undo);

group.getGroupNode().removeFromParent();

dialogService.notify(Localization.lang("Removed group \"%0\" and its subgroups.", group.getDisplayName()));
}
}
}

0 comments on commit 18d7448

Please sign in to comment.