Skip to content

Commit a97ea89

Browse files
committed
fix: ApacheVelocity not work, update ui
1 parent 1f8b927 commit a97ea89

File tree

6 files changed

+36
-15
lines changed

6 files changed

+36
-15
lines changed

resources/META-INF/plugin.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>com.dengzii.plugin.template</id>
33
<name>Generate Module From Template</name>
4-
<version>1.6.4</version>
4+
<version>1.6.5</version>
55
<vendor email="[email protected]" url="https://github.com/dengzii">dengzi</vendor>
66

77
<description><![CDATA[
@@ -14,13 +14,14 @@
1414
2. Support placeholders / ApacheVelocity template lang in file name.<br>
1515
3. Specify file templates from IDE custom/build-in templates.<br>
1616
4. Passing placeholders to file template as variables.<br>
17-
5. Output/import template file. share your template with your partner.<br>
17+
5. Export / Import template, share template by file.<br>
1818
<br>
1919
<b>Usage</b><br>
2020
1. Configure template in plugin settings: <b>File > Settings > Tools > Module Template Settings</b>.<br>
2121
2. Create directories from the 'Structure' tab, click the right mouse button to operate the file tree.<br>
2222
3. FileTree can use placeholders or ApacheVelocity template lang, the placeholder should like this -> <b>${YOUR_PLACEHOLDER_HERE}</b>.<br>
23-
4. The 'File Template' tab lists which template the specified file uses, you can also use placeholders for FileName field.<br>
23+
4. The 'File Template' tab lists which template the specified file uses, you can also use placeholders for FileName field,
24+
for same name file, you can use path to distinguish them, for example: c/x.js is match a/b/c/x.js<br>
2425
5. The 'Placeholder' tab's table defines placeholders for replacing filenames and file templates<br>
2526
More information: <a href='https://github.com/dengzii/GenerateModuleFromTemplate/blob/master/README.md'>README</a><br>
2627
<br>
@@ -42,6 +43,9 @@ Any question please <a href='https://github.com/dengzii/GenerateModuleFromTempla
4243
]]></description>
4344

4445
<change-notes><![CDATA[
46+
<b>Version 1.6.5 (2023/12/11)</b><br>
47+
1. Update: File template support match by file path.<br>
48+
2. Fix: ApacheVelocity template lang not work.<br>
4549
<b>Version 1.6.4 (2023/07/06)</b><br>
4650
1. Feature: Support ApacheVelocity in file name.<br>
4751
<br>
@@ -54,7 +58,7 @@ Any question please <a href='https://github.com/dengzii/GenerateModuleFromTempla
5458
<depends>com.intellij.modules.lang</depends>
5559

5660
<extensions defaultExtensionNs="com.intellij">
57-
<fileTemplateGroup implementation="com.dengzii.plugin.template.template.FileTemplateFactory" order="first"/>
61+
<!-- <fileTemplateGroup implementation="com.dengzii.plugin.template.template.FileTemplateFactory" order="first"/>-->
5862
<applicationConfigurable groupId="tools" displayName="Module Template Settings"
5963
id="preferences.ModuleTemplateConfig"
6064
instance="com.dengzii.plugin.template.TemplateConfigurable"/>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class FileWriteCommand(private var kit: PluginKit, private var module: Module) :
5151
}
5252
}
5353
}
54+
fileTreeNode.context = context
5455

