From dcb7b184fd1c3274eeb2fd1b2c93bec9f630c447 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Fri, 28 Aug 2020 21:15:21 +0200 Subject: [PATCH 1/6] Refactored EditAction --- src/main/java/org/jabref/gui/edit/EditAction.java | 3 ++- .../java/org/jabref/gui/maintable/MainTable.java | 15 +++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/edit/EditAction.java b/src/main/java/org/jabref/gui/edit/EditAction.java index 2835d825c70..a05b592b190 100644 --- a/src/main/java/org/jabref/gui/edit/EditAction.java +++ b/src/main/java/org/jabref/gui/edit/EditAction.java @@ -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; @@ -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 diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 67f2427912d..351f6b1afdc 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -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; @@ -39,7 +41,6 @@ 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; @@ -237,17 +238,15 @@ 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; - } + 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: From 7671d33bd709287e20bb5d5069c8e9c67f2e2cc7 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Fri, 28 Aug 2020 21:54:00 +0200 Subject: [PATCH 2/6] Re-enable mac-hack --- src/main/java/org/jabref/gui/maintable/MainTable.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 351f6b1afdc..e646b56b286 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -41,6 +41,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; @@ -238,7 +239,9 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) { event.consume(); break; case PASTE: - new EditAction(StandardActions.PASTE, panel.frame(), Globals.stateManager).execute(); + if (!OS.OS_X) { + new EditAction(StandardActions.PASTE, panel.frame(), Globals.stateManager).execute(); + } event.consume(); break; case COPY: From 3c459681d57c149a178d95dc57b8e6c5f59b7997 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 28 Aug 2020 22:29:31 +0200 Subject: [PATCH 3/6] Fix double pasting on mac in textfield --- src/main/java/org/jabref/gui/edit/EditAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/edit/EditAction.java b/src/main/java/org/jabref/gui/edit/EditAction.java index a05b592b190..de0016a3f20 100644 --- a/src/main/java/org/jabref/gui/edit/EditAction.java +++ b/src/main/java/org/jabref/gui/edit/EditAction.java @@ -52,7 +52,8 @@ public void execute() { textInput.cut(); break; case PASTE: - textInput.paste(); + // handled by FX in TextInputControl#paste + // textInput.paste(); break; case DELETE_ENTRY: // DELETE_ENTRY in text field should do forward delete From deb494ae2ac5aa934e6873643d268e04a2784df6 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 30 Aug 2020 18:11:20 +0200 Subject: [PATCH 4/6] setFocusTraversable to false to fix EditAction focus stealing --- src/main/java/org/jabref/gui/actions/ActionFactory.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/jabref/gui/actions/ActionFactory.java b/src/main/java/org/jabref/gui/actions/ActionFactory.java index 9174d96ff82..151a596b66c 100644 --- a/src/main/java/org/jabref/gui/actions/ActionFactory.java +++ b/src/main/java/org/jabref/gui/actions/ActionFactory.java @@ -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; } From 69a3ab7d6affa4f8d3cf2541181fb747cd9d5b45 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 30 Aug 2020 19:24:33 +0200 Subject: [PATCH 5/6] renable paste in text input --- src/main/java/org/jabref/gui/edit/EditAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/edit/EditAction.java b/src/main/java/org/jabref/gui/edit/EditAction.java index de0016a3f20..07362fc396f 100644 --- a/src/main/java/org/jabref/gui/edit/EditAction.java +++ b/src/main/java/org/jabref/gui/edit/EditAction.java @@ -52,8 +52,8 @@ public void execute() { textInput.cut(); break; case PASTE: - // handled by FX in TextInputControl#paste - // textInput.paste(); + //Executed twice for mac when pasting via cmd+v + textInput.paste(); break; case DELETE_ENTRY: // DELETE_ENTRY in text field should do forward delete From 2a9b1bf2addf837519a00ac87c52e86160cd1305 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 30 Aug 2020 20:08:03 +0200 Subject: [PATCH 6/6] Add workaround for pasting twice in OSX --- src/main/java/org/jabref/gui/JabRefFrame.java | 6 ++++++ src/main/java/org/jabref/gui/edit/EditAction.java | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index ea46b25feb0..28204b87a42 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -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; @@ -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: } } diff --git a/src/main/java/org/jabref/gui/edit/EditAction.java b/src/main/java/org/jabref/gui/edit/EditAction.java index 07362fc396f..a05b592b190 100644 --- a/src/main/java/org/jabref/gui/edit/EditAction.java +++ b/src/main/java/org/jabref/gui/edit/EditAction.java @@ -52,8 +52,7 @@ public void execute() { textInput.cut(); break; case PASTE: - //Executed twice for mac when pasting via cmd+v - textInput.paste(); + textInput.paste(); break; case DELETE_ENTRY: // DELETE_ENTRY in text field should do forward delete