Skip to content

Commit a3644cc

Browse files
author
dengzi
committed
config placeholder and file template
1 parent 6e7ae4d commit a3644cc

7 files changed

Lines changed: 305 additions & 49 deletions

File tree

src/com/dengzii/plugin/template/Config.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ object Config {
2222
private const val KEY_TEMPLATES = "KEY_TEMPLATES"
2323

2424
private val GSON = Gson()
25-
val DEFAULT_MODULE_TEMPLATE = listOf(
26-
Module.create(AucTemplate.MODULE, "feature", "com.example.feature", "Java", "Auc Feature Module"),
27-
Module.create(AucTemplate.APP, "app", "com.example.feature", "Java", "Auc App Module"),
28-
Module.create(AucTemplate.PKG, "pkg", "com.example.feature", "Java", "Auc Pkg Module"),
29-
Module.create(AucTemplate.EXPORT, "export", "com.example.feature", "Java", "Auc Export Module")
25+
26+
val DEFAULT_MODULE_TEMPLATES = listOf(
27+
Module.create(AucTemplate.MODULE, "feature", "com.example", "Java", "Auc Feature Module"),
28+
Module.create(AucTemplate.APP, "app", "com.example", "Java", "Auc App Module"),
29+
Module.create(AucTemplate.PKG, "pkg", "com.example", "Java", "Auc Pkg Module"),
30+
Module.create(AucTemplate.EXPORT, "export", "com.example", "Java", "Auc Export Module")
3031
)
3132

33+
val MODULE_BLUEPRINT =
34+
Module.create(AucTemplate.MODULE, "feature", "com.example", "Java", "Auc Feature Module")
35+
3236
fun clear() {
3337
PropertiesComponent.getInstance().unsetValue(KEY_TEMPLATES)
3438
}

src/com/dengzii/plugin/template/template/AucTemplate.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ import com.dengzii.plugin.template.model.FileTreeNode
1313

1414
object AucTemplate {
1515

16-
private val res = AucFrame {
17-
res {
18-
drawable {}
19-
layout {}
20-
values {}
21-
}
22-
}
23-
2416
private val aucFileTemplates: () -> MutableMap<String, String> = {
2517
mutableMapOf(
2618
Pair("AndroidManifest.xml", "Template AndroidManifest.xml"),
@@ -58,7 +50,7 @@ object AucTemplate {
5850
}
5951
}
6052
}
61-
include(res)
53+
include(Template.ANDROID_RES)
6254
AndroidManifest.xml
6355
}
6456
test {}
@@ -82,7 +74,7 @@ object AucTemplate {
8274
}
8375
}
8476
}
85-
include(res)
77+
include(Template.ANDROID_RES)
8678
AndroidManifest.xml
8779
}
8880
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.dengzii.plugin.template.template
2+
3+
import com.dengzii.plugin.template.model.FileTreeNode
4+
5+
/**
6+
* <pre>
7+
* author : dengzi
8+
* e-mail : denua@foxmail.com
9+
* github : https://github.com/MrDenua
10+
* time : 2020/1/14
11+
* desc :
12+
* </pre>
13+
*/
14+
object Template {
15+
16+
val ANDROID_RES = FileTreeNode {
17+
res {
18+
drawable {}
19+
layout {}
20+
values {}
21+
}
22+
}
23+
24+
val ANDROID_APP = FileTreeNode {
25+
placeholder(Placeholder.MODULE_NAME, "app")
26+
placeholder(Placeholder.PACKAGE_NAME, "com.example")
27+
28+
dir("libs")
29+
src {
30+
dir("androidTest")
31+
main {
32+
java {
33+
pkg_name {
34+
module_name {
35+
file("MainActivity.java}")
36+
}
37+
}
38+
}
39+
include(ANDROID_RES)
40+
AndroidManifest.xml
41+
}
42+
dir("test")
43+
}
44+
gitignore
45+
build.gradle
46+
proguard_rules.pro
47+
}
48+
}

