From b1997e4437b46ebae03330d50fce91b3a2a5e6a4 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Sat, 29 Oct 2016 16:40:53 +0200 Subject: [PATCH 1/3] prevent the search to get focus when delting/pasting an entry --- src/main/java/net/sf/jabref/gui/BasePanel.java | 16 +++++++++++++--- .../maintable/MainTableSelectionListener.java | 5 ++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 5cf207f7079..f23d913bbc3 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -772,6 +772,13 @@ private void delete() { return; } + // 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 = new NamedCompound( (entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry"))); for (BibEntry entry : entries) { @@ -784,6 +791,9 @@ private void delete() { markBaseChanged(); frame.output(formatOutputMessage(Localization.lang("Deleted"), entries.size())); + + // prevent the main table from loosing focus + mainTable.requestFocus(); } private void paste() { @@ -827,11 +837,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 +1736,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 From 77ddd7b381a6cf3dbfdbb67f883cc813bc99a59a Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Sat, 29 Oct 2016 16:57:46 +0200 Subject: [PATCH 2/3] consider cutting entries --- .../java/net/sf/jabref/gui/BasePanel.java | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index f23d913bbc3..3ff81450a31 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,14 +740,24 @@ 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 it 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; } @@ -779,8 +768,14 @@ private void delete() { selectPreviousEntry(); } - NamedCompound compound = new NamedCompound( - (entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry"))); + NamedCompound compound; + if (!cut) { + compound = new NamedCompound( + (entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry"))); + } else { + 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); @@ -790,7 +785,7 @@ private void delete() { getUndoManager().addEdit(compound); markBaseChanged(); - frame.output(formatOutputMessage(Localization.lang("Deleted"), entries.size())); + frame.output(formatOutputMessage(!cut ? Localization.lang("Deleted") : Localization.lang("Cut"), entries.size())); // prevent the main table from loosing focus mainTable.requestFocus(); From 69bdb2b67180d4d175ee87d8bf68cbab29dc1ed2 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Sat, 29 Oct 2016 18:11:59 +0200 Subject: [PATCH 3/3] change the condition --- src/main/java/net/sf/jabref/gui/BasePanel.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 3ff81450a31..069ed66fc22 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -750,7 +750,7 @@ private void cut() { * 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 it will be localized as "cut" + * If true the action will be localized as "cut" */ private void delete(boolean cut) { List entries = mainTable.getSelectedEntries(); @@ -769,12 +769,12 @@ private void delete(boolean cut) { } NamedCompound compound; - if (!cut) { + if (cut) { compound = new NamedCompound( - (entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry"))); + (entries.size() > 1 ? Localization.lang("cut entries") : Localization.lang("cut entry"))); } else { compound = new NamedCompound( - (entries.size() > 1 ? Localization.lang("cut entries") : Localization.lang("cut entry"))); + (entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry"))); } for (BibEntry entry : entries) { compound.addEdit(new UndoableRemoveEntry(bibDatabaseContext.getDatabase(), entry, BasePanel.this)); @@ -785,7 +785,7 @@ private void delete(boolean cut) { getUndoManager().addEdit(compound); markBaseChanged(); - frame.output(formatOutputMessage(!cut ? Localization.lang("Deleted") : Localization.lang("Cut"), entries.size())); + frame.output(formatOutputMessage(cut ? Localization.lang("Cut") : Localization.lang("Deleted"), entries.size())); // prevent the main table from loosing focus mainTable.requestFocus();