Skip to content

Commit

Permalink
Fixed freeze on Mac OS X when creating/editing groups (#2727)
Browse files Browse the repository at this point in the history
* Fixed freeze on Mac OS X when creating/editing groups
 - also fixed wrong actions on groups menu items

* hopefully fix import order
  • Loading branch information
boceckts authored and tobiasdiez committed Apr 11, 2017
1 parent d206fb8 commit a4fdd5a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupTreeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
removeSubgroups.setOnAction(event -> viewModel.removeSubgroups(group));

MenuItem addEntries = new MenuItem(Localization.lang("Add selected entries to this group"));
removeSubgroups.setOnAction(event -> viewModel.addSelectedEntries(group));
addEntries.setOnAction(event -> viewModel.addSelectedEntries(group));
MenuItem removeEntries = new MenuItem(Localization.lang("Remove selected entries from this group"));
removeSubgroups.setOnAction(event -> viewModel.removeSelectedEntries(group));
removeEntries.setOnAction(event -> viewModel.removeSelectedEntries(group));

MenuItem sortAlphabetically = new MenuItem(Localization.lang("Sort all subgroups (recursively)"));
sortAlphabetically.setOnAction(event -> viewModel.sortAlphabeticallyRecursive(group));
Expand Down
99 changes: 54 additions & 45 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.util.Optional;
import java.util.function.Predicate;

import javax.swing.SwingUtilities;

import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
Expand Down Expand Up @@ -123,61 +126,67 @@ private void onActiveDatabaseChanged(Optional<BibDatabaseContext> newDatabase) {
* Opens "New Group Dialog" and add the resulting group to the specified group
*/
public void addNewSubgroup(GroupNodeViewModel parent) {
Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(new GroupDialog());
newGroup.ifPresent(group -> {
GroupTreeNode newGroupNode = parent.addSubgroup(group);
SwingUtilities.invokeLater(() -> {
Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(new GroupDialog());
newGroup.ifPresent(group -> {
GroupTreeNode newGroupNode = parent.addSubgroup(group);

// TODO: Add undo
//UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(parent, new GroupTreeNodeViewModel(newGroupNode), UndoableAddOrRemoveGroup.ADD_NODE);
//panel.getUndoManager().addEdit(undo);
// TODO: Add undo
//UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(parent, new GroupTreeNodeViewModel(newGroupNode), UndoableAddOrRemoveGroup.ADD_NODE);
//panel.getUndoManager().addEdit(undo);

// TODO: Expand parent to make new group visible
//parent.expand();
// TODO: Expand parent to make new group visible
//parent.expand();

dialogService.notify(Localization.lang("Added group \"%0\".", group.getName()));
dialogService.notify(Localization.lang("Added group \"%0\".", group.getName()));
});
});
}

/**
* Opens "Edit Group Dialog" and changes the given group to the edited one.
*/
public void editGroup(GroupNodeViewModel oldGroup) {
Optional<AbstractGroup> newGroup = dialogService
.showCustomDialogAndWait(new GroupDialog(oldGroup.getGroupNode().getGroup()));
newGroup.ifPresent(group -> {

// TODO: Keep assignments
boolean keepPreviousAssignments = dialogService.showConfirmationDialogAndWait(
Localization.lang("Change of Grouping Method"),
Localization.lang("Assign the original group's entries to this group?"));
// WarnAssignmentSideEffects.warnAssignmentSideEffects(newGroup, panel.frame());
boolean removePreviousAssignents = (oldGroup.getGroupNode().getGroup() instanceof ExplicitGroup)
&& (group instanceof ExplicitGroup);

List<FieldChange> addChange = oldGroup.getGroupNode().setGroup(
group,
keepPreviousAssignments,
removePreviousAssignents,
stateManager.getEntriesInCurrentDatabase());

// TODO: Add undo
// Store undo information.
// AbstractUndoableEdit undoAddPreviousEntries = null;
// UndoableModifyGroup undo = new UndoableModifyGroup(GroupSelector.this, groupsRoot, node, newGroup);
// if (undoAddPreviousEntries == null) {
// panel.getUndoManager().addEdit(undo);
//} else {
// NamedCompound nc = new NamedCompound("Modify Group");
// nc.addEdit(undo);
// nc.addEdit(undoAddPreviousEntries);
// nc.end();/
// panel.getUndoManager().addEdit(nc);
//}
//if (!addChange.isEmpty()) {
// undoAddPreviousEntries = UndoableChangeEntriesOfGroup.getUndoableEdit(null, addChange);
//}

dialogService.notify(Localization.lang("Modified group \"%0\".", group.getName()));
SwingUtilities.invokeLater(() -> {
Optional<AbstractGroup> newGroup = dialogService
.showCustomDialogAndWait(new GroupDialog(oldGroup.getGroupNode().getGroup()));
newGroup.ifPresent(group -> {

Platform.runLater(() -> {
// TODO: Keep assignments
boolean keepPreviousAssignments = dialogService.showConfirmationDialogAndWait(
Localization.lang("Change of Grouping Method"),
Localization.lang("Assign the original group's entries to this group?"));
// WarnAssignmentSideEffects.warnAssignmentSideEffects(newGroup, panel.frame());
boolean removePreviousAssignents = (oldGroup.getGroupNode().getGroup() instanceof ExplicitGroup)
&& (group instanceof ExplicitGroup);

List<FieldChange> addChange = oldGroup.getGroupNode().setGroup(
group,
keepPreviousAssignments,
removePreviousAssignents,
stateManager.getEntriesInCurrentDatabase());

// TODO: Add undo
// Store undo information.
// AbstractUndoableEdit undoAddPreviousEntries = null;
// UndoableModifyGroup undo = new UndoableModifyGroup(GroupSelector.this, groupsRoot, node, newGroup);
// if (undoAddPreviousEntries == null) {
// panel.getUndoManager().addEdit(undo);
//} else {
// NamedCompound nc = new NamedCompound("Modify Group");
// nc.addEdit(undo);
// nc.addEdit(undoAddPreviousEntries);
// nc.end();/
// panel.getUndoManager().addEdit(nc);
//}
//if (!addChange.isEmpty()) {
// undoAddPreviousEntries = UndoableChangeEntriesOfGroup.getUndoableEdit(null, addChange);
//}

dialogService.notify(Localization.lang("Modified group \"%0\".", group.getName()));
});
});
});
}

Expand Down

0 comments on commit a4fdd5a

Please sign in to comment.