4848
4949public class SearchInFilesPopOver extends CustomPopOver {
5050
51- private String rootPath = ((String ) PropertiesLoader .getProperty ("sqlbrowserfx.root.path" , String .class , "~/" ))
52- .replaceAll ("\" " , "" );
51+ private String rootPath = "~/" ;
5352
5453 private CodeArea codeArea = new CodeArea ();
5554 TextField searchField ;
@@ -62,9 +61,10 @@ public class SearchInFilesPopOver extends CustomPopOver {
6261
6362 private ScheduledExecutorService executor = Executors .newSingleThreadScheduledExecutor ();
6463
64+ private Label descLabel ;
65+
6566
6667 public SearchInFilesPopOver () {
67-
6868 var fileSearchBox = this .createFileSearchBox ();
6969 var linesListBox = this .createLinesListBox ();
7070 var hSplit = new SplitPane (fileSearchBox , new CustomVBox (new Label ("Lines Matches" ),linesListBox ));
@@ -78,13 +78,18 @@ public SearchInFilesPopOver() {
7878 var borderPane = new BorderPane (vSplit );
7979 this .setContentNode (borderPane );
8080 this .setPrefSize (1000 , 800 );
81- // Add ESC key handler to close the stage
82- borderPane .setOnKeyPressed (event -> {
83- if (event .getCode () == KeyCode .ESCAPE ) {
84- PropertiesLoader .storeProperty ("./sqlbrowserfx.properties" , "sqlbrowserfx.root.path" , this .rootPath );
85- this .hide ();
86- }
87- });
81+ this .setHideOnEscape (true );
82+ this .setOnShowing (event -> {
83+ PropertiesLoader .loadProperties ();
84+ rootPath = ((String ) PropertiesLoader .getProperty ("sqlbrowserfx.root.path" , String .class , "~/" ))
85+ .replaceAll ("\" " , "" );
86+ this .descLabel .setText ("File Search in: " + rootPath );
87+ });
88+ this .setOnHidden (event -> {
89+ if (executor != null ) {
90+ executor .shutdownNow ();
91+ }
92+ });
8893 }
8994
9095
@@ -142,17 +147,18 @@ private VBox createFileSearchBox() {
142147 caseInsensitiveCheckBox .setTooltip (new Tooltip ("Case Insensitive" ));
143148 caseInsensitiveCheckBox .setFocusTraversable (false );
144149
145- var descLabel = new Label ("File Search in: " + rootPath );
150+ descLabel = new Label ("File Search in: " + rootPath );
146151
147152 var settingsButton = new Button ("" , JavaFXUtils .createIcon ("/icons/settings.png" ));
148153 settingsButton .setOnMouseClicked (event -> {
149154 var dirChooser = new DirectoryChooser ();
150- File initialDir = new File (this .rootPath );
155+ var initialDir = new File (this .rootPath );
151156 dirChooser .setInitialDirectory (initialDir );
152- var selectedDir = dirChooser .showDialog (vbox . getScene (). getWindow ());
157+ var selectedDir = dirChooser .showDialog (this . getOwnerWindow ());
153158 if (selectedDir != null ) {
154159 this .rootPath = selectedDir .getAbsolutePath ();
155160 descLabel .setText ("File Search in: " + rootPath );
161+ PropertiesLoader .storeProperty ("./sqlbrowserfx.properties" , "sqlbrowserfx.root.path" , this .rootPath );
156162 }
157163 });
158164 settingsButton .setTooltip (new Tooltip ("Click to change root path" ));
0 commit comments