Skip to content

Commit 5d98c0d

Browse files
committed
添加配置重置功能
1 parent aa80cc8 commit 5d98c0d

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

src/main/java/com/sjhy/plugin/tool/ConfigInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public ConfigInfo() {
9595
/**
9696
* 初始化默认设置
9797
*/
98-
private void initDefault() {
98+
public void initDefault() {
9999
// 版本号
100100
this.version = "1.1.0";
101101
// 默认编码

src/main/java/com/sjhy/plugin/ui/MainSetting.form

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.sjhy.plugin.ui.MainSetting">
3-
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3+
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
66
<xy x="0" y="1" width="606" height="499"/>
@@ -44,19 +44,32 @@
4444
</component>
4545
<vspacer id="fd955">
4646
<constraints>
47-
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
47+
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
4848
</constraints>
4949
</vspacer>
5050
<component id="94649" class="javax.swing.JTextField" binding="authorTextField">
5151
<constraints>
52-
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
52+
<grid row="1" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
5353
<preferred-size width="150" height="-1"/>
5454
</grid>
5555
</constraints>
5656
<properties>
5757
<text value=""/>
5858
</properties>
5959
</component>
60+
<component id="49eb5" class="javax.swing.JButton" binding="resetBtn">
61+
<constraints>
62+
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
63+
</constraints>
64+
<properties>
65+
<text resource-bundle="string" key="button.reset"/>
66+
</properties>
67+
</component>
68+
<hspacer id="fefd">
69+
<constraints>
70+
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
71+
</constraints>
72+
</hspacer>
6073
</children>
6174
</grid>
6275
</form>

src/main/java/com/sjhy/plugin/ui/MainSetting.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.sjhy.plugin.ui;
22

33
import com.intellij.openapi.options.Configurable;
4+
import com.intellij.openapi.options.ConfigurationException;
5+
import com.intellij.openapi.options.UnnamedConfigurable;
46
import com.sjhy.plugin.comm.AbstractService;
7+
import com.sjhy.plugin.tool.CollectionUtil;
58
import com.sjhy.plugin.tool.ConfigInfo;
69
import org.jetbrains.annotations.Nls;
710
import org.jetbrains.annotations.NotNull;
811
import org.jetbrains.annotations.Nullable;
912

1013
import 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

src/main/resources/string.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
button.reset=\u91CD\u7F6E\u9ED8\u8BA4\u8BBE\u7F6E
12
button.type.mapper.copy.group=Copy Group
23
label.all=&All
34
label.author.name=&\u4F5C\u8005\u540D\u79F0\uFF1A

0 commit comments

Comments
 (0)