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 copy pasting and delete via menu or key #6740

Merged
merged 2 commits into from
Aug 6, 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
29 changes: 29 additions & 0 deletions src/main/java/org/jabref/gui/edit/EditAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.maintable.MainTable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Class for handling general actions; cut, copy and paste. The focused component is kept track of by
* Globals.focusListener, and we call the action stored under the relevant name in its action map.
*/
public class EditAction extends SimpleCommand {

private static final Logger LOGGER = LoggerFactory.getLogger(EditAction.class);

private final JabRefFrame frame;
private final StandardActions action;
private final StateManager stateManager;
Expand Down Expand Up @@ -54,6 +60,29 @@ public void execute() {
default:
throw new IllegalStateException("Only cut/copy/paste supported in TextInputControl but got " + action);
}

} else if (focusOwner instanceof MainTable) {

LOGGER.debug("I am a Maintable in Edit action");
// Not sure what is selected -> copy/paste/cut selected entries

// ToDo: Should be handled by BibDatabaseContext instead of BasePanel
switch (action) {
case COPY:
frame.getCurrentBasePanel().copy();
break;
case CUT:
frame.getCurrentBasePanel().cut();
break;
case PASTE:
frame.getCurrentBasePanel().paste();
break;
case DELETE_ENTRY:
frame.getCurrentBasePanel().delete(false);
break;
default:
throw new IllegalStateException("Only cut/copy/paste supported but got " + action);
}
}
});
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.ViewModelTableRowFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.event.EntriesAddedEvent;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -221,9 +222,11 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) {
event.consume();
break;
case PASTE:
paste();
event.consume();
break;
if (!OS.OS_X) { // ugly hack, prevents duplicate entries on pasting. Side effect: Prevents pasting using cmd+v on an empty library
paste();
event.consume();
break;
}
case COPY:
copy();
event.consume();
Expand Down Expand Up @@ -258,6 +261,7 @@ public void paste() {
if (!entriesToAdd.isEmpty()) {
this.requestFocus();
}

}

private void handleOnDragOver(TableRow<BibEntryTableViewModel> row, BibEntryTableViewModel item, DragEvent event) {
Expand Down