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

Refactor edit action #6808

Merged
merged 6 commits into from
Aug 30, 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
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
import org.jabref.logic.undo.AddUndoableActionEvent;
import org.jabref.logic.undo.UndoChangeEvent;
import org.jabref.logic.undo.UndoRedoEvent;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.shared.DatabaseLocation;
Expand Down Expand Up @@ -278,6 +279,11 @@ private void initKeyBindings() {
case NEW_UNPUBLISHED:
new NewEntryAction(this, StandardEntryType.Unpublished, dialogService, prefs, stateManager).execute();
break;
case PASTE:
if (OS.OS_X) { // Workaround for a jdk issue that executes paste twice when using cmd+v in a TextField
event.consume();
break;
}
default:
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/actions/ActionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public Button createIconButton(Action action, Command command) {
button.graphicProperty().unbind();
action.getIcon().ifPresent(icon -> button.setGraphic(icon.getGraphicNode()));

button.setFocusTraversable(false); // Prevent the buttons from stealing the focus
return button;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/edit/EditAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public String toString() {
@Override
public void execute() {
stateManager.getFocusOwner().ifPresent(focusOwner -> {
LOGGER.debug("EditAction - focusOwner: {}; Action: {}", focusOwner.toString(), action.getText());
if (focusOwner instanceof TextInputControl) {
// Focus is on text field -> copy/paste/cut selected text
TextInputControl textInput = (TextInputControl) focusOwner;
Expand All @@ -63,7 +64,7 @@ public void execute() {

} else if (focusOwner instanceof MainTable) {

LOGGER.debug("I am a Maintable in Edit action");
LOGGER.debug("EditAction - MainTable: {}", frame.getCurrentBasePanel().getTabTitle());
// Not sure what is selected -> copy/paste/cut selected entries

// ToDo: Should be handled by BibDatabaseContext instead of BasePanel
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.DragAndDropDataFormats;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.edit.EditAction;
import org.jabref.gui.externalfiles.ImportHandler;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.keyboard.KeyBinding;
Expand Down Expand Up @@ -237,17 +239,17 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) {
event.consume();
break;
case PASTE:
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;
if (!OS.OS_X) {
new EditAction(StandardActions.PASTE, panel.frame(), Globals.stateManager).execute();
}
event.consume();
break;
case COPY:
copy();
new EditAction(StandardActions.COPY, panel.frame(), Globals.stateManager).execute();
event.consume();
break;
case CUT:
cut();
new EditAction(StandardActions.CUT, panel.frame(), Globals.stateManager).execute();
event.consume();
break;
default:
Expand Down