!1 添加列表元素顺序上下移动及主配置页中显示当前版本号

Merge pull request !1 from 熊猫大侠/master
This commit is contained in:
makejava 2019-06-03 11:27:28 +08:00 committed by Gitee
commit 49ef97aade
6 changed files with 108 additions and 11 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <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="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<xy x="0" y="1" width="606" height="499"/> <xy x="0" y="1" width="606" height="499"/>
@ -10,7 +10,7 @@
<children> <children>
<component id="c1393" class="javax.swing.JLabel"> <component id="c1393" class="javax.swing.JLabel">
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<labelFor value="3e397"/> <labelFor value="3e397"/>
@ -19,7 +19,7 @@
</component> </component>
<component id="9b299" class="javax.swing.JLabel"> <component id="9b299" class="javax.swing.JLabel">
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<labelFor value="94649"/> <labelFor value="94649"/>
@ -28,7 +28,7 @@
</component> </component>
<component id="3e397" class="javax.swing.JComboBox" binding="encodeComboBox"> <component id="3e397" class="javax.swing.JComboBox" binding="encodeComboBox">
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<model> <model>
@ -44,7 +44,7 @@
</component> </component>
<component id="94649" class="javax.swing.JTextField" binding="authorTextField"> <component id="94649" class="javax.swing.JTextField" binding="authorTextField">
<constraints> <constraints>
<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"> <grid row="2" 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"/> <preferred-size width="150" height="-1"/>
</grid> </grid>
</constraints> </constraints>
@ -54,7 +54,7 @@
</component> </component>
<component id="49eb5" class="javax.swing.JButton" binding="resetBtn"> <component id="49eb5" class="javax.swing.JButton" binding="resetBtn">
<constraints> <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"/> <grid row="1" 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> </constraints>
<properties> <properties>
<text resource-bundle="string" key="button.reset"/> <text resource-bundle="string" key="button.reset"/>
@ -62,13 +62,13 @@
</component> </component>
<hspacer id="fefd"> <hspacer id="fefd">
<constraints> <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"/> <grid row="1" 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> </constraints>
</hspacer> </hspacer>
<grid id="45da" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="45da" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="3" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
@ -101,6 +101,22 @@
</component> </component>
</children> </children>
</grid> </grid>
<component id="9a049" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.version"/>
</properties>
</component>
<component id="a9c9" class="javax.swing.JLabel" binding="versionLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children> </children>
</grid> </grid>
</form> </form>

View File

@ -62,6 +62,10 @@ public class MainSetting implements Configurable, Configurable.Composite {
* 模板导出按钮 * 模板导出按钮
*/ */
private JButton exportBtn; private JButton exportBtn;
/**
* 当前版本号
*/
private JLabel versionLabel;
/** /**
* 重置列表 * 重置列表
@ -294,6 +298,7 @@ public class MainSetting implements Configurable, Configurable.Composite {
*/ */
private void init() { private void init() {
//初始化数据 //初始化数据
versionLabel.setText(settings.getVersion());
authorTextField.setText(settings.getAuthor()); authorTextField.setText(settings.getAuthor());
encodeComboBox.setSelectedItem(settings.getEncode()); encodeComboBox.setSelectedItem(settings.getEncode());
} }

View File

@ -200,7 +200,7 @@ public class TemplateSettingPanel implements Configurable {
}; };
// 创建元素选择面板 // 创建元素选择面板
this.baseItemSelectPanel = new BaseItemSelectPanel<Template>(group.get(currGroupName).getElementList()) { this.baseItemSelectPanel = new BaseItemSelectPanel<Template>(group.get(currGroupName).getElementList(), true) {
@Override @Override
protected void addItem(String name) { protected void addItem(String name) {
List<Template> templateList = group.get(currGroupName).getElementList(); List<Template> templateList = group.get(currGroupName).getElementList();

View File

@ -34,6 +34,10 @@ public abstract class BaseItemSelectPanel<T extends Item> {
* 可选面板集合 * 可选面板集合
*/ */
private List<T> itemList; private List<T> itemList;
/**
* 列表元素是否可上下移动
*/
private boolean movable = false;
/** /**
* 左边面板 * 左边面板
@ -54,6 +58,11 @@ public abstract class BaseItemSelectPanel<T extends Item> {
this.itemList = itemList; this.itemList = itemList;
} }
protected BaseItemSelectPanel(@NotNull List<T> itemList, boolean movable) {
this.itemList = itemList;
this.movable = movable;
}
/** /**
* 新增元素 * 新增元素
* *
@ -230,6 +239,72 @@ public abstract class BaseItemSelectPanel<T extends Item> {
} }
}); });
// 如果启动顺序移动
if (isMovable()) {
// 上移事件
actionGroup.add(new AnAction(AllIcons.Actions.MoveUp) {
@Override
public void actionPerformed(AnActionEvent e) {
T selectedItem = getSelectedItem();
// 获取当前选项索引
int index = getItemList().indexOf(selectedItem);
int targetIndex = index - 1;
// 判断选项是否是不可移动情况, 已经在第一项 只有一个选项
if (index == 0 || getItemList().size() == 1) {
return;
}
T targetItem = getItemList().get(targetIndex);
getItemList().set(index, targetItem);
getItemList().set(targetIndex, selectedItem);
reset(getItemList(), targetIndex);
}
@Override
public void update(AnActionEvent e) {
boolean movable = false;
if (getSelectedItem() != null && itemList.size() > 1 && itemList.indexOf(getSelectedItem()) > 0) {
movable = true;
}
e.getPresentation().setEnabled(movable);
}
});
// 下移事件
actionGroup.add(new AnAction(AllIcons.Actions.MoveDown) {
@Override
public void actionPerformed(AnActionEvent e) {
T selectedItem = getSelectedItem();
// 获取当前选项索引
int index = getItemList().indexOf(selectedItem);
int targetIndex = index + 1;
// 判断选项是否是不可移动情况, 已经在最后一项 只有一个选项
if (index == getItemList().size() - 1 || getItemList().size() == 1) {
return;
}
T targetItem = getItemList().get(targetIndex);
getItemList().set(index, targetItem);
getItemList().set(targetIndex, selectedItem);
reset(getItemList(), targetIndex);
}
@Override
public void update(AnActionEvent e) {
boolean movable = false;
boolean isLast = itemList.size() - itemList.indexOf(getSelectedItem()) == 1;
if (getSelectedItem() != null && itemList.size() > 1 && !isLast) {
movable = true;
}
e.getPresentation().setEnabled(movable);
}
});
}
return actionGroup; return actionGroup;
} }

View File

@ -132,7 +132,7 @@
<p>More <a href="https://github.com/makejavas/EasyCode">Help Info</a>.</p> <p>More <a href="https://github.com/makejavas/EasyCode">Help Info</a>.</p>
]]></change-notes> ]]></change-notes>
<!-- please see https://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description --> <!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="172"/> <idea-version since-build="172"/>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html <!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html

View File

@ -1,6 +1,7 @@
button.reset=\u91CD\u7F6E\u9ED8\u8BA4\u8BBE\u7F6E button.reset=\u91CD\u7F6E\u9ED8\u8BA4\u8BBE\u7F6E
button.type.mapper.copy.group=Copy Group button.type.mapper.copy.group=Copy Group
label.all=&All label.all=&All
label.version=&\u5f53\u524d\u7248\u672c\uFF1A
label.author.name=&\u4F5C\u8005\u540D\u79F0\uFF1A label.author.name=&\u4F5C\u8005\u540D\u79F0\uFF1A
label.cancel=&Cancel label.cancel=&Cancel
label.choose=&Choose label.choose=&Choose