Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent the search to get focus when deleting/pasting an entry #2211

Merged
merged 3 commits into from
Oct 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either you change the condition and put cut instead of not cut or you wrap it in if and else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to cut (but didn't change the semantic').

// 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new editor was only needed if the condition was met, and previously the focus was possibly set to the wrong editor (if the condition wasn't met).

panel.showEntryEditor(editor);
panel.showEntryEditor(panel.getEntryEditor(entry));
}
editor.requestFocus();
panel.getCurrentEditor().requestFocus();
}

@Override
Expand Down