11package com .xwintop .xJavaFxTool .newui ;
22
33import com .xwintop .xJavaFxTool .Main ;
4+ import com .xwintop .xJavaFxTool .controller .index .PluginManageController ;
45import com .xwintop .xJavaFxTool .model .PluginJarInfo ;
56import com .xwintop .xJavaFxTool .plugin .PluginManager ;
67import com .xwintop .xJavaFxTool .services .index .SystemSettingService ;
8+ import com .xwintop .xcore .javafx .dialog .FxAlerts ;
9+ import com .xwintop .xcore .util .javafx .JavaFxViewUtil ;
10+ import javafx .fxml .FXMLLoader ;
11+ import javafx .scene .Parent ;
712import javafx .scene .layout .VBox ;
813import lombok .extern .slf4j .Slf4j ;
914
15+ import java .io .IOException ;
16+ import java .util .HashMap ;
1017import java .util .List ;
18+ import java .util .Map ;
1119import java .util .ResourceBundle ;
1220
1321@ Slf4j
@@ -19,37 +27,46 @@ public void openConfigDialog() {
1927 SystemSettingService .openSystemSettings ("设置" );
2028 }
2129
30+ public void openPluginManager () {
31+ try {
32+ FXMLLoader fXMLLoader = PluginManageController .getFXMLLoader ();
33+ Parent root = fXMLLoader .load ();
34+ JavaFxViewUtil .openNewWindow (Main .RESOURCE_BUNDLE .getString ("plugin_manage" ), root );
35+ } catch (IOException e ) {
36+ FxAlerts .error ("打开插件管理对话框失败" , e );
37+ }
38+ }
39+
2240 public void initialize () {
2341
2442 List <PluginJarInfo > pluginList = PluginManager .getInstance ().getPluginList ();
2543 ResourceBundle menuResourceBundle = Main .RESOURCE_BUNDLE ;
2644
45+ Map <String , PluginCategoryController > categoryControllers = new HashMap <>();
46+
2747 for (PluginJarInfo jarInfo : pluginList ) {
28- String parentId = jarInfo .getMenuParentId ();
29- if (parentId .startsWith ("p-" )) {
30- parentId = parentId .substring (2 );
31- String categoryName = menuResourceBundle .getString (parentId );
32- String pluginName = jarInfo .getName ();
33- log .info ("plugin: {} - {}" , categoryName , pluginName );
34- }
35- }
48+ String menuParentTitle = jarInfo .getMenuParentTitle ();
49+ if (menuParentTitle != null ) {
3650
37- for (int i = 0 ; i < 5 ; i ++) {
38- PluginCategoryController category = PluginCategoryController .newInstance ("最近使用" );
39- addCategory (category );
51+ String categoryName = menuResourceBundle .getString (menuParentTitle );
52+ String pluginName = jarInfo .getName ();
4053
41- for (int j = 0 ; j < 10 ; j ++) {
42- PluginItemController item =
43- PluginItemController .newInstance ("临时记事本" );
54+ PluginCategoryController category = categoryControllers .computeIfAbsent (
55+ categoryName , __ -> {
56+ PluginCategoryController _category =
57+ PluginCategoryController .newInstance (categoryName );
58+ addCategory (_category );
59+ return _category ;
60+ }
61+ );
4462
63+ PluginItemController item = PluginItemController .newInstance (pluginName );
4564 category .addItem (item );
4665 }
47-
4866 }
4967 }
5068
5169 private void addCategory (PluginCategoryController category ) {
5270 this .pluginCategories .getChildren ().add (category .root );
5371 }
54-
5572}
0 commit comments