Skip to content

Commit 2faa149

Browse files
Siedlerchrcalixtus
andauthored
Refactor edit action (#6808)
Co-authored-by: Carl Christian Snethlage <[email protected]>
1 parent 5540b93 commit 2faa149

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/main/java/org/jabref/gui/JabRefFrame.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
import org.jabref.logic.undo.AddUndoableActionEvent;
133133
import org.jabref.logic.undo.UndoChangeEvent;
134134
import org.jabref.logic.undo.UndoRedoEvent;
135+
import org.jabref.logic.util.OS;
135136
import org.jabref.logic.util.io.FileUtil;
136137
import org.jabref.model.database.BibDatabaseContext;
137138
import org.jabref.model.database.shared.DatabaseLocation;
@@ -278,6 +279,11 @@ private void initKeyBindings() {
278279
case NEW_UNPUBLISHED:
279280
new NewEntryAction(this, StandardEntryType.Unpublished, dialogService, prefs, stateManager).execute();
280281
break;
282+
case PASTE:
283+
if (OS.OS_X) { // Workaround for a jdk issue that executes paste twice when using cmd+v in a TextField
284+
event.consume();
285+
break;
286+
}
281287
default:
282288
}
283289
}

src/main/java/org/jabref/gui/actions/ActionFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public Button createIconButton(Action action, Command command) {
136136
button.graphicProperty().unbind();
137137
action.getIcon().ifPresent(icon -> button.setGraphic(icon.getGraphicNode()));
138138

139+
button.setFocusTraversable(false); // Prevent the buttons from stealing the focus
139140
return button;
140141
}
141142

src/main/java/org/jabref/gui/edit/EditAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public String toString() {
4040
@Override
4141
public void execute() {
4242
stateManager.getFocusOwner().ifPresent(focusOwner -> {
43+
LOGGER.debug("EditAction - focusOwner: {}; Action: {}", focusOwner.toString(), action.getText());
4344
if (focusOwner instanceof TextInputControl) {
4445
// Focus is on text field -> copy/paste/cut selected text
4546
TextInputControl textInput = (TextInputControl) focusOwner;
@@ -63,7 +64,7 @@ public void execute() {
6364

6465
} else if (focusOwner instanceof MainTable) {
6566

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

6970
// ToDo: Should be handled by BibDatabaseContext instead of BasePanel

src/main/java/org/jabref/gui/maintable/MainTable.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.jabref.gui.DialogService;
3030
import org.jabref.gui.DragAndDropDataFormats;
3131
import org.jabref.gui.StateManager;
32+
import org.jabref.gui.actions.StandardActions;
33+
import org.jabref.gui.edit.EditAction;
3234
import org.jabref.gui.externalfiles.ImportHandler;
3335
import org.jabref.gui.externalfiletype.ExternalFileTypes;
3436
import org.jabref.gui.keyboard.KeyBinding;
@@ -237,17 +239,17 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) {
237239
event.consume();
238240
break;
239241
case PASTE:
240-
if (!OS.OS_X) { // ugly hack, prevents duplicate entries on pasting. Side effect: Prevents pasting using cmd+v on an empty library
241-
paste();
242-
event.consume();
243-
break;
242+
if (!OS.OS_X) {
243+
new EditAction(StandardActions.PASTE, panel.frame(), Globals.stateManager).execute();
244244
}
245+
event.consume();
246+
break;
245247
case COPY:
246-
copy();
248+
new EditAction(StandardActions.COPY, panel.frame(), Globals.stateManager).execute();
247249
event.consume();
248250
break;
249251
case CUT:
250-
cut();
252+
new EditAction(StandardActions.CUT, panel.frame(), Globals.stateManager).execute();
251253
event.consume();
252254
break;
253255
default:

0 commit comments

Comments
 (0)