diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 5cf207f7079..069ed66fc22 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -335,32 +335,11 @@ private void setupActions() { actions.put(Actions.PRINT_PREVIEW, new PrintPreviewAction()); - //when you modify this action be sure to adjust Actions.DELETE - //they are the same except of the Localization, delete confirmation and Actions.COPY call - actions.put(Actions.CUT, (BaseAction) () -> { - runCommand(Actions.COPY); - List entries = mainTable.getSelectedEntries(); - if (entries.isEmpty()) { - return; - } - - NamedCompound compound = new NamedCompound( - (entries.size() > 1 ? Localization.lang("cut entries") : Localization.lang("cut entry"))); - for (BibEntry entry : entries) { - compound.addEdit(new UndoableRemoveEntry(bibDatabaseContext.getDatabase(), entry, BasePanel.this)); - bibDatabaseContext.getDatabase().removeEntry(entry); - ensureNotShowingBottomPanel(entry); - } - compound.end(); - getUndoManager().addEdit(compound); - - frame.output(formatOutputMessage(Localization.lang("Cut"), entries.size())); - markBaseChanged(); - }); + actions.put(Actions.CUT, (BaseAction) this::cut); //when you modify this action be sure to adjust Actions.CUT, //they are the same except of the Localization, delete confirmation and Actions.COPY call - actions.put(Actions.DELETE, (BaseAction) () -> delete()); + actions.put(Actions.DELETE, (BaseAction) () -> delete(false)); // The action for pasting entries or cell contents. // - more robust detection of available content flavors (doesn't only look at first one offered) @@ -761,19 +740,42 @@ private void copy() { } } - //when you modify this action be sure to adjust Actions.CUT, - //they are the same except of the Localization, delete confirmation and Actions.COPY call - private void delete() { + private void cut() { + runCommand(Actions.COPY); + // cannot call runCommand(Actions.DELETE), b/c it will call delete(false) with the wrong parameter + delete(true); + } + + /** + * Removes the selected entries from the database + * @param cut If false the user will get asked if he really wants to delete the entries, and it will be localized + * as "deleted". + * If true the action will be localized as "cut" + */ + private void delete(boolean cut) { List entries = mainTable.getSelectedEntries(); if (entries.isEmpty()) { return; } - if (!showDeleteConfirmationDialog(entries.size())) { + if (!cut && !showDeleteConfirmationDialog(entries.size())) { return; } - NamedCompound compound = new NamedCompound( - (entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry"))); + // select the next entry to stay at the same place as before (or the previous if we're already at the end) + if (mainTable.getSelectedRow() != mainTable.getRowCount() -1){ + selectNextEntry(); + } else { + selectPreviousEntry(); + } + + NamedCompound compound; + if (cut) { + compound = new NamedCompound( + (entries.size() > 1 ? Localization.lang("cut entries") : Localization.lang("cut entry"))); + } else { + compound = new NamedCompound( + (entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry"))); + } for (BibEntry entry : entries) { compound.addEdit(new UndoableRemoveEntry(bibDatabaseContext.getDatabase(), entry, BasePanel.this)); bibDatabaseContext.getDatabase().removeEntry(entry); @@ -783,7 +785,10 @@ private void delete() { getUndoManager().addEdit(compound); markBaseChanged(); - frame.output(formatOutputMessage(Localization.lang("Deleted"), entries.size())); + frame.output(formatOutputMessage(cut ? Localization.lang("Cut") : Localization.lang("Deleted"), entries.size())); + + // prevent the main table from loosing focus + mainTable.requestFocus(); } private void paste() { @@ -827,11 +832,12 @@ private void paste() { output(formatOutputMessage(Localization.lang("Pasted"), bes.size())); markBaseChanged(); + highlightEntry(firstBE); + mainTable.requestFocus(); + if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { selectionListener.editSignalled(firstBE); } - - highlightEntry(firstBE); } } @@ -1725,7 +1731,6 @@ public void selectNextEntry() { highlightEntry((mainTable.getSelectedRow() + 1) % mainTable.getRowCount()); } - public void selectFirstEntry() { highlightEntry(0); } diff --git a/src/main/java/net/sf/jabref/gui/maintable/MainTableSelectionListener.java b/src/main/java/net/sf/jabref/gui/maintable/MainTableSelectionListener.java index 4208c9dc41e..3470c299405 100644 --- a/src/main/java/net/sf/jabref/gui/maintable/MainTableSelectionListener.java +++ b/src/main/java/net/sf/jabref/gui/maintable/MainTableSelectionListener.java @@ -183,11 +183,10 @@ public void editSignalled() { public void editSignalled(BibEntry entry) { final BasePanelMode mode = panel.getMode(); - EntryEditor editor = panel.getEntryEditor(entry); if (mode != BasePanelMode.SHOWING_EDITOR) { - panel.showEntryEditor(editor); + panel.showEntryEditor(panel.getEntryEditor(entry)); } - editor.requestFocus(); + panel.getCurrentEditor().requestFocus(); } @Override