55import java .awt .FlowLayout ;
66import java .awt .Font ;
77import java .awt .event .ActionEvent ;
8+ import java .awt .event .KeyAdapter ;
89import java .io .File ;
910import java .util .List ;
1011import java .util .Objects ;
12+ import java .util .Optional ;
1113import java .util .stream .Collectors ;
1214
1315import javax .swing .AbstractAction ;
@@ -61,7 +63,6 @@ public class GlobalSearchBar extends JPanel {
6163 private static final PseudoClass CLASS_NO_RESULTS = PseudoClass .getPseudoClass ("emptyResult" );
6264 private static final PseudoClass CLASS_RESULTS_FOUND = PseudoClass .getPseudoClass ("emptyResult" );
6365
64-
6566 private final JabRefFrame frame ;
6667
6768 private final TextField searchField = SearchTextField .create ();
@@ -70,7 +71,7 @@ public class GlobalSearchBar extends JPanel {
7071 private final JButton searchModeButton = new JButton ();
7172 private final JLabel currentResults = new JLabel ("" );
7273 private final SearchQueryHighlightObservable searchQueryHighlightObservable = new SearchQueryHighlightObservable ();
73- private JButton openCurrentResultsInDialog = new JButton (IconTheme .JabRefIcon .OPEN_IN_NEW_WINDOW .getSmallIcon ());
74+ private final JButton openCurrentResultsInDialog = new JButton (IconTheme .JabRefIcon .OPEN_IN_NEW_WINDOW .getSmallIcon ());
7475 private SearchWorker searchWorker ;
7576 private GlobalSearchWorker globalSearchWorker ;
7677
@@ -83,7 +84,6 @@ public class GlobalSearchBar extends JPanel {
8384 */
8485 private boolean dontSelectSearchBar ;
8586
86-
8787 public GlobalSearchBar (JabRefFrame frame ) {
8888 super ();
8989 this .frame = Objects .requireNonNull (frame );
@@ -99,6 +99,7 @@ public GlobalSearchBar(JabRefFrame frame) {
9999
100100 // default action to be performed for toggling globalSearch
101101 AbstractAction globalSearchStandardAction = new AbstractAction () {
102+
102103 @ Override
103104 public void actionPerformed (ActionEvent e ) {
104105 searchPreferences .setGlobalSearch (globalSearch .isSelected ());
@@ -108,13 +109,43 @@ public void actionPerformed(ActionEvent e) {
108109
109110 // additional action for global search shortcut
110111 AbstractAction globalSearchShortCutAction = new AbstractAction () {
112+
111113 @ Override
112114 public void actionPerformed (ActionEvent e ) {
113115 globalSearch .setSelected (true );
114116 globalSearchStandardAction .actionPerformed (new ActionEvent (this , 0 , "fire standard action" ));
115117 focus ();
116118 }
117119 };
120+ //TODO: These have to be somehow converted
121+ /*
122+ String endSearch = "endSearch";
123+ searchField.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLEAR_SEARCH), endSearch);
124+ searchField.getActionMap().put(endSearch, new AbstractAction() {
125+ @Override
126+ public void actionPerformed(ActionEvent event) {
127+ if (autoCompleteSupport.isVisible()) {
128+ autoCompleteSupport.setVisible(false);
129+ } else {
130+ endSearch();
131+ }
132+ }
133+ });
134+ */
135+
136+ /*
137+ String acceptSearch = "acceptSearch";
138+ searchField.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.ACCEPT), acceptSearch);
139+ searchField.getActionMap().put(acceptSearch, new AbstractAction() {
140+ @Override
141+ public void actionPerformed(ActionEvent e) {
142+ autoCompleteSupport.setVisible(false);
143+ BasePanel currentBasePanel = frame.getCurrentBasePanel();
144+ Globals.getFocusListener().setFocused(currentBasePanel.getMainTable());
145+ currentBasePanel.getMainTable().requestFocus();
146+ }
147+ });
148+ */
118149
119150 String searchGlobalByKey = "searchGlobalByKey" ;
120151 globalSearch .getInputMap (JComponent .WHEN_IN_FOCUSED_WINDOW ).put (Globals .getKeyPrefs ().getKey (KeyBinding .GLOBAL_SEARCH ), searchGlobalByKey );
@@ -154,38 +185,31 @@ public void actionPerformed(ActionEvent e) {
154185
155186 EasyBind .subscribe (searchField .textProperty (), searchText -> performSearch ());
156187
157- /*
158- String endSearch = "endSearch";
159- searchField.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLEAR_SEARCH), endSearch);
160- searchField.getActionMap().put(endSearch, new AbstractAction() {
161- @Override
162- public void actionPerformed(ActionEvent event) {
163- if (autoCompleteSupport.isVisible()) {
164- autoCompleteSupport.setVisible(false);
165- } else {
166- endSearch();
167- }
168- }
169- });
170- */
171-
172- /*
173- String acceptSearch = "acceptSearch";
174- searchField.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.ACCEPT), acceptSearch);
175- searchField.getActionMap().put(acceptSearch, new AbstractAction() {
176- @Override
177- public void actionPerformed(ActionEvent e) {
178- autoCompleteSupport.setVisible(false);
179- BasePanel currentBasePanel = frame.getCurrentBasePanel();
180- Globals.getFocusListener().setFocused(currentBasePanel.getMainTable());
181- currentBasePanel.getMainTable().requestFocus();
182- }
183- });
184- */
185-
186188 JFXPanel container = new JFXPanel ();
187189 DefaultTaskExecutor .runInJavaFXThread (() -> {
188190 container .setScene (new Scene (searchField ));
191+ container .addKeyListener (new KeyAdapter () {
192+
193+ @ Override
194+ public void keyPressed (java .awt .event .KeyEvent e ) {
195+ //We need to consume this event here to prevent the propgation of keybinding events back to the JFrame
196+ Optional <KeyBinding > keyBinding = Globals .getKeyPrefs ().mapToKeyBinding (e );
197+ if (keyBinding .isPresent ()) {
198+ switch (keyBinding .get ()) {
199+ case CUT :
200+ case COPY :
201+ case PASTE :
202+ case DELETE_ENTRY :
203+ case SELECT_ALL :
204+ e .consume ();
205+ break ;
206+ default :
207+ //do nothing
208+ }
209+ }
210+ }
211+ });
212+
189213 });
190214
191215 setLayout (new FlowLayout (FlowLayout .RIGHT ));
@@ -207,7 +231,7 @@ public void actionPerformed(ActionEvent e) {
207231
208232 public void performGlobalSearch () {
209233 BasePanel currentBasePanel = frame .getCurrentBasePanel ();
210- if (currentBasePanel == null || validateSearchResultFrame (true )) {
234+ if (( currentBasePanel == null ) || validateSearchResultFrame (true )) {
211235 return ;
212236 }
213237
@@ -226,7 +250,7 @@ public void performGlobalSearch() {
226250
227251 private void openLocalFindingsInExternalPanel () {
228252 BasePanel currentBasePanel = frame .getCurrentBasePanel ();
229- if (currentBasePanel == null || validateSearchResultFrame (false )) {
253+ if (( currentBasePanel == null ) || validateSearchResultFrame (false )) {
230254 return ;
231255 }
232256
@@ -237,7 +261,7 @@ private void openLocalFindingsInExternalPanel() {
237261
238262 SearchResultFrame searchDialog = new SearchResultFrame (currentBasePanel .frame (),
239263 Localization .lang ("Search results in library %0 for %1" , currentBasePanel .getBibDatabaseContext ()
240- .getDatabaseFile ().map (File ::getName ).orElse (GUIGlobals .UNTITLED_TITLE ),
264+ .getDatabaseFile ().map (File ::getName ).orElse (GUIGlobals .UNTITLED_TITLE ),
241265 this .getSearchQuery ().localize ()),
242266 getSearchQuery (), false );
243267 List <BibEntry > entries = currentBasePanel .getDatabase ().getEntries ().stream ()
@@ -250,7 +274,7 @@ private void openLocalFindingsInExternalPanel() {
250274
251275 private boolean validateSearchResultFrame (boolean globalSearch ) {
252276 if (searchResultFrame != null ) {
253- if (searchResultFrame .isGlobalSearch () == globalSearch && isStillValidQuery (searchResultFrame .getSearchQuery ())) {
277+ if (( searchResultFrame .isGlobalSearch () == globalSearch ) && isStillValidQuery (searchResultFrame .getSearchQuery ())) {
254278 searchResultFrame .focus ();
255279 return true ;
256280 } else {
@@ -358,6 +382,7 @@ public void setAutoCompleter(AutoCompleteSuggestionProvider<Author> searchComple
358382 searchCompleter ,
359383 new PersonNameStringConverter (true , true , AutoCompleteFirstNameMode .BOTH ),
360384 new AppendPersonNamesStrategy ());
385+
361386 }
362387
363388 public SearchQueryHighlightObservable getSearchQueryHighlightObservable () {
@@ -384,7 +409,7 @@ public void updateResults(int matched, String description, boolean grammarBasedS
384409 currentResults .setText (Localization .lang ("Found %0 results." , String .valueOf (matched )));
385410 searchField .pseudoClassStateChanged (CLASS_RESULTS_FOUND , true );
386411 }
387- searchField .setTooltip (new Tooltip (description ));
412+ DefaultTaskExecutor . runInJavaFXThread (() -> searchField .setTooltip (new Tooltip (description ) ));
388413 openCurrentResultsInDialog .setEnabled (true );
389414 }
390415
0 commit comments