src/com/dengzii/plugin/template/ui/ConfigurePanel.form

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<properties/>
1515
<border type="none"/>
1616
<children>
17-
<grid id="7bf3e" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
17+
<grid id="7bf3e" layout-manager="FlowLayout" hgap="5" vgap="0" flow-align="0">
1818
<constraints/>
1919
<properties/>
2020
<border type="none"/>
@@ -70,7 +70,9 @@
7070
</grid>
7171
<grid id="e3588" layout-manager="BorderLayout" hgap="0" vgap="0">
7272
<constraints border-constraint="Center"/>
73-
<properties/>
73+
<properties>
74+
<background color="-13355980"/>
75+
</properties>
7476
<border type="none"/>
7577
<children>
7678
<grid id="6e9e7" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -132,41 +134,23 @@
132134
<border type="empty"/>
133135
<children/>
134136
</grid>
135-
<grid id="9bfd" layout-manager="BorderLayout" hgap="0" vgap="0">
137+
<grid id="9bfd" binding="panelFileTemp" layout-manager="BorderLayout" hgap="0" vgap="0">
136138
<constraints>
137139
<tabbedpane title="File Template"/>
138140
</constraints>
139141
<properties/>
140142
<border type="none"/>
141-
<children>
142-
<component id="843ce" class="com.intellij.ui.table.JBTable" binding="JB">
143-
<constraints border-constraint="Center"/>
144-
<properties/>
145-
</component>
146-
</children>
143+
<children/>
147144
</grid>
148-
<grid id="14430" layout-manager="BorderLayout" hgap="0" vgap="0">
145+
<grid id="14430" binding="panelPlaceholder" layout-manager="BorderLayout" hgap="0" vgap="0">
149146
<constraints>
150147
<tabbedpane title="Placeholder"/>
151148
</constraints>
152-
<properties/>
149+
<properties>
150+
<background color="-12828863"/>
151+
</properties>
153152
<border type="none"/>
154-
<children>
155-
<scrollpane id="c88a5">
156-
<constraints border-constraint="Center"/>
157-
<properties/>
158-
<border type="none"/>
159-
<children>
160-
<component id="61461" class="javax.swing.JTextArea" binding="taPlaceholder">
161-
<constraints/>
162-
<properties>
163-
<margin top="6" left="6" bottom="6" right="6"/>
164-
<text value=""/>
165-
</properties>
166-
</component>
167-
</children>
168-
</scrollpane>
169-
</children>
153+
<children/>
170154
</grid>
171155
</children>
172156
</tabbedpane>

