-
-
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
Add drag and drop in EntryEditor #9965
Conversation
Hi, However, this drag or drop will happen when dragging the group to the EntryEditor panel instead of dragging it to the exact group field inside General Tab. I try to add setOnDragDropped() function to a tab, but it seems I can't do it. It'll be helpful if someone can give me some advice. |
First of all, I don't know if there is a correct way to do this X) Why a tab and not a field? If you only set it on the tab, I would be surprised if it works if you drag it to a field. In order to deal with drag and drop to a field, I'd start looking at jabref/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java Lines 262 to 265 in 424ff1c
And if you follow that trail to its superclass jabref/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java Lines 112 to 113 in 424ff1c
inside |
Please move the drag logic to a new GroupEditor implementing SimpleEditor, so we can keep the FieldsEditorTab clean of those special cases. Single responsibilty of the FieldsEditorTab is to draw the FieldEditors. |
Hi, I didn't find this GroupEditor. Do you mean to create a new class implementing SimpleEditor? |
Hi, |
Yes I think that should work in bindToEntry. Although this method is always called if any entry in the main table is selected, there are probably no memory leaks produced, as far as I can see. Looks good so far. Let's see what a second maintainer thinks. |
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.
Undo unnecessary whitespace changes
Huh, tried to remove directly within github ui, but only commented instead of committet... 🤣
Just fixed some unnecessary whitespace changes. Something was not right in my ui. |
I fear the listeners are registered everytime. I would try to register the listeners in the constructor and add a field for the entry this.entry = entry; then you have a chance to access the entry in the listeners |
|
That is even more elegant! Yeah that should be working fine. |
Change the type of bibEntry from ObservableOptionalValue<BibEntry> to Optional<BibEntry>
Hi, I have removed the listener to the constructor, but I still have few questions:
|
This is really weird, and shouldn't happen. Manually re-running the test in GitHub appears to have "fixed" it. Looking at the code again, perhaps |
You'll have difficulties dealing with local variables inside of a lambda. If you are willing to try you can rewrite almost the whole dragDropped function as a chain ending it with It would be an interesting exercise, but it might make it unreadable. The outer |
I tried to rewrite the setOnDragDropped and it seems ugly, so I think it's better to stick with 'if' version
I can change that but I don't understand the point. I think if the condition fails and the boolean success will stay false. I'm not sure why we still need the else clause. |
Agreed, thank you for humoring me, and sorry 😅
Logically nothing should change, true. But from my (opinionated 😁) point of view, keeping each I just re-arranged your latest code and arrived at this, and just to be clear, I think the first version you made with an Here I can mentally deal with the if (event.getDragboard().hasContent(DragAndDropDataFormats.GROUP)) {
final String group = (List<String>) event.getDragboard().getContent(DragAndDropDataFormats.GROUP).get(0);
bibEntry.ifPresentOrElse(entry -> {
final String changedGroup = entry.getField(StandardField.GROUPS)
.map(setGroup -> setGroup + (preferences.getBibEntryPreferences().getKeywordSeparator()) + (group)).orElse(group);
entry.setField(StandardField.GROUPS, changedGroup);
event.setDropCompleted(true);
}, () -> event.setDropCompleted(false));
} else {
event.setDropCompleted(false);
}
event.consume();
}); |
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.
Codewise, it looks good to me! Two very minor things and it is ready to go,
- Add a short note to the CHANGELOG
- Address the empty string case for groups (dragging all entries, see note in code)
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.
LGTM! Thank you for putting your time and effort into this PR!
Thank you for the help |
fixes JabRef#569
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)