55import java .util .ArrayList ;
66import java .util .concurrent .Executors ;
77import java .util .concurrent .ScheduledExecutorService ;
8- import java .util .concurrent .TimeUnit ;
98import java .util .regex .Pattern ;
109
1110import org .fxmisc .flowless .VirtualizedScrollPane ;
1211import org .fxmisc .richtext .CodeArea ;
1312
13+ import gr .sqlbrowserfx .SqlBrowserFXAppManager ;
1414import gr .sqlbrowserfx .nodes .codeareas .FileCodeArea ;
1515import gr .sqlbrowserfx .nodes .codeareas .SimpleFileCodeArea ;
1616import gr .sqlbrowserfx .nodes .codeareas .java .FileJavaCodeArea ;
2525import javafx .application .Platform ;
2626import javafx .beans .property .SimpleStringProperty ;
2727import javafx .collections .FXCollections ;
28+ import javafx .geometry .Insets ;
2829import javafx .geometry .Orientation ;
2930import javafx .scene .control .Button ;
3031import javafx .scene .control .CheckBox ;
@@ -67,7 +68,7 @@ public class SearchInFilesPopOver extends CustomPopOver {
6768 public SearchInFilesPopOver () {
6869 var fileSearchBox = this .createFileSearchBox ();
6970 var linesListBox = this .createLinesListBox ();
70- var hSplit = new SplitPane (fileSearchBox , new CustomVBox ( new Label ( "Lines Matches" ), linesListBox ) );
71+ var hSplit = new SplitPane (fileSearchBox , linesListBox );
7172 hSplit .setOrientation (Orientation .HORIZONTAL );
7273 hSplit .setDividerPositions (0.7f , 0.3f );
7374
@@ -77,7 +78,7 @@ public SearchInFilesPopOver() {
7778
7879 var borderPane = new BorderPane (vSplit );
7980 this .setContentNode (borderPane );
80- this .setPrefSize ( 1000 , 800 );
81+ this .setMaxSize ( 1280 , 720 );
8182 this .setHideOnEscape (true );
8283 this .setOnShowing (event -> {
8384 PropertiesLoader .loadProperties ();
@@ -118,7 +119,11 @@ private VBox createLinesListBox() {
118119 selectLineMatch (linesListView .getSelectionModel ().getSelectedItem ());
119120 });
120121
121- return new VBox (new CustomHBox (prevBtn , nextBtn ), linesListView );
122+ var label = new Label ("Lines Matches" );
123+ label .setPadding (new Insets (3 , 0 , 3 , 0 ));
124+ var vbox = new CustomVBox (label , new CustomHBox (prevBtn , nextBtn ), linesListView );
125+ linesListView .prefHeightProperty ().bind (filesTableView .heightProperty ());
126+ return vbox ;
122127 }
123128
124129 private VBox createFileSearchBox () {
@@ -244,22 +249,18 @@ private void createFilesTableView() {
244249 }
245250 });
246251
247- var openInVSCode = new MenuItem ("Open in VS Code" , JavaFXUtils .createIcon ("/icons/code-file.png" ));
248- openInVSCode .setOnAction (e -> {
249- var selected = filesTableView .getSelectionModel ().getSelectedItem ();
250- if (selected != null ) {
251- openInVSCode (selected .getAbsolutePath (), false );
252- }
253- });
254- var openInActiveVSCode = new MenuItem ("Open in Active VS Code" , JavaFXUtils .createIcon ("/icons/code-file.png" ));
255- openInActiveVSCode .setOnAction (e -> {
252+ var openFile = new MenuItem ("Open File" , JavaFXUtils .createIcon ("/icons/code-file.png" ));
253+ openFile .setOnAction (e -> {
256254 var selected = filesTableView .getSelectionModel ().getSelectedItem ();
257255 if (selected != null ) {
258- openInVSCode (selected .getAbsolutePath (), true );
256+ var filesTabPane = SqlBrowserFXAppManager .getFirstActiveFilesTabPane ();
257+ if (filesTabPane != null ) {
258+ filesTabPane .openNewFileTab (new File (selected .getAbsolutePath ()));
259+ }
259260 }
260261 });
261262
262- filesTableView .setContextMenu (new ContextMenu (menuItemCopy , openInVSCode , openInActiveVSCode ));
263+ filesTableView .setContextMenu (new ContextMenu (menuItemCopy , openFile ));
263264 }
264265
265266 private void selectFile () {
@@ -274,16 +275,16 @@ private void selectFile() {
274275
275276 private void selectLineMatch (LineMatch selectedItem ) {
276277 if (selectedItem == null ) {
277- return ;
278+ return ;
278279 }
279- int line = selectedItem .getLineNumber () - 1 ; // CodeArea lines are 0-based
280- int position = codeArea .position (line , 0 ).toOffset ();
281- codeArea .moveTo (position );
280+ int line = selectedItem .getLineNumber () - 1 ; // CodeArea lines are 0-based
281+ int position = codeArea .position (line , 0 ).toOffset ();
282+ codeArea .moveTo (position );
282283
283- int lineEnd = codeArea .position (line + 1 , 0 ).toOffset ();
284- codeArea .selectRange (position , lineEnd );
285-
286- codeArea .requestFollowCaret ( );
284+ int lineEnd = codeArea .position (line + 1 , 0 ).toOffset ();
285+ codeArea .selectRange (position , lineEnd );
286+
287+ codeArea .showParagraphAtCenter ( line );
287288 }
288289
289290
@@ -354,15 +355,17 @@ private void search() {
354355 final var finalPattern = pattern ;
355356 final var extension = extensionField .getText ();
356357
357- executor .schedule (() -> {
358+ executor .shutdownNow ();
359+ executor = Executors .newSingleThreadScheduledExecutor ();
360+ executor .execute (() -> {
358361 var searchResults = FilesUtils .walkContentsWithLines (rootPath , finalPattern , extension , 10 );
359362
360363 Platform .runLater (() -> {
361364 filesTableView .setItems (FXCollections .observableArrayList (searchResults ));
362365 searchField .setDisable (false );
363366 filesTableView .setDisable (false );
364367 });
365- }, 0 , TimeUnit . SECONDS );
368+ });
366369 }
367370
368371}
0 commit comments