Skip to content

Commit

Permalink
添加配置重置功能
Browse files Browse the repository at this point in the history
  • Loading branch information
makejavas committed Jul 27, 2018
1 parent aa80cc8 commit 5d98c0d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/sjhy/plugin/tool/ConfigInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ConfigInfo() {
/**
* 初始化默认设置
*/
private void initDefault() {
public void initDefault() {
// 版本号
this.version = "1.1.0";
// 默认编码
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/com/sjhy/plugin/ui/MainSetting.form
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.sjhy.plugin.ui.MainSetting">
<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">
<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">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="0" y="1" width="606" height="499"/>
Expand Down Expand Up @@ -44,19 +44,32 @@
</component>
<vspacer id="fd955">
<constraints>
<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"/>
<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"/>
</constraints>
</vspacer>
<component id="94649" class="javax.swing.JTextField" binding="authorTextField">
<constraints>
<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">
<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">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="49eb5" class="javax.swing.JButton" binding="resetBtn">
<constraints>
<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"/>
</constraints>
<properties>
<text resource-bundle="string" key="button.reset"/>
</properties>
</component>
<hspacer id="fefd">
<constraints>
<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"/>
</constraints>
</hspacer>
</children>
</grid>
</form>
53 changes: 53 additions & 0 deletions src/main/java/com/sjhy/plugin/ui/MainSetting.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.sjhy.plugin.ui;

import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.sjhy.plugin.comm.AbstractService;
import com.sjhy.plugin.tool.CollectionUtil;
import com.sjhy.plugin.tool.ConfigInfo;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
* 主设置面板
Expand All @@ -29,12 +34,51 @@ public class MainSetting extends AbstractService implements Configurable, Config
* 作者编辑框
*/
private JTextField authorTextField;
/**
* 重置默认设置按钮
*/
private JButton resetBtn;

/**
* 重置列表
*/
private List<Configurable> resetList;

/**
* 需要保存的列表
*/
private List<Configurable> saveList;

/**
* 默认构造方法
*/
public MainSetting() {
init();

//初始化事件
ConfigInfo configInfo = ConfigInfo.getInstance();
//重置配置信息
resetBtn.addActionListener(e -> {
int result = JOptionPane.showConfirmDialog(null, "确认重置默认配置?\n重置默认配置只会还原插件自带分组配置信息,不会删除用户新增分组信息。", "Title Info", JOptionPane.OK_CANCEL_OPTION);
if (JOptionPane.YES_OPTION == result) {
if (CollectionUtil.isEmpty(resetList)) {
return;
}
// 初始化默认配置
configInfo.initDefault();
resetList.forEach(UnnamedConfigurable::reset);
if (CollectionUtil.isEmpty(saveList)) {
return;
}
saveList.forEach(configurable -> {
try {
configurable.apply();
} catch (ConfigurationException e1) {
e1.printStackTrace();
}
});
}
});
}

/**
Expand Down Expand Up @@ -70,6 +114,15 @@ public Configurable[] getConfigurables() {
result[1] = new TemplateSettingPanel();
result[2] = new TableSettingPanel();
result[3] = new GlobalConfigSettingPanel();
// 需要重置的列表
resetList = new ArrayList<>();
resetList.add(result[0]);
resetList.add(result[1]);
resetList.add(result[3]);
// 不需要重置的列表
saveList = new ArrayList<>();
saveList.add(this);
saveList.add(result[2]);
return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/string.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
button.reset=\u91CD\u7F6E\u9ED8\u8BA4\u8BBE\u7F6E
button.type.mapper.copy.group=Copy Group
label.all=&All
label.author.name=&\u4F5C\u8005\u540D\u79F0\uFF1A
Expand Down

0 comments on commit 5d98c0d

Please sign in to comment.