11package com .sjhy .plugin .ui ;
22
33import com .intellij .openapi .options .Configurable ;
4+ import com .intellij .openapi .options .ConfigurationException ;
5+ import com .intellij .openapi .options .UnnamedConfigurable ;
46import com .sjhy .plugin .comm .AbstractService ;
7+ import com .sjhy .plugin .tool .CollectionUtil ;
58import com .sjhy .plugin .tool .ConfigInfo ;
69import org .jetbrains .annotations .Nls ;
710import org .jetbrains .annotations .NotNull ;
811import org .jetbrains .annotations .Nullable ;
912
1013import javax .swing .*;
14+ import java .util .ArrayList ;
15+ import java .util .List ;
1116
1217/**
1318 * 主设置面板
@@ -29,12 +34,51 @@ public class MainSetting extends AbstractService implements Configurable, Config
2934 * 作者编辑框
3035 */
3136 private JTextField authorTextField ;
37+ /**
38+ * 重置默认设置按钮
39+ */
40+ private JButton resetBtn ;
41+
42+ /**
43+ * 重置列表
44+ */
45+ private List <Configurable > resetList ;
46+
47+ /**
48+ * 需要保存的列表
49+ */
50+ private List <Configurable > saveList ;
3251
3352 /**
3453 * 默认构造方法
3554 */
3655 public MainSetting () {
3756 init ();
57+
58+ //初始化事件
59+ ConfigInfo configInfo = ConfigInfo .getInstance ();
60+ //重置配置信息
61+ resetBtn .addActionListener (e -> {
62+ int result = JOptionPane .showConfirmDialog (null , "确认重置默认配置?\n 重置默认配置只会还原插件自带分组配置信息,不会删除用户新增分组信息。" , "Title Info" , JOptionPane .OK_CANCEL_OPTION );
63+ if (JOptionPane .YES_OPTION == result ) {
64+ if (CollectionUtil .isEmpty (resetList )) {
65+ return ;
66+ }
67+ // 初始化默认配置
68+ configInfo .initDefault ();
69+ resetList .forEach (UnnamedConfigurable ::reset );
70+ if (CollectionUtil .isEmpty (saveList )) {
71+ return ;
72+ }
73+ saveList .forEach (configurable -> {
74+ try {
75+ configurable .apply ();
76+ } catch (ConfigurationException e1 ) {
77+ e1 .printStackTrace ();
78+ }
79+ });
80+ }
81+ });
3882 }
3983
4084 /**
@@ -70,6 +114,15 @@ public Configurable[] getConfigurables() {
70114 result [1 ] = new TemplateSettingPanel ();
71115 result [2 ] = new TableSettingPanel ();
72116 result [3 ] = new GlobalConfigSettingPanel ();
117+ // 需要重置的列表
118+ resetList = new ArrayList <>();
119+ resetList .add (result [0 ]);
120+ resetList .add (result [1 ]);
121+ resetList .add (result [3 ]);
122+ // 不需要重置的列表
123+ saveList = new ArrayList <>();
124+ saveList .add (this );
125+ saveList .add (result [2 ]);
73126 return result ;
74127 }
75128
0 commit comments