2323import javafx .beans .binding .Bindings ;
2424import javafx .beans .property .BooleanProperty ;
2525import javafx .beans .property .ObjectProperty ;
26+ import javafx .beans .property .SimpleBooleanProperty ;
2627import javafx .collections .ListChangeListener ;
2728import javafx .css .PseudoClass ;
2829import javafx .geometry .Insets ;
@@ -88,10 +89,10 @@ final class ModListPageSkin extends SkinBase<ModListPage> {
8889 private final HBox toolbarSelecting ;
8990
9091 private final JFXListView <ModInfoObject > listView ;
91- private final JFXTextField searchField ;
9292
93- @ FXThread
94- private boolean isSearching = false ;
93+ private final BooleanProperty isSearching = new SimpleBooleanProperty (false );
94+ private final JFXTextField searchField ;
95+ private final PauseTransition searchPause = new PauseTransition (Duration .millis (100 ));
9596
9697 ModListPageSkin (ModListPage skinnable ) {
9798 super (skinnable );
@@ -118,18 +119,21 @@ final class ModListPageSkin extends SkinBase<ModListPage> {
118119 searchField = new JFXTextField ();
119120 searchField .setPromptText (i18n ("search" ));
120121 HBox .setHgrow (searchField , Priority .ALWAYS );
121- PauseTransition pause = new PauseTransition (Duration .millis (100 ));
122- pause .setOnFinished (e -> search ());
122+ searchPause .setOnFinished (e -> search ());
123123 searchField .textProperty ().addListener ((observable , oldValue , newValue ) -> {
124- pause .setRate (1 );
125- pause .playFromStart ();
124+ if (isSearching .get () || !StringUtils .isBlank (newValue )) {
125+ searchPause .setRate (1 );
126+ searchPause .playFromStart ();
127+ }
126128 });
127129
128130 JFXButton closeSearchBar = createToolbarButton2 (null , SVG .CLOSE ,
129131 () -> {
130132 changeToolbar (toolbarNormal );
131133
132- isSearching = false ;
134+ searchPause .stop ();
135+
136+ isSearching .set (false );
133137 searchField .clear ();
134138 Bindings .bindContent (listView .getItems (), getSkinnable ().getItems ());
135139 });
@@ -192,7 +196,7 @@ final class ModListPageSkin extends SkinBase<ModListPage> {
192196 FXUtils .onChangeAndOperate (listView .getSelectionModel ().selectedItemProperty (),
193197 selectedItem -> {
194198 if (selectedItem == null )
195- changeToolbar (isSearching ? searchBar : toolbarNormal );
199+ changeToolbar (isSearching . get () ? searchBar : toolbarNormal );
196200 else
197201 changeToolbar (toolbarSelecting );
198202 });
@@ -223,12 +227,22 @@ final class ModListPageSkin extends SkinBase<ModListPage> {
223227 StackPane placeholderContainer = new StackPane ();
224228 placeholderContainer .getStyleClass ().add ("notice-pane" );
225229 Label placeholderLabel = new Label (i18n ("mods.empty" ));
230+ placeholderLabel .textProperty ().bind (
231+ Bindings .createStringBinding (() -> {
232+ if (isSearching .get ()) {
233+ return i18n ("search.no_results_found" );
234+ } else {
235+ return i18n ("mods.empty" );
236+ }
237+ },
238+ isSearching )
239+ );
226240 placeholderContainer .getChildren ().add (placeholderLabel );
227241 listView .setPlaceholder (placeholderContainer );
228242
229243 Bindings .bindContent (listView .getItems (), skinnable .getItems ());
230244 skinnable .getItems ().addListener ((ListChangeListener <? super ModInfoObject >) c -> {
231- if (isSearching ) {
245+ if (isSearching . get () ) {
232246 search ();
233247 }
234248 });
@@ -271,7 +285,7 @@ private void changeToolbar(HBox newToolbar) {
271285 }
272286
273287 private void search () {
274- isSearching = true ;
288+ isSearching . set ( true ) ;
275289
276290 Bindings .unbindContent (listView .getItems (), getSkinnable ().getItems ());
277291
0 commit comments