Skip to content

Commit da61364

Browse files
committed
动态获取feature id
1 parent 2563cfe commit da61364

File tree

9 files changed

+499
-33
lines changed

9 files changed

+499
-33
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,24 @@ getString(R.string.xxxx)
1717
可以通过在设置中指定xml 文件位置和feature id
1818
路径:Android Studio / Preferences / Tools / Extract To Special Xml
1919

20-
todo:
20+
可以通过指定python 的方式,动态获取feature id。标准:
21+
>可以接受一个参数,参数的内容是项目的地址\
22+
结果需要通过打印到控制台的方式返回
2123

22-
1. 通过python 或者javascript 提供自定义字符串键的功能
24+
比如:
25+
26+
```python
27+
# coding=utf-8
28+
import sys
29+
30+
from git import Repo
31+
32+
path = "."
33+
if len(sys.argv) > 1:
34+
path = sys.argv[1]
35+
repo = Repo(path)
36+
print(repo.active_branch.name)
37+
```
2338

2439
## build
2540

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'org.example'
7-
version '1.1-SNAPSHOT'
7+
version '1.2-SNAPSHOT'
88

99
repositories {
1010
mavenCentral()

src/main/java/com/fuzhengyin/string_appender/AppSettingsComponent.java

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
package com.fuzhengyin.string_appender;
44

5-
import com.intellij.ui.components.JBLabel;
65
import com.intellij.ui.components.JBTextField;
7-
import com.intellij.util.ui.FormBuilder;
86
import org.jetbrains.annotations.NotNull;
97

108
import javax.swing.*;
@@ -15,15 +13,15 @@
1513
public class AppSettingsComponent {
1614

1715
private final JPanel myMainPanel;
18-
private final JBTextField xmlPathText = new JBTextField();
19-
private final JBTextField featureIdText = new JBTextField();
16+
private final JBTextField xmlPathText;
17+
private final JBTextField featureIdText;
18+
private final AppSettingsPanel appSettingsPanel;
2019

2120
public AppSettingsComponent() {
22-
myMainPanel = FormBuilder.createFormBuilder()
23-
.addLabeledComponent(new JBLabel("xml path"), xmlPathText, 1, false)
24-
.addLabeledComponent(new JBLabel("featureId"),featureIdText, 1)
25-
.addComponentFillVertically(new JPanel(), 0)
26-
.getPanel();
21+
appSettingsPanel = new AppSettingsPanel();
22+
myMainPanel = appSettingsPanel.contentPanel;
23+
xmlPathText = appSettingsPanel.xmlPath;
24+
featureIdText = appSettingsPanel.featuredId;
2725
}
2826

2927
public JPanel getPanel() {
@@ -39,16 +37,68 @@ public String getXmlPath() {
3937
return xmlPathText.getText();
4038
}
4139

42-
public void xmlPath(@NotNull String newText) {
40+
public void setXmlPath(@NotNull String newText) {
4341
xmlPathText.setText(newText);
4442
}
4543

4644
public String getFeatureId() {
4745
return featureIdText.getText();
4846
}
4947

50-
public void featureId(String newStatus) {
48+
public void setFeatureId(String newStatus) {
5149
featureIdText.setText(newStatus);
5250
}
5351

52+
public int getMaxWordType() {
53+
return appSettingsPanel.maxWordType();
54+
}
55+
56+
public String getFeatureScriptPath() {
57+
return appSettingsPanel.featureScriptPath.getText();
58+
}
59+
60+
public int getMaxWord() {
61+
return (int) appSettingsPanel.spinnerMaxWord.getValue();
62+
}
63+
64+
public void setMaxWord(int word) {
65+
appSettingsPanel.spinnerMaxWord.setValue(word);
66+
appSettingsPanel.spinnerMaxLength.setValue(word);
67+
}
68+
69+
public void setMaxWordType(int type) {
70+
appSettingsPanel.setMaxWordType(type);
71+
}
72+
73+
public int getMaxLength() {
74+
return (int) appSettingsPanel.spinnerMaxLength.getValue();
75+
}
76+
77+
public void setMaxLength(int length) {
78+
appSettingsPanel.spinnerMaxLength.setValue(length);
79+
}
80+
81+
public int getFeatureIdType() {
82+
return appSettingsPanel.featureId();
83+
}
84+
85+
public void setFeatureIdType(int type) {
86+
appSettingsPanel.setFeatureIdType(type);
87+
}
88+
89+
public String getFeatureIdScriptPath() {
90+
return appSettingsPanel.featureScriptPath.getText();
91+
}
92+
93+
public void setFeatureIdScriptPath(String path) {
94+
appSettingsPanel.featureScriptPath.setText(path);
95+
}
96+
97+
public String getPythonPath() {
98+
return appSettingsPanel.pythonPath.getText();
99+
}
100+
101+
public void setPythonPath(String pythonPath) {
102+
appSettingsPanel.pythonPath.setText(pythonPath);
103+
}
54104
}

src/main/java/com/fuzhengyin/string_appender/AppSettingsConfigurable.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public boolean isModified() {
4141
AppSettingsState settings = AppSettingsState.getInstance();
4242
boolean modified = !mySettingsComponent.getXmlPath().equals(settings.xmlPath);
4343
modified |= !mySettingsComponent.getFeatureId().equals(settings.featureId);
44+
modified |= !mySettingsComponent.getFeatureIdScriptPath().equals(settings.featureScriptPath);
45+
modified |= mySettingsComponent.getFeatureIdType() != settings.featureProduceType;
46+
modified |= mySettingsComponent.getMaxWordType() != settings.maxWordType;
47+
modified |= mySettingsComponent.getMaxWord() != settings.maxWord;
48+
modified |= mySettingsComponent.getMaxLength() != settings.maxLength;
49+
modified |= !mySettingsComponent.getPythonPath().equals(settings.pythonPath);
4450
return modified;
4551
}
4652

@@ -49,13 +55,25 @@ public void apply() {
4955
AppSettingsState settings = AppSettingsState.getInstance();
5056
settings.xmlPath = mySettingsComponent.getXmlPath();
5157
settings.featureId = mySettingsComponent.getFeatureId();
58+
settings.featureProduceType = mySettingsComponent.getFeatureIdType();
59+
settings.featureScriptPath = mySettingsComponent.getFeatureScriptPath();
60+
settings.maxWordType = mySettingsComponent.getMaxWordType();
61+
settings.maxWord = mySettingsComponent.getMaxWord();
62+
settings.maxLength = mySettingsComponent.getMaxLength();
63+
settings.pythonPath = mySettingsComponent.getPythonPath();
5264
}
5365

5466
@Override
5567
public void reset() {
5668
AppSettingsState settings = AppSettingsState.getInstance();
57-
mySettingsComponent.xmlPath(settings.xmlPath);
58-
mySettingsComponent.featureId(settings.featureId);
69+
mySettingsComponent.setXmlPath(settings.xmlPath);
70+
mySettingsComponent.setFeatureId(settings.featureId);
71+
mySettingsComponent.setFeatureIdType(settings.featureProduceType);
72+
mySettingsComponent.setFeatureIdScriptPath(settings.featureScriptPath);
73+
mySettingsComponent.setMaxWord(settings.maxWord);
74+
mySettingsComponent.setMaxWordType(settings.maxWordType);
75+
mySettingsComponent.setMaxLength(settings.maxLength);
76+
mySettingsComponent.setPythonPath(settings.pythonPath);
5977
}
6078

6179
@Override
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.fuzhengyin.string_appender.AppSettingsPanel">
3+
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="7" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="20" y="20" width="500" height="234"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<component id="ef9b9" class="javax.swing.JLabel">
12+
<constraints>
13+
<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"/>
14+
</constraints>
15+
<properties>
16+
<text value="Xml Path"/>
17+
</properties>
18+
</component>
19+
<component id="abc3b" class="com.intellij.ui.components.JBTextField" binding="xmlPath">
20+
<constraints>
21+
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
22+
<preferred-size width="150" height="-1"/>
23+
</grid>
24+
</constraints>
25+
<properties/>
26+
</component>
27+
<component id="b3070" class="javax.swing.JLabel">
28+
<constraints>
29+
<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"/>
30+
</constraints>
31+
<properties>
32+
<text value="Feature Id"/>
33+
</properties>
34+
</component>
35+
<component id="6e9d0" class="com.intellij.ui.components.JBTextField" binding="featuredId">
36+
<constraints>
37+
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
38+
<preferred-size width="150" height="-1"/>
39+
</grid>
40+
</constraints>
41+
<properties/>
42+
</component>
43+
<component id="6daf2" class="javax.swing.JLabel">
44+
<constraints>
45+
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
46+
</constraints>
47+
<properties>
48+
<text value="restricted"/>
49+
</properties>
50+
</component>
51+
<component id="c88be" class="javax.swing.JRadioButton" binding="fixedString">
52+
<constraints>
53+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
54+
</constraints>
55+
<properties>
56+
<text value="fixed"/>
57+
</properties>
58+
</component>
59+
<component id="1a019" class="javax.swing.JTextField" binding="featureScriptPath">
60+
<constraints>
61+
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
62+
<preferred-size width="150" height="-1"/>
63+
</grid>
64+
</constraints>
65+
<properties/>
66+
</component>
67+
<component id="21604" class="javax.swing.JRadioButton" binding="scriptRadioButton" default-binding="true">
68+
<constraints>
69+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
70+
</constraints>
71+
<properties>
72+
<text value="script"/>
73+
</properties>
74+
</component>
75+
<component id="d8a96" class="javax.swing.JButton" binding="selectXmlPath">
76+
<constraints>
77+
<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"/>
78+
</constraints>
79+
<properties>
80+
<text value="select"/>
81+
</properties>
82+
</component>
83+
<component id="2401f" class="javax.swing.JButton" binding="selectScriptPath">
84+
<constraints>
85+
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
86+
</constraints>
87+
<properties>
88+
<text value="select"/>
89+
</properties>
90+
</component>
91+
<component id="b4af2" class="javax.swing.JRadioButton" binding="maxWordCountRadioButton" default-binding="true">
92+
<constraints>
93+
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
94+
</constraints>
95+
<properties>
96+
<text value="max word count"/>
97+
</properties>
98+
</component>
99+
<component id="95a87" class="javax.swing.JSpinner" binding="spinnerMaxWord">
100+
<constraints>
101+
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
102+
</constraints>
103+
<properties/>
104+
</component>
105+
<component id="78608" class="javax.swing.JSpinner" binding="spinnerMaxLength">
106+
<constraints>
107+
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
108+
</constraints>
109+
<properties/>
110+
</component>
111+
<component id="6668c" class="javax.swing.JRadioButton" binding="maxLengthRadioButton" default-binding="true">
112+
<constraints>
113+
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
114+
</constraints>
115+
<properties>
116+
<text value="max length"/>
117+
</properties>
118+
</component>
119+
<component id="f6693" class="javax.swing.JLabel">
120+
<constraints>
121+
<grid row="6" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
122+
</constraints>
123+
<properties>
124+
<text value="如果添加了限制,会在遇到限制的情况下弹窗,由用户自定义key,保持为0为默认值"/>
125+
</properties>
126+
</component>
127+
<component id="261c" class="javax.swing.JLabel">
128+
<constraints>
129+
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
130+
</constraints>
131+
<properties>
132+
<text value="python"/>
133+
</properties>
134+
</component>
135+
<component id="25e44" class="javax.swing.JTextField" binding="pythonPath">
136+
<constraints>
137+
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
138+
<preferred-size width="150" height="-1"/>
139+
</grid>
140+
</constraints>
141+
<properties/>
142+
</component>
143+
</children>
144+
</grid>
145+
<buttonGroups>
146+
<group name="featuredIdGroup">
147+
<member id="c88be"/>
148+
<member id="21604"/>
149+
</group>
150+
<group name="restrictedGroup">
151+
<member id="b4af2"/>
152+
<member id="6668c"/>
153+
</group>
154+
</buttonGroups>
155+
</form>

0 commit comments

Comments
 (0)