src/com/dengzii/plugin/template/ui/ConfigurePanel.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import com.dengzii.plugin.template.template.AucTemplate;
66
import com.intellij.icons.AllIcons;
77
import com.intellij.openapi.options.SearchableConfigurable;
8-
import com.intellij.openapi.roots.ui.componentsList.components.ScrollablePanel;
98
import com.intellij.ui.DocumentAdapter;
109
import com.intellij.ui.components.JBList;
11-
import com.intellij.ui.table.JBTable;
1210
import org.jetbrains.annotations.Nls;
1311
import org.jetbrains.annotations.NotNull;
1412
import org.jetbrains.annotations.Nullable;
@@ -35,11 +33,11 @@ public class ConfigurePanel extends JPanel implements SearchableConfigurable {
3533
private JButton btRemove;
3634
private JButton btCopy;
3735

38-
private JTextArea taPlaceholder;
3936
private JTextField tfName;
40-
private JBTable JB;
4137
private JBList listTemplate;
4238
private JPanel panelStructure;
39+
private JPanel panelPlaceholder;
40+
private JPanel panelFileTemp;
4341

4442
private List<Module> configs;
4543
private DefaultListModel<String> model;
@@ -49,10 +47,23 @@ public class ConfigurePanel extends JPanel implements SearchableConfigurable {
4947
private ConfigurePanel panel;
5048
private PreviewPanel previewPanel;
5149

50+
private EditableTable tablePlaceholder;
51+
private EditableTable tableFileTemp;
52+
5253
private ConfigurePanel() {
54+
55+
initComponent();
56+
initPanel();
57+
}
58+
59+
private void initComponent() {
5360
setLayout(new BorderLayout());
5461
add(contentPane);
55-
initPanel();
62+
63+
tablePlaceholder = new EditableTable(new String[]{"Placeholder", "Default Value"});
64+
tableFileTemp = new EditableTable(new String[]{"FileName", "Template"});
65+
panelPlaceholder.add(tablePlaceholder, BorderLayout.CENTER);
66+
panelFileTemp.add(tableFileTemp, BorderLayout.CENTER);
5667
}
5768

5869
@Override
@@ -61,6 +72,7 @@ public void apply() {
6172
panel.apply();
6273
return;
6374
}
75+
cacheConfig();
6476
Config.INSTANCE.saveModuleTemplates(configs);
6577
}
6678

@@ -79,13 +91,13 @@ public JComponent createComponent() {
7991

8092
@Override
8193
public boolean isModified() {
82-
return true;//currentConfig != null && !tfName.getText().equals(currentConfig.getTemplateName());
94+
return true;
8395
}
8496

8597
@Nls(capitalization = Nls.Capitalization.Title)
8698
@Override
8799
public String getDisplayName() {
88-
return "Module Template Generator";
100+
return "Directory Template";
89101
}
90102

91103
private void onAdd() {
@@ -130,9 +142,21 @@ private void onTemplateSelect(int index) {
130142
if (currentConfig == configs.get(index)) {
131143
return;
132144
}
145+
if (currentConfig != null) {
146+
cacheConfig();
147+
}
133148
currentConfig = configs.get(index);
134149
tfName.setText(currentConfig.getTemplateName());
135150
previewPanel.setModuleConfig(currentConfig);
151+
152+
// update file template and placeholder table
153+
tableFileTemp.setPairData(currentConfig.getTemplate().getFileTemplates());
154+
tablePlaceholder.setPairData(currentConfig.getTemplate().getPlaceHolderMap());
155+
}
156+
157+
private void cacheConfig() {
158+
currentConfig.getTemplate().setFileTemplates(tableFileTemp.getPairResult());
159+
currentConfig.getTemplate().setPlaceHolderMap(tablePlaceholder.getPairResult());
136160
}
137161

138162
private void initPanel() {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.dengzii.plugin.template.ui
2+
3+
import com.intellij.icons.AllIcons
4+
import com.intellij.util.ui.JBEmptyBorder
5+
import java.awt.Dimension
6+
import java.awt.FlowLayout
7+
import java.awt.event.ActionEvent
8+
import javax.swing.Icon
9+
import javax.swing.JButton
10+
import javax.swing.JPanel
11+
12+
/**
13+
* <pre>
14+
* author : dengzi
15+
* e-mail : denua@foxmail.com
16+
* github : https://github.com/MrDenua
17+
* time : 2020/1/14
18+
* desc :
19+
* </pre>
20+
*/
21+
class EditToolbar : JPanel() {
22+
23+
private val btAdd = JButton("Add")
24+
private val btRemove = JButton("Remove")
25+
private val btCopy = JButton("Copy")
26+
27+
init {
28+
initLayout()
29+
initButton()
30+
}
31+
32+
fun onAdd(listener: (e: ActionEvent) -> Unit) {
33+
btAdd.addActionListener(listener)
34+
}
35+
36+
fun onRemove(listener: (e: ActionEvent) -> Unit) {
37+
btRemove.addActionListener(listener)
38+
}
39+
40+
fun onCopy(listener: (e: ActionEvent) -> Unit) {
41+
btCopy.addActionListener(listener)
42+
}
43+
44+
private fun initLayout() {
45+
46+
val flowLayout = FlowLayout()
47+
flowLayout.vgap = 0
48+
flowLayout.hgap = 5
49+
flowLayout.alignment = FlowLayout.LEFT
50+
layout = flowLayout
51+
border = JBEmptyBorder(0, 0, 0, 0)
52+
}
53+
54+
private fun initButton() {
55+
setIconButton(btAdd, AllIcons.General.Add)
56+
setIconButton(btRemove, AllIcons.General.Remove)
57+
setIconButton(btCopy, AllIcons.General.CopyHovered)
58+
}
59+
60+
private fun setIconButton(button: JButton, icon: Icon) {
61+
add(button)
62+
button.toolTipText = button.text
63+
button.icon = icon
64+
button.text = ""
65+
button.preferredSize = Dimension(25, 25)
66+
}
67+
68+
}

0 commit comments

Comments
 (0)