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

Fix del/copy/paste key trigger main table action in search bar #3070

Merged
merged 5 commits into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ If fetched article is already in database the ImportInspectionDialog is started
We fixed an issue where the fetcher for the Astrophysics Data System (ADS) added some non-bibtex data to the entry returned from the search [#3035](https://github.com/JabRef/jabref/issues/3035)
We fixed an issue where assigning an entry via drag and drop to a group caused JabRef to stop/freeze completely [#3036](https://github.com/JabRef/jabref/issues/3036)
We fixed an issue where the preferences could not be imported without a restart of JabRef [#3064](https://github.com/JabRef/jabref/issues/3064)
We fixed an issue where <kbd>DEL</kbd>, <kbd>Ctrl</kbd>+<kbd>C</kbd>, <kbd>Ctrl</kbd>+<kbd>V</kbd> and <kbd>Ctrl</kbd>+<kbd>A</kbd> in the search field triggered corresponding actions in the main table [#3067](https://github.com/JabRef/jabref/issues/3067)
### Removed


Expand Down
15 changes: 2 additions & 13 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.awt.Insets;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.KeyListener;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -157,18 +157,7 @@ public EntryEditor(JabRefFrame frame, BasePanel panel, BibEntry entry, String la

JFXPanel container = new JFXPanel();

container.addKeyListener(new KeyListener() {

@Override
public void keyTyped(java.awt.event.KeyEvent e) {
//empty
}

@Override
public void keyReleased(java.awt.event.KeyEvent e) {
// empty

}
container.addKeyListener(new KeyAdapter() {

@Override
public void keyPressed(java.awt.event.KeyEvent e) {
Expand Down
67 changes: 31 additions & 36 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.io.File;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.swing.AbstractAction;
Expand Down Expand Up @@ -61,7 +63,6 @@ public class GlobalSearchBar extends JPanel {
private static final PseudoClass CLASS_NO_RESULTS = PseudoClass.getPseudoClass("emptyResult");
private static final PseudoClass CLASS_RESULTS_FOUND = PseudoClass.getPseudoClass("emptyResult");


private final JabRefFrame frame;

private final TextField searchField = SearchTextField.create();
Expand All @@ -70,7 +71,7 @@ public class GlobalSearchBar extends JPanel {
private final JButton searchModeButton = new JButton();
private final JLabel currentResults = new JLabel("");
private final SearchQueryHighlightObservable searchQueryHighlightObservable = new SearchQueryHighlightObservable();
private JButton openCurrentResultsInDialog = new JButton(IconTheme.JabRefIcon.OPEN_IN_NEW_WINDOW.getSmallIcon());
private final JButton openCurrentResultsInDialog = new JButton(IconTheme.JabRefIcon.OPEN_IN_NEW_WINDOW.getSmallIcon());
private SearchWorker searchWorker;
private GlobalSearchWorker globalSearchWorker;

Expand All @@ -83,7 +84,6 @@ public class GlobalSearchBar extends JPanel {
*/
private boolean dontSelectSearchBar;


public GlobalSearchBar(JabRefFrame frame) {
super();
this.frame = Objects.requireNonNull(frame);
Expand All @@ -99,6 +99,7 @@ public GlobalSearchBar(JabRefFrame frame) {

// default action to be performed for toggling globalSearch
AbstractAction globalSearchStandardAction = new AbstractAction() {

@Override
public void actionPerformed(ActionEvent e) {
searchPreferences.setGlobalSearch(globalSearch.isSelected());
Expand All @@ -108,6 +109,7 @@ public void actionPerformed(ActionEvent e) {

// additional action for global search shortcut
AbstractAction globalSearchShortCutAction = new AbstractAction() {

@Override
public void actionPerformed(ActionEvent e) {
globalSearch.setSelected(true);
Expand Down Expand Up @@ -154,38 +156,31 @@ public void actionPerformed(ActionEvent e) {

EasyBind.subscribe(searchField.textProperty(), searchText -> performSearch());

/*
String endSearch = "endSearch";
searchField.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLEAR_SEARCH), endSearch);
Copy link
Member

Choose a reason for hiding this comment

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

Do these keyboard shortcuts now work as expected?
Would be nice if they do otherwise I would prefer to keep the commented-out code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I thought the commented code ws just obsolete. I will see if I can fix this issue, too

Copy link
Member Author

@Siedlerchr Siedlerchr Aug 4, 2017

Choose a reason for hiding this comment

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

I could not get them to work, so I added a TODO. This also depends on #3076 which will be out of scope for this PR

searchField.getActionMap().put(endSearch, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent event) {
if (autoCompleteSupport.isVisible()) {
autoCompleteSupport.setVisible(false);
} else {
endSearch();
}
}
});
*/

/*
String acceptSearch = "acceptSearch";
searchField.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.ACCEPT), acceptSearch);
searchField.getActionMap().put(acceptSearch, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
autoCompleteSupport.setVisible(false);
BasePanel currentBasePanel = frame.getCurrentBasePanel();
Globals.getFocusListener().setFocused(currentBasePanel.getMainTable());
currentBasePanel.getMainTable().requestFocus();
}
});
*/

JFXPanel container = new JFXPanel();
DefaultTaskExecutor.runInJavaFXThread(() -> {
container.setScene(new Scene(searchField));
container.addKeyListener(new KeyAdapter() {

@Override
public void keyPressed(java.awt.event.KeyEvent e) {
//We need to consume this event here to prevent the propgation of keybinding events back to the JFrame
Optional<KeyBinding> keyBinding = Globals.getKeyPrefs().mapToKeyBinding(e);
if (keyBinding.isPresent()) {
switch (keyBinding.get()) {
case CUT:
case COPY:
case PASTE:
case DELETE_ENTRY:
case SELECT_ALL:
e.consume();
break;
default:
//do nothing
}
}
}
});

});

setLayout(new FlowLayout(FlowLayout.RIGHT));
Expand All @@ -207,7 +202,7 @@ public void actionPerformed(ActionEvent e) {

public void performGlobalSearch() {
BasePanel currentBasePanel = frame.getCurrentBasePanel();
if (currentBasePanel == null || validateSearchResultFrame(true)) {
if ((currentBasePanel == null) || validateSearchResultFrame(true)) {
return;
}

Expand All @@ -226,7 +221,7 @@ public void performGlobalSearch() {

private void openLocalFindingsInExternalPanel() {
BasePanel currentBasePanel = frame.getCurrentBasePanel();
if (currentBasePanel == null || validateSearchResultFrame(false)) {
if ((currentBasePanel == null) || validateSearchResultFrame(false)) {
return;
}

Expand All @@ -237,7 +232,7 @@ private void openLocalFindingsInExternalPanel() {

SearchResultFrame searchDialog = new SearchResultFrame(currentBasePanel.frame(),
Localization.lang("Search results in library %0 for %1", currentBasePanel.getBibDatabaseContext()
.getDatabaseFile().map(File::getName).orElse(GUIGlobals.UNTITLED_TITLE),
.getDatabaseFile().map(File::getName).orElse(GUIGlobals.UNTITLED_TITLE),
this.getSearchQuery().localize()),
getSearchQuery(), false);
List<BibEntry> entries = currentBasePanel.getDatabase().getEntries().stream()
Expand All @@ -250,7 +245,7 @@ private void openLocalFindingsInExternalPanel() {

private boolean validateSearchResultFrame(boolean globalSearch) {
if (searchResultFrame != null) {
if (searchResultFrame.isGlobalSearch() == globalSearch && isStillValidQuery(searchResultFrame.getSearchQuery())) {
if ((searchResultFrame.isGlobalSearch() == globalSearch) && isStillValidQuery(searchResultFrame.getSearchQuery())) {
searchResultFrame.focus();
return true;
} else {
Expand Down