Skip to content

Commit

Permalink
Fix copy pasting and delete via menu or key (#6740)
Browse files Browse the repository at this point in the history
* Fix copy pasting via menu

Add hack for OSX.
Caveat: Prevents pasting using Cmd+V on an empty library

* fix checkstyle
  • Loading branch information
Siedlerchr authored Aug 6, 2020
1 parent 3d68514 commit 7d66c25
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
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

0 comments on commit 7d66c25

Please sign in to comment.