Skip to content
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

Fix Preferences style value too long #6372

Merged
merged 13 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed the paste entry command in the menu and toolbar, that did not do anything. [#6293](https://github.com/JabRef/jabref/issues/6293)
- We fixed an issue where the windows installer did not create an entry in the start menu [bug report in the forum](https://discourse.jabref.org/t/error-while-fetching-from-doi/2018/3)
- We fixed an issue where JabRef switched to discrete graphics under macOS [#5935](https://github.com/JabRef/jabref/issues/5935)
- We fixed an issue where the Preferences entry preview will be unexpected modified leads to Value too long exception [#6198](https://github.com/JabRef/jabref/issues/6198)

### Removed

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/preferences/PreviewTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private void dragDetectedInAvailable(MouseEvent event) {
List<PreviewLayout> selectedLayouts = new ArrayList<>(viewModel.availableSelectionModelProperty().getValue().getSelectedItems());
if (!selectedLayouts.isEmpty()) {
Dragboard dragboard = startDragAndDrop(TransferMode.MOVE);
viewModel.dragDetected(viewModel.availableListProperty(), selectedLayouts, dragboard);
viewModel.dragDetected(viewModel.availableListProperty(), viewModel.availableSelectionModelProperty(), selectedLayouts, dragboard);
}
event.consume();
}
Expand All @@ -220,7 +220,7 @@ private void dragDetectedInChosen(MouseEvent event) {
List<PreviewLayout> selectedLayouts = new ArrayList<>(viewModel.chosenSelectionModelProperty().getValue().getSelectedItems());
if (!selectedLayouts.isEmpty()) {
Dragboard dragboard = startDragAndDrop(TransferMode.MOVE);
viewModel.dragDetected(viewModel.chosenListProperty(), selectedLayouts, dragboard);
viewModel.dragDetected(viewModel.chosenListProperty(), viewModel.chosenSelectionModelProperty(), selectedLayouts, dragboard);
}
event.consume();
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/org/jabref/gui/preferences/PreviewTabViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class PreviewTabViewModel implements PreferenceTabViewModel {
private final CustomLocalDragboard localDragboard;
private Validator chosenListValidator;
private ListProperty<PreviewLayout> dragSourceList = null;
private ObjectProperty<MultipleSelectionModel<PreviewLayout>> dragSourceSelectionModel = null;

public PreviewTabViewModel(DialogService dialogService, JabRefPreferences preferences, TaskExecutor taskExecutor, StateManager stateManager) {
this.dialogService = dialogService;
Expand Down Expand Up @@ -231,12 +232,14 @@ public boolean validateSettings() {

public void addToChosen() {
List<PreviewLayout> selected = new ArrayList<>(availableSelectionModelProperty.getValue().getSelectedItems());
availableSelectionModelProperty.getValue().clearSelection();
availableListProperty.removeAll(selected);
chosenListProperty.addAll(selected);
}

public void removeFromChosen() {
List<PreviewLayout> selected = new ArrayList<>(chosenSelectionModelProperty.getValue().getSelectedItems());
chosenSelectionModelProperty.getValue().clearSelection();
chosenListProperty.removeAll(selected);
availableListProperty.addAll(selected);
availableListProperty.sort((a, b) -> a.getName().compareToIgnoreCase(b.getName()));
Expand All @@ -249,6 +252,7 @@ public void selectedInChosenUp() {

List<Integer> selected = new ArrayList<>(chosenSelectionModelProperty.getValue().getSelectedIndices());
List<Integer> newIndices = new ArrayList<>();
chosenSelectionModelProperty.getValue().clearSelection();

for (int oldIndex : selected) {
boolean alreadyTaken = newIndices.contains(oldIndex - 1);
Expand All @@ -257,7 +261,6 @@ public void selectedInChosenUp() {
newIndices.add(newIndex);
}

chosenSelectionModelProperty.getValue().clearSelection();
newIndices.forEach(index -> chosenSelectionModelProperty.getValue().select(index));
chosenSelectionModelProperty.getValue().select(newIndices.get(0));
refreshPreview();
Expand All @@ -270,6 +273,7 @@ public void selectedInChosenDown() {

List<Integer> selected = new ArrayList<>(chosenSelectionModelProperty.getValue().getSelectedIndices());
List<Integer> newIndices = new ArrayList<>();
chosenSelectionModelProperty.getValue().clearSelection();

for (int i = selected.size() - 1; i >= 0; i--) {
int oldIndex = selected.get(i);
Expand All @@ -279,7 +283,6 @@ public void selectedInChosenDown() {
newIndices.add(newIndex);
}

chosenSelectionModelProperty.getValue().clearSelection();
newIndices.forEach(index -> chosenSelectionModelProperty.getValue().select(index));
chosenSelectionModelProperty.getValue().select(newIndices.get(0));
refreshPreview();
Expand Down Expand Up @@ -365,12 +368,13 @@ public void dragOver(DragEvent event) {
}
}

public void dragDetected(ListProperty<PreviewLayout> sourceList, List<PreviewLayout> selectedLayouts, Dragboard dragboard) {
public void dragDetected(ListProperty<PreviewLayout> sourceList, ObjectProperty<MultipleSelectionModel<PreviewLayout>> sourceSelectionModel, List<PreviewLayout> selectedLayouts, Dragboard dragboard) {
ClipboardContent content = new ClipboardContent();
content.put(DragAndDropDataFormats.PREVIEWLAYOUTS, "");
dragboard.setContent(content);
localDragboard.putPreviewLayouts(selectedLayouts);
dragSourceList = sourceList;
dragSourceSelectionModel = sourceSelectionModel;
}

/**
Expand All @@ -386,6 +390,7 @@ public boolean dragDropped(ListProperty<PreviewLayout> targetList, Dragboard dra
if (dragboard.hasContent(DragAndDropDataFormats.PREVIEWLAYOUTS)) {
List<PreviewLayout> draggedLayouts = localDragboard.getPreviewLayouts();
if (!draggedLayouts.isEmpty()) {
dragSourceSelectionModel.getValue().clearSelection();
dragSourceList.getValue().removeAll(draggedLayouts);
targetList.getValue().addAll(draggedLayouts);
success = true;
Expand All @@ -412,7 +417,7 @@ public boolean dragDroppedInChosenCell(PreviewLayout targetLayout, Dragboard dra
if (dragboard.hasContent(DragAndDropDataFormats.PREVIEWLAYOUTS)) {
List<PreviewLayout> draggedSelectedLayouts = new ArrayList<>(localDragboard.getPreviewLayouts());
if (!draggedSelectedLayouts.isEmpty()) {

chosenSelectionModelProperty.getValue().clearSelection();
int targetId = chosenListProperty.getValue().indexOf(targetLayout);

// see https://stackoverflow.com/questions/28603224/sort-tableview-with-drag-and-drop-rows
Expand All @@ -427,7 +432,7 @@ public boolean dragDroppedInChosenCell(PreviewLayout targetLayout, Dragboard dra
}
targetLayout = chosenListProperty.getValue().get(targetId);
}

dragSourceSelectionModel.getValue().clearSelection();
dragSourceList.getValue().removeAll(draggedSelectedLayouts);

if (targetLayout != null) {
Expand All @@ -438,7 +443,6 @@ public boolean dragDroppedInChosenCell(PreviewLayout targetLayout, Dragboard dra

chosenListProperty.getValue().addAll(targetId, draggedSelectedLayouts);

chosenSelectionModelProperty.getValue().clearSelection();
draggedSelectedLayouts.forEach(layout -> chosenSelectionModelProperty.getValue().select(layout));

success = true;
Expand Down