2626import gr .sqlbrowserfx .nodes .ContextMenuOwner ;
2727import gr .sqlbrowserfx .nodes .InputMapOwner ;
2828import gr .sqlbrowserfx .nodes .SearchAndReplacePopOver ;
29+ import gr .sqlbrowserfx .nodes .SearchInFilesPopOver ;
2930import gr .sqlbrowserfx .nodes .codeareas .sql .SimpleLineNumberFactory ;
3031import gr .sqlbrowserfx .utils .JavaFXUtils ;
3132import javafx .application .Platform ;
@@ -51,14 +52,14 @@ public abstract class AutoCompleteCodeArea<T extends CodeAreaSyntaxProvider> ext
5152 // this is a random offset that achieves to locate correctly
5253 // the autocomplete pop up when zooming
5354 private static final int Y_OFFSET = (int ) (Math .round (JavaFXUtils .getZoomFactorApplied () * 35 + 5 ));
54- private boolean autoCompletePopupShowing = false ;
5555 private boolean insertMode = false ;
5656 private boolean hasSimpleContextMenu = false ;
5757 private final T syntaxProvider ;
5858
5959 private ListView <Keyword > suggestionsList ;
6060 private Popup autoCompletePopup ;
6161 protected SearchAndReplacePopOver searchAndReplacePopOver ;
62+ protected SearchInFilesPopOver searchInFilesPopOver ;
6263 private final SimpleBooleanProperty showLinesProperty = new SimpleBooleanProperty (true );
6364 private final SimpleBooleanProperty autoCompleteProperty = new SimpleBooleanProperty (true );
6465 private final SimpleBooleanProperty isTextSelectedProperty = new SimpleBooleanProperty (false );
@@ -77,15 +78,9 @@ public AutoCompleteCodeArea(String text, boolean editable, boolean withMenu, boo
7778 super ();
7879
7980 this .setEditable (editable );
80-
8181 this .selectedTextProperty ().addListener ((ob , ov , nv ) -> this .isTextSelectedProperty .set (!nv .isEmpty ()));
82-
83- searchAndReplacePopOver = new SearchAndReplacePopOver (this );
84- autoCompletePopup = this .createAutoCompletePopup ();
85-
8682 this .setContextMenu (this .createContextMenu ());
8783 this .setKeys ();
88-
8984 this .setOnMouseClicked (mouseEvent -> this .onMouseClicked ());
9085
9186 this .showLinesProperty .addListener ((ob , ov , nv ) -> enableShowLineNumbers (nv ));
@@ -111,13 +106,32 @@ public AutoCompleteCodeArea(String text, boolean editable, boolean withMenu, boo
111106
112107 abstract protected T initSyntaxProvider ();
113108
109+ protected Boolean isAutoCompletePopupShowing () {
110+ return this .autoCompletePopup != null && this .autoCompletePopup .isShowing ();
111+ }
112+
113+ protected Boolean isSearchInFilesPopOverShowing () {
114+ return this .searchInFilesPopOver != null && this .searchInFilesPopOver .isShowing ();
115+ }
116+
117+ protected Boolean isSearchAndReplacePopOverShowing () {
118+ return this .searchAndReplacePopOver != null && this .searchAndReplacePopOver .isShowing ();
119+ }
120+
121+
114122 protected void onMouseClicked () {
115- if (autoCompletePopupShowing ) {
123+ if (isAutoCompletePopupShowing () ) {
116124 hideAutocompletePopup ();
117125 }
118126
119- searchAndReplacePopOver .hide ();
120-
127+ if (isSearchInFilesPopOverShowing ()) {
128+ searchInFilesPopOver .hide ();
129+ }
130+
131+ if (isSearchAndReplacePopOverShowing ()) {
132+ searchAndReplacePopOver .hide ();
133+ }
134+
121135 if (goToLinePopOver != null ) {
122136 goToLinePopOver .hide ();
123137 }
@@ -218,11 +232,15 @@ public void setInputMap() {
218232 action -> this .replaceSelection ("(" + getSelectedText () + ")" ));
219233
220234
235+ var searchInFiles = InputMap .consume (
236+ EventPattern .keyPressed (KeyCode .H , KeyCombination .CONTROL_DOWN , KeyCombination .SHIFT_DOWN ),
237+ action -> this .showSearchInFilesPopup ());
221238
222239 Nodes .addFallbackInputMap (this , addTabs );
223240 Nodes .addFallbackInputMap (this , removeTabs );
224241 Nodes .addInputMap (this , autocomplete );
225242 Nodes .addInputMap (this , searchAndReplace );
243+ Nodes .addInputMap (this , searchInFiles );
226244 Nodes .addInputMap (this , delete );
227245 Nodes .addInputMap (this , toUpper );
228246 Nodes .addInputMap (this , toLower );
@@ -293,6 +311,9 @@ public void enableHighlighting() {
293311 }
294312
295313 protected void showSearchAndReplacePopup () {
314+ if (searchAndReplacePopOver == null ) {
315+ searchAndReplacePopOver = new SearchAndReplacePopOver (this );
316+ }
296317 if (!this .getSelectedText ().isEmpty ()) {
297318 searchAndReplacePopOver .getFindField ().setText (this .getSelectedText ());
298319 searchAndReplacePopOver .getFindField ().selectAll ();
@@ -301,6 +322,14 @@ protected void showSearchAndReplacePopup() {
301322 searchAndReplacePopOver .getFindField ().requestFocus ();
302323 searchAndReplacePopOver .show (getParent (), boundsInScene .getMaxX () - 400 , boundsInScene .getMinY ());
303324 }
325+
326+ protected void showSearchInFilesPopup () {
327+ var boundsInScene = this .localToScreen (this .getBoundsInLocal ());
328+ if (this .searchInFilesPopOver == null ) {
329+ this .searchInFilesPopOver = new SearchInFilesPopOver ();
330+ }
331+ this .searchInFilesPopOver .show (getParent (), boundsInScene .getMinX (), boundsInScene .getMinY ());
332+ }
304333
305334 // FIXME: we override copy method as it the default method seems broken for strings containing '{' or '}'
306335 @ Override
@@ -333,6 +362,9 @@ public ContextMenu createContextMenu() {
333362
334363 var menuItemSearchAndReplace = new MenuItem ("Search..." , JavaFXUtils .createIcon ("/icons/magnify.png" ));
335364 menuItemSearchAndReplace .setOnAction (action -> this .showSearchAndReplacePopup ());
365+
366+ var menuItemSearchInFiles = new MenuItem ("Search In Files..." , JavaFXUtils .createIcon ("/icons/magnify.png" ));
367+ menuItemSearchInFiles .setOnAction (action -> this .showSearchInFilesPopup ());
336368
337369 var menuItemUperCase = new MenuItem ("To Upper Case" , JavaFXUtils .createIcon ("/icons/uppercase.png" ));
338370 menuItemUperCase .setOnAction (action -> this .convertSelectedTextToUpperCase ());
@@ -386,7 +418,7 @@ public ContextMenu createContextMenu() {
386418 new SeparatorMenuItem (),
387419 menuItemFormat , menuItemFormat3 ,
388420 new SeparatorMenuItem (),
389- menuItemSearchAndReplace , menuItemGoToLine , menuItemSuggestions ,
421+ menuItemSearchAndReplace , menuItemSearchInFiles , menuItemGoToLine , menuItemSuggestions ,
390422 new SeparatorMenuItem (),
391423 menuItemSaveAs );
392424 return menu ;
@@ -526,15 +558,13 @@ protected void showSuggestionsList(List<Keyword> suggestions, String query, int
526558 return ;
527559 }
528560
529- autoCompletePopup .getContent ().setAll (suggestionsList );
530561 this .setOnSuggestionListKeyPressed (suggestionsList , query , caretPosition );
531562 this .showAutoCompletePopup ();
532563 }
533564
534565 protected void hideAutocompletePopup () {
535- if (autoCompletePopup != null && autoCompletePopupShowing ) {
566+ if (isAutoCompletePopupShowing () ) {
536567 autoCompletePopup .hide ();
537- autoCompletePopupShowing = false ;
538568 }
539569 }
540570
@@ -581,20 +611,21 @@ protected void listViewOnEnterAction(ListView<Keyword> suggestionsList, final St
581611 }
582612
583613 protected void showAutoCompletePopup () {
614+ if (autoCompletePopup == null ) {
615+ autoCompletePopup = this .createAutoCompletePopup ();
616+ }
617+
618+ autoCompletePopup .getContent ().setAll (suggestionsList );
619+
584620 var pointer = this .caretBoundsProperty ().getValue ().get ();
585- if (!autoCompletePopupShowing ) {
621+ if (!isAutoCompletePopupShowing () ) {
586622 autoCompletePopup .show (this , pointer .getMaxX (), pointer .getMinY () + Y_OFFSET );
587- autoCompletePopupShowing = true ;
588623 }
589624 }
590625
591626 protected Popup createAutoCompletePopup () {
592- if (autoCompletePopup != null )
593- return autoCompletePopup ;
594-
595627 var popup = new Popup ();
596628 popup .setAutoHide (true );
597- popup .setOnAutoHide (event -> autoCompletePopupShowing = false );
598629 return popup ;
599630 }
600631
0 commit comments