5556
val failedList = mutableListOf<FileTreeNode>()
5657
fileTreeNode.children.forEach {

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ open class FileTreeNode() {
5050
@Transient
5151
private var module: Module? = null
5252

53+
@Transient
54+
var context: VelocityContext? = null
55+
5356
companion object {
5457

5558
private val TAG = FileTreeNode::class.java.simpleName
@@ -148,7 +151,10 @@ open class FileTreeNode() {
148151
return getRealNameInternal(velocityContext, this.name)
149152
}
150153

151-
private fun getRealNameInternal(velocityContext: VelocityContext? = null, fileName: String = this.name): String {
154+
private fun getRealNameInternal(
155+
velocityContext: VelocityContext? = getContextInherit(),
156+
fileName: String = this.name,
157+
): String {
152158
return if (isDir) {
153159
val rn = replacePlaceholder(velocityContext, fileName, getPlaceholderInherit(), false)
154160
if (getModuleInherit()?.lowercaseDir == true) rn.lowercase() else rn
@@ -197,6 +203,14 @@ open class FileTreeNode() {
197203
return nodes
198204
}
199205

206+
private fun getContextInherit(): VelocityContext? {
207+
return if (context == null) {
208+
parent?.getContextInherit()
209+
} else {
210+
context
211+
}
212+
}
213+
200214
fun getFileTemplateInherit(): MutableMap<String, String>? {
201215
return if (fileTemplates.isNullOrEmpty()) {
202216
return parent?.getFileTemplateInherit()
@@ -216,7 +230,7 @@ open class FileTreeNode() {
216230
/**
217231
* Resolve all file template file name in tree node.
218232
*/
219-
fun resolveFileTemplate(context: VelocityContext? = null) {
233+
fun resolveFileTemplate(context: VelocityContext? = getContextInherit()) {
220234
val templates = getAllTemplateMap()
221235
val placeholders = getPlaceholderInherit() ?: return
222236
if (fileTemplates != null && templates.isNotEmpty()) {
@@ -227,7 +241,7 @@ open class FileTreeNode() {
227241
}
228242
}
229243
traversal({ it, _ ->
230-
it.resolveFileTemplate()
244+
it.resolveFileTemplate(context)
231245
})
232246
}
233247

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Module(
1212
var lowercaseDir: Boolean = true,
1313
var capitalizeFile: Boolean = true,
1414
var packageNameToDir: Boolean = true,
15-
var enableApacheVelocity: Boolean = false,
15+
var enableApacheVelocity: Boolean = true,
1616
) {
1717

1818
companion object {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
<constraints/>
198198
<properties>
199199
<selected value="false"/>
200-
<text value="Replace placeholder"/>
200+
<text value="Preview Mode"/>
201201
</properties>
202202
</component>
203203
<component id="a98e" class="javax.swing.JCheckBox" binding="cbEnableVelocity">

src/com/dengzii/plugin/template/ui/RealConfigurePanel.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,19 @@ class RealConfigurePanel : ConfigurePanel() {
4040

4141
init {
4242
panelActionBar.add(ActionToolBarUtils.create("ActionBar1", listOf(
43-
ActionToolBarUtils.Action(AllIcons.General.Add) {
43+
ActionToolBarUtils.Action(AllIcons.General.Add, desc = "Create template") {
4444
onAddConfig()
4545
},
46-
ActionToolBarUtils.Action(AllIcons.General.Remove) {
46+
ActionToolBarUtils.Action(AllIcons.General.Remove, desc = "Remove selected template") {
4747
onRemoveConfig()
4848
},
49-
ActionToolBarUtils.Action(AllIcons.General.CopyHovered) {
49+
ActionToolBarUtils.Action(AllIcons.General.CopyHovered, desc = "Copy selected template") {
5050
onCopyConfig()
5151
},
52-
ActionToolBarUtils.Action(AllIcons.Actions.Download) {
52+
ActionToolBarUtils.Action(AllIcons.ToolbarDecorator.Import, desc = "Import template from file") {
53+
onImportTemplate()
54+
},
55+
ActionToolBarUtils.Action(AllIcons.Actions.MenuSaveall, desc = "Export selected template") {
5356
onExportTemplate()
5457
}
5558
)))
@@ -234,7 +237,6 @@ class RealConfigurePanel : ConfigurePanel() {
234237
private fun onAddConfig() {
235238
PopMenuUtils.create(linkedMapOf(
236239
"Empty Template" to { addModuleTemplate(getEmpty()) },
237-
"* Import From File" to { onImportTemplate() },
238240
"Android Application" to { addModuleTemplate(getAndroidApplication()) },
239241
"Android Mvp" to { addModuleTemplate(getAndroidMvp()) },
240242
"Auc Module" to { addModuleTemplate(getAucModule()) },
@@ -246,7 +248,7 @@ class RealConfigurePanel : ConfigurePanel() {
246248

247249
private fun onExportTemplate() {
248250
val descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor()
249-
descriptor.title = "Save Template to File"
251+
descriptor.title = "Save template ${currentConfig!!.templateName} to File"
250252
val vf = FileChooser.chooseFile(descriptor, project, null)
251253
if (vf != null && vf.isWritable) {
252254
val config = GSON.toJson(currentConfig)

0 commit comments

Comments
 (0)