Skip to content

Commit

Permalink
Merge pull request #2211 from bartsch-dev/dontFocusSearch
Browse files Browse the repository at this point in the history
Prevent the search to get focus when deleting/pasting an entry
  • Loading branch information
koppor authored Oct 30, 2016
2 parents 6e43be0 + 69bdb2b commit 1b676b7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
71 changes: 38 additions & 33 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<BibEntry> 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)
Expand Down Expand Up @@ -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<BibEntry> 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);
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -1725,7 +1731,6 @@ public void selectNextEntry() {
highlightEntry((mainTable.getSelectedRow() + 1) % mainTable.getRowCount());
}


public void selectFirstEntry() {
highlightEntry(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b676b7

Please sign in to comment.