-
-
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
Fix paste of BibTeX data #9985
Fix paste of BibTeX data #9985
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,11 @@ public void cut() { | |
} | ||
|
||
private void setupKeyBindings(KeyBindingRepository keyBindings) { | ||
EditAction pasteAction = new EditAction(StandardActions.PASTE, libraryTab.frame(), stateManager); | ||
EditAction copyAction = new EditAction(StandardActions.COPY, libraryTab.frame(), stateManager); | ||
EditAction cutAction = new EditAction(StandardActions.CUT, libraryTab.frame(), stateManager); | ||
EditAction deleteAction = new EditAction(StandardActions.DELETE_ENTRY, libraryTab.frame(), stateManager); | ||
|
||
this.addEventFilter(KeyEvent.KEY_PRESSED, event -> { | ||
if (event.getCode() == KeyCode.ENTER) { | ||
getSelectedEntries().stream() | ||
|
@@ -288,19 +293,19 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) { | |
event.consume(); | ||
break; | ||
case PASTE: | ||
new EditAction(StandardActions.PASTE, libraryTab.frame(), stateManager).execute(); | ||
pasteAction.execute(); | ||
event.consume(); | ||
break; | ||
case COPY: | ||
new EditAction(StandardActions.COPY, libraryTab.frame(), stateManager).execute(); | ||
copyAction.execute(); | ||
event.consume(); | ||
break; | ||
case CUT: | ||
new EditAction(StandardActions.CUT, libraryTab.frame(), stateManager).execute(); | ||
cutAction.execute(); | ||
event.consume(); | ||
break; | ||
case DELETE_ENTRY: | ||
new EditAction(StandardActions.DELETE_ENTRY, libraryTab.frame(), stateManager).execute(); | ||
deleteAction.execute(); | ||
event.consume(); | ||
break; | ||
default: | ||
|
@@ -324,23 +329,22 @@ private void clearAndSelectLast() { | |
|
||
public void paste() { | ||
List<BibEntry> entriesToAdd; | ||
entriesToAdd = this.clipBoardManager.getBibTeXEntriesFromClipboard() | ||
.map(importHandler::handleBibTeXData) | ||
.orElseGet(this::handleNonBibTeXStringData); | ||
|
||
String content = ClipBoardManager.getContents(); | ||
entriesToAdd = importHandler.handleBibTeXData(content); | ||
if (entriesToAdd.isEmpty()) { | ||
entriesToAdd = handleNonBibTeXStringData(content); | ||
} | ||
if (entriesToAdd.isEmpty()) { | ||
return; | ||
} | ||
for (BibEntry entry : entriesToAdd) { | ||
importHandler.importEntryWithDuplicateCheck(database, entry); | ||
} | ||
if (!entriesToAdd.isEmpty()) { | ||
this.requestFocus(); | ||
} | ||
} | ||
|
||
private List<BibEntry> handleNonBibTeXStringData() { | ||
String data = ClipBoardManager.getContents(); | ||
List<BibEntry> entries = new ArrayList<>(); | ||
private List<BibEntry> handleNonBibTeXStringData(String data) { | ||
try { | ||
entries = this.importHandler.handleStringData(data); | ||
return this.importHandler.handleStringData(data); | ||
} catch (FetcherException exception) { | ||
if (exception instanceof FetcherClientException) { | ||
dialogService.showInformationDialogAndWait(Localization.lang("Look up identifier"), Localization.lang("No data was found for the identifier")); | ||
|
@@ -349,8 +353,8 @@ private List<BibEntry> handleNonBibTeXStringData() { | |
} else { | ||
dialogService.showErrorDialogAndWait(exception); | ||
} | ||
return List.of(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. List.of is unmodiefable. Be careful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the calling code and also tried out locally. In general, the list of entries in the clipboard should not be modified. -- If someone pastes twice and continues working, this should not be modified. I thought, this behavior is also "expected" for immediate code handling pasted data. Soemtimes, I lean to follow https://github.com/HugoMatilla/Effective-JAVA-Summary#15-minimize-mutability, but I think, its very hard to implement (and causes much more resources). |
||
} | ||
return entries; | ||
} | ||
|
||
public void dropEntry(List<BibEntry> entriesToAdd) { | ||
|
@@ -393,8 +397,8 @@ private void handleOnDragDetected(TableRow<BibEntryTableViewModel> row, BibEntry | |
|
||
List<BibEntry> entries = getSelectionModel().getSelectedItems().stream().map(BibEntryTableViewModel::getEntry).collect(Collectors.toList()); | ||
|
||
// The following is necesary to initiate the drag and drop in javafx, although we don't need the contents | ||
// It doesn't work without | ||
// The following is necessary to initiate the drag and drop in JavaFX, | ||
// although we don't need the contents, it does not work without | ||
// Drag'n'drop to other tabs use COPY TransferMode, drop to group sidepane use MOVE | ||
ClipboardContent content = new ClipboardContent(); | ||
Dragboard dragboard = startDragAndDrop(TransferMode.COPY_OR_MOVE); | ||
|
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.
Why do you remove setting them for the DragAndDropDataFormat here? I think this was also neceessary for drag and drop with groups
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.
Drag drop is handled differently.
I checked all usages of the variable carefully.
Example 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.
but that is for drag and drop between groups. Not entries
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.
I still assume that dragstrop is handled by dragophandler and not by the copy functionality. Dragging is iMho natively supported by JavaFX and we do not need to emulate it via copy and paste. This is how I understood the existing code. I checked drag and drop, too