99import com .xwintop .xcore .javafx .dialog .FxAlerts ;
1010import com .xwintop .xcore .util .javafx .JavaFxViewUtil ;
1111import java .io .IOException ;
12+ import java .util .ArrayList ;
1213import java .util .HashMap ;
1314import java .util .List ;
1415import java .util .Map ;
1516import java .util .ResourceBundle ;
17+ import javafx .beans .Observable ;
1618import javafx .fxml .FXMLLoader ;
1719import javafx .scene .Parent ;
1820import javafx .scene .control .TabPane ;
21+ import javafx .scene .control .TextField ;
1922import javafx .scene .layout .VBox ;
2023import javafx .scene .web .WebView ;
2124import lombok .extern .slf4j .Slf4j ;
25+ import org .apache .commons .lang3 .StringUtils ;
2226
2327@ Slf4j
2428public class NewLauncherController {
@@ -29,26 +33,25 @@ public class NewLauncherController {
2933
3034 public TabPane tabPane ;
3135
32- public void openConfigDialog () {
33- SystemSettingService .openSystemSettings ("设置" );
34- }
36+ public TextField txtSearch ;
3537
36- public void openPluginManager () {
37- try {
38- FXMLLoader fXMLLoader = PluginManageController .getFXMLLoader ();
39- Parent root = fXMLLoader .load ();
40- JavaFxViewUtil .openNewWindow (Main .RESOURCE_BUNDLE .getString ("plugin_manage" ), root );
41- } catch (IOException e ) {
42- FxAlerts .error ("打开插件管理对话框失败" , e );
43- }
44- }
38+ // 实现搜索用
39+ private List <PluginItemController > pluginItemControllers = new ArrayList <>();
4540
4641 public void initialize () {
4742 NewLauncherService .getInstance ().setController (this );
43+ txtSearch .textProperty ().addListener (this ::onSearchKeywordChanged );
4844 loadPlugins (); // 加载插件列表到界面上
4945 startWebView .getEngine ().load (IndexController .QQ_URL ); // 额外再打开一个反馈页面,可关闭
5046 }
5147
48+ public void onSearchKeywordChanged (Observable ob , String _old , String keyword ) {
49+ boolean notSearching = StringUtils .isBlank (keyword );
50+ pluginItemControllers .forEach (itemController -> {
51+ itemController .setVisible (notSearching || itemController .matchKeyword (keyword ));
52+ });
53+ }
54+
5255 private void loadPlugins () {
5356 List <PluginJarInfo > pluginList = PluginManager .getInstance ().getPluginList ();
5457 ResourceBundle menuResourceBundle = Main .RESOURCE_BUNDLE ;
@@ -70,6 +73,10 @@ private void loadPlugins() {
7073
7174 PluginItemController item = PluginItemController .newInstance (jarInfo );
7275 category .addItem (item );
76+
77+ if (!pluginItemControllers .contains (item )) {
78+ pluginItemControllers .add (item );
79+ }
7380 }
7481 }
7582 }
@@ -81,4 +88,18 @@ private void addCategory(PluginCategoryController category) {
8188 public TabPane getTabPane () {
8289 return tabPane ;
8390 }
91+
92+ public void openConfigDialog () {
93+ SystemSettingService .openSystemSettings ("设置" );
94+ }
95+
96+ public void openPluginManager () {
97+ try {
98+ FXMLLoader fXMLLoader = PluginManageController .getFXMLLoader ();
99+ Parent root = fXMLLoader .load ();
100+ JavaFxViewUtil .openNewWindow (Main .RESOURCE_BUNDLE .getString ("plugin_manage" ), root );
101+ } catch (IOException e ) {
102+ FxAlerts .error ("打开插件管理对话框失败" , e );
103+ }
104+ }
84105}
0 commit comments