Skip to content

Commit bfd3613

Browse files
author
dengzi
committed
completion placeholder config, config dialog
1 parent 3e6ace6 commit bfd3613

7 files changed

Lines changed: 76 additions & 95 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CreateModuleAction : AnAction() {
2222
Logger.d(CreateModuleAction::class.java.simpleName, "Project is not valid.")
2323
return
2424
}
25-
CreateModuleDialog.createAndShow {
25+
CreateModuleDialog.createAndShow(kit.project) {
2626
FileWriteCommand.startAction(kit, it)
2727
}
2828
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FileWriteCommand(private var kit: PluginKit, private var module: Module) :
3838
return
3939
}
4040
val fileTreeNode = module.template
41-
Logger.d(TAG, fileTreeNode.placeHolderMap.toString())
41+
Logger.d(TAG, fileTreeNode.placeholders.toString())
4242
fileTreeNode.children.forEach {
4343
createFileTree(it, current)
4444
}
@@ -60,7 +60,7 @@ class FileWriteCommand(private var kit: PluginKit, private var module: Module) :
6060
val result = kit.createFileFromTemplate(
6161
treeNode.name,
6262
treeNode.getTemplateName()!!,
63-
treeNode.placeHolderMap.orEmpty(),
63+
treeNode.placeholders.orEmpty(),
6464
currentDirectory)
6565
if (result == null) {
6666
Logger.e(TAG, "create file from template failed, file: ${treeNode.name} template:${treeNode.getTemplateName()}")

src/com/dengzii/plugin/template/model/FileTreeNode.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ open class FileTreeNode private constructor() {
2020

2121
// the backing field is 'realName'
2222
var name: String
23-
get() = realName.replacePlaceholder(placeHolderMap)
23+
get() = realName.replacePlaceholder(placeholders)
2424
set(value) {
2525
realName = value
2626
}
@@ -33,8 +33,8 @@ open class FileTreeNode private constructor() {
3333
}
3434
get() = realChildren
3535

36-
var placeHolderMap: MutableMap<String, String>? = null
37-
get() = field ?: parent?.placeHolderMap
36+
var placeholders: MutableMap<String, String>? = null
37+
get() = field ?: parent?.placeholders
3838

3939
// template for node, higher priority than fileTemplates
4040
var template: String? = null
@@ -47,9 +47,8 @@ open class FileTreeNode private constructor() {
4747
// the origin name with original placeholder
4848
private var realName: String = ""
4949
// the label composed by 'name' and 'isDir'.
50-
private val labeledChildren = mutableMapOf<String, FileTreeNode>()
51-
@Transient
52-
var parent: FileTreeNode? = null
50+
@Transient private val labeledChildren = mutableMapOf<String, FileTreeNode>()
51+
@Transient var parent: FileTreeNode? = null
5352

5453
companion object {
5554

@@ -143,21 +142,21 @@ open class FileTreeNode private constructor() {
143142
}
144143

145144
fun placeholder(name: String, value: String) {
146-
if (this.placeHolderMap == null) {
147-
this.placeHolderMap = kotlin.collections.mutableMapOf()
145+
if (this.placeholders == null) {
146+
this.placeholders = kotlin.collections.mutableMapOf()
148147
}
149-
placeHolderMap!![name] = value
148+
placeholders!![name] = value
150149
}
151150

152151
fun placeholder(placeholder: Placeholder) {
153152
placeholder(placeholder.placeholder, placeholder.value)
154153
}
155154

156155
fun placeholders(placeholders: Map<String, String>) {
157-
if (this.placeHolderMap == null) {
158-
this.placeHolderMap = kotlin.collections.mutableMapOf()
156+
if (this.placeholders == null) {
157+
this.placeholders = kotlin.collections.mutableMapOf()
159158
}
160-
placeHolderMap!!.putAll(placeholders)
159+
this.placeholders!!.putAll(placeholders)
161160
}
162161

163162
fun filtemplates(placeholders: Map<String, String>) {
@@ -282,7 +281,7 @@ open class FileTreeNode private constructor() {
282281
fun clone(): FileTreeNode {
283282
val clone = FileTreeNode(null, name, isDir)
284283
clone.fileTemplates = fileTemplates?.toMutableMap()
285-
clone.placeHolderMap = placeHolderMap?.toMutableMap()
284+
clone.placeholders = placeholders?.toMutableMap()
286285
children.forEach {
287286
clone.addChild(it.clone())
288287
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class ConfigurePanel extends JPanel implements SearchableConfigurable {
4545
private EditableTable tablePlaceholder;
4646
private EditableTable tableFileTemp;
4747

48-
private ConfigurePanel() {
48+
public ConfigurePanel() {
4949

5050
initComponent();
5151
loadConfig();
@@ -57,8 +57,8 @@ private void initComponent() {
5757
add(contentPane);
5858

5959
panelPreview = new PreviewPanel();
60-
tablePlaceholder = new EditableTable(new String[]{"Placeholder", "Default Value"});
61-
tableFileTemp = new EditableTable(new String[]{"FileName", "Template"});
60+
tablePlaceholder = new EditableTable(new String[]{"Placeholder", "Default Value"}, new Boolean[]{true, true});
61+
tableFileTemp = new EditableTable(new String[]{"FileName", "Template"}, new Boolean[]{true, true});
6262
panelStructure.add(panelPreview);
6363
panelPlaceholder.add(tablePlaceholder, BorderLayout.CENTER);
6464
panelFileTemp.add(tableFileTemp, BorderLayout.CENTER);
@@ -148,13 +148,13 @@ private void onConfigSelect(int index) {
148148
// update tree, file template and placeholder table
149149
panelPreview.setModuleConfig(currentConfig);
150150
tableFileTemp.setPairData(currentConfig.getTemplate().getFileTemplates());
151-
tablePlaceholder.setPairData(currentConfig.getTemplate().getPlaceHolderMap());
151+
tablePlaceholder.setPairData(currentConfig.getTemplate().getPlaceholders());
152152
}
153153

154154
private void cacheConfig() {
155155
if (currentConfig == null) return;
156156
currentConfig.getTemplate().setFileTemplates(tableFileTemp.getPairResult());
157-
currentConfig.getTemplate().setPlaceHolderMap(tablePlaceholder.getPairResult());
157+
currentConfig.getTemplate().setPlaceholders(tablePlaceholder.getPairResult());
158158
}
159159

160160
private int getSelectedConfigIndex() {

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

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<properties/>
4040
<border type="empty"/>
4141
<children>
42-
<grid id="e3588" binding="mainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="14" vgap="10">
42+
<grid id="e3588" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="14" vgap="10">
4343
<margin top="10" left="26" bottom="10" right="26"/>
4444
<constraints border-constraint="Center"/>
4545
<properties>
@@ -94,100 +94,67 @@
9494
</grid>
9595
</children>
9696
</grid>
97-
<grid id="48e1c" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
97+
<grid id="1845e" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
9898
<margin top="0" left="0" bottom="0" right="0"/>
9999
<constraints>
100100
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
101101
</constraints>
102102
<properties/>
103103
<border type="empty"/>
104104
<children>
105-
<component id="2c8d4" class="javax.swing.JTextField" binding="fieldModuleName">
106-
<constraints>
107-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
108-
<preferred-size width="150" height="-1"/>
109-
</grid>
110-
</constraints>
111-
<properties>
112-
<font size="12"/>
113-
<text value="feature"/>
114-
</properties>
115-
</component>
116-
<component id="4de4" class="javax.swing.JLabel">
105+
<component id="c97b" class="javax.swing.JLabel">
117106
<constraints>
118107
<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"/>
119108
</constraints>
120109
<properties>
121110
<font size="12" style="1"/>
122-
<text value="Module Name"/>
111+
<text value="Language"/>
123112
</properties>
124113
</component>
125-
</children>
126-
</grid>
127-
<grid id="79e1e" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
128-
<margin top="0" left="0" bottom="0" right="0"/>
129-
<constraints>
130-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
131-
</constraints>
132-
<properties/>
133-
<border type="empty"/>
134-
<children>
135-
<component id="6198f" class="javax.swing.JTextField" binding="fieldPkgName">
114+
<component id="9f2f1" class="javax.swing.JComboBox" binding="cbLanguage">
136115
<constraints>
137-
<grid row="1" column="0" 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>
116+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
140117
</constraints>
141118
<properties>
142119
<font size="12"/>
143-
<text value="com.example.app"/>
144-
</properties>
145-
</component>
146-
<component id="884b" class="javax.swing.JLabel">
147-
<constraints>
148-
<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"/>
149-
</constraints>
150-
<properties>
151-
<font size="12" style="1"/>
152-
<text value="Package Name"/>
120+
<model>
121+
<item value="Kotlin"/>
122+
<item value="Java"/>
123+
</model>
153124
</properties>
154125
</component>
155126
</children>
156127
</grid>
157-
<grid id="1845e" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
128+
<grid id="d3c26" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
158129
<margin top="0" left="0" bottom="0" right="0"/>
159130
<constraints>
160-
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
131+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
161132
</constraints>
162133
<properties/>
163134
<border type="empty"/>
164135
<children>
165-
<component id="c97b" class="javax.swing.JLabel">
136+
<component id="173ba" class="javax.swing.JLabel">
166137
<constraints>
167138
<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"/>
168139
</constraints>
169140
<properties>
170141
<font size="12" style="1"/>
171-
<text value="Language"/>
142+
<text value="Placeholder"/>
172143
</properties>
173144
</component>
174-
<component id="9f2f1" class="javax.swing.JComboBox" binding="cbLanguage">
145+
<grid id="7aa5e" binding="panelPlaceholder" layout-manager="BorderLayout" hgap="0" vgap="0">
175146
<constraints>
176-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
147+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
177148
</constraints>
178-
<properties>
179-
<font size="12"/>
180-
<model>
181-
<item value="Kotlin"/>
182-
<item value="Java"/>
183-
</model>
184-
</properties>
185-
</component>
149+
<properties/>
150+
<border type="none"/>
151+
<children/>
152+
</grid>
186153
</children>
187154
</grid>
188-
<vspacer id="91596">
155+
<vspacer id="ed063">
189156
<constraints>
190-
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
157+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
191158
</constraints>
192159
</vspacer>
193160
</children>

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.dengzii.plugin.template.Config;
44
import com.dengzii.plugin.template.model.Module;
55
import com.intellij.icons.AllIcons;
6+
import com.intellij.openapi.options.ShowSettingsUtil;
7+
import com.intellij.openapi.project.Project;
68

79
import javax.swing.*;
810
import java.awt.*;
@@ -18,8 +20,6 @@ public class CreateModuleDialog extends JDialog {
1820
private JPanel rootPanel;
1921
private JLabel labelTitle;
2022
private JComboBox cbModuleType;
21-
private JTextField fieldModuleName;
22-
private JTextField fieldPkgName;
2323
private JComboBox cbLanguage;
2424
private JPanel mainPanel;
2525
private JPanel contentPanel;
@@ -28,7 +28,9 @@ public class CreateModuleDialog extends JDialog {
2828
private JButton btCancel;
2929
private JButton btPrevious;
3030
private JButton btFinish;
31+
private JPanel panelPlaceholder;
3132

33+
private EditableTable tablePlaceholder;
3234
private OnFinishListener onFinishListener;
3335

3436
private java.util.List<Module> moduleTemplates = Collections.emptyList();
@@ -40,33 +42,35 @@ public class CreateModuleDialog extends JDialog {
4042
private PreviewPanel previewPanel;
4143

4244
private int currentPanelIndex;
45+
private Project project;
4346

44-
private CreateModuleDialog(OnFinishListener onFinishListener) {
47+
private CreateModuleDialog(Project project, OnFinishListener onFinishListener) {
4548
setContentPane(rootPanel);
4649
setModal(true);
4750
getRootPane().setDefaultButton(btFinish);
48-
51+
this.project = project;
4952
this.onFinishListener = onFinishListener;
5053
}
5154

52-
public static void createAndShow(OnFinishListener onFinishListener) {
55+
public static void createAndShow(Project project, OnFinishListener onFinishListener) {
5356

54-
CreateModuleDialog dialog = new CreateModuleDialog(onFinishListener);
57+
CreateModuleDialog dialog = new CreateModuleDialog(project, onFinishListener);
5558
dialog.initDialog();
5659
dialog.initData();
5760
dialog.pack();
5861
dialog.setVisible(true);
5962
}
6063

6164
public static void main(String[] args) {
62-
createAndShow(config -> {
65+
createAndShow(null, config -> {
6366

6467
});
6568
}
6669

6770
private void onNextClick(ActionEvent e) {
71+
selectedModule.getTemplate().setFileTemplates(tablePlaceholder.getPairResult());
6872
if (currentPanelIndex == panels.size() - 1) {
69-
onFinishListener.onFinish(moduleTemplates.get(cbModuleType.getSelectedIndex()));
73+
onFinishListener.onFinish(selectedModule);
7074
dispose();
7175
return;
7276
}
@@ -85,8 +89,7 @@ private void onPreviousClick(ActionEvent e) {
8589
}
8690

8791
private void onConfClick(ActionEvent e) {
88-
setPanel();
89-
setButton();
92+
ShowSettingsUtil.getInstance().editConfigurable(project, new ConfigurePanel());
9093
}
9194

9295
private void setButton() {
@@ -104,16 +107,14 @@ private void setPanel() {
104107
labelTitle.setText(title);
105108
contentPanel.removeAll();
106109
contentPanel.add(panels.get(title));
107-
contentPanel.invalidate();
108110
contentPanel.doLayout();
109111
contentPanel.updateUI();
110112
}
111113

112-
private void onModuleConfigChange(Module module) {
113-
selectedModule = module;
114-
fieldModuleName.setText(selectedModule.getTemplateName());
115-
fieldPkgName.setText(selectedModule.getTemplateName());
114+
private void onModuleConfigChange() {
115+
selectedModule = moduleTemplates.get(cbModuleType.getSelectedIndex());
116116
previewPanel.setModuleConfig(selectedModule);
117+
tablePlaceholder.setPairData(selectedModule.getTemplate().getPlaceholders());
117118
}
118119

119120
private void initDialog() {
@@ -131,6 +132,9 @@ private void initDialog() {
131132
rootPanel.registerKeyboardAction(e -> dispose(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
132133
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
133134

135+
tablePlaceholder = new EditableTable(new String[]{"Placeholder", "Value"}, new Boolean[]{false, true});
136+
tablePlaceholder.setToolBarVisible(false);
137+
panelPlaceholder.add(tablePlaceholder, BorderLayout.CENTER);
134138
cbLanguage.setModel(new DefaultComboBoxModel<>(Module.Companion.getLangList()));
135139

136140
btConfigure.setIcon(AllIcons.General.GearPlain);
@@ -152,7 +156,7 @@ private void initDialog() {
152156
}
153157
});
154158
cbModuleType.addItemListener(e -> {
155-
onModuleConfigChange(moduleTemplates.get(cbModuleType.getSelectedIndex()));
159+
onModuleConfigChange();
156160
});
157161
}
158162

0 commit comments

Comments
 (0)