mirror of https://gitee.com/makejava/EasyCode.git
解决编辑模板无发撤销问题,添加变量名提示功能。
This commit is contained in:
parent
97a3da0197
commit
599f87942b
|
@ -42,7 +42,7 @@ intellij {
|
|||
version '2018.1.5'
|
||||
type 'IU'
|
||||
// 依赖的插件
|
||||
plugins = ['DatabaseTools']
|
||||
plugins = ['DatabaseTools', 'Velocity']
|
||||
//Disables updating since-build attribute in plugin.xml
|
||||
updateSinceUntilBuild false
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.sjhy.plugin.provider;
|
||||
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.velocity.VtlGlobalVariableProvider;
|
||||
import com.intellij.velocity.psi.VtlLightVariable;
|
||||
import com.intellij.velocity.psi.VtlVariable;
|
||||
import com.intellij.velocity.psi.files.VtlFile;
|
||||
import com.sjhy.plugin.ui.base.TemplateEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* EasyCode 专用Velocity全局变量
|
||||
*
|
||||
* @author makejava
|
||||
* @version 1.0.0
|
||||
* @since 2018/8/14 11:07
|
||||
*/
|
||||
public class EasyCodeGlobalVariableProvider extends VtlGlobalVariableProvider {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VtlVariable> getGlobalVariables(@NotNull VtlFile file) {
|
||||
// 非EasyCode模板,不提供支持。
|
||||
if (!Objects.equals(file.getName(), TemplateEditor.EASY_CODE_TEMPLATE)) {
|
||||
//noinspection unchecked
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
final List<VtlVariable> result = new ArrayList<>();
|
||||
result.add(new VtlLightVariable("author", file, CommonClassNames.JAVA_LANG_STRING));
|
||||
result.add(new VtlLightVariable("encode", file, CommonClassNames.JAVA_LANG_STRING));
|
||||
result.add(new VtlLightVariable("packageName", file, CommonClassNames.JAVA_LANG_STRING));
|
||||
result.add(new VtlLightVariable("modulePath", file, CommonClassNames.JAVA_LANG_STRING));
|
||||
result.add(new VtlLightVariable("importList", file, "java.util.Set<java.lang.String>"));
|
||||
result.add(new VtlLightVariable("callback", file, "com.sjhy.plugin.entity.Callback"));
|
||||
result.add(new VtlLightVariable("tool", file, "com.sjhy.plugin.tool.NameUtils"));
|
||||
result.add(new VtlLightVariable("time", file, "com.sjhy.plugin.tool.TimeUtils"));
|
||||
result.add(new VtlLightVariable("tableInfo", file, "com.sjhy.plugin.entity.TableInfo"));
|
||||
result.add(new VtlLightVariable("tableInfoList", file, "java.util.List<com.sjhy.plugin.entity.TableInfo>"));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.sjhy.plugin.ui.base;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
|
@ -40,6 +40,10 @@ import java.util.Objects;
|
|||
*/
|
||||
@Getter
|
||||
public class TemplateEditor {
|
||||
/**
|
||||
* EASY CODE 模板
|
||||
*/
|
||||
public static final String EASY_CODE_TEMPLATE = "EasyCodeTemplate.vm.ft";
|
||||
/**
|
||||
* 项目对象
|
||||
*/
|
||||
|
@ -104,7 +108,9 @@ public class TemplateEditor {
|
|||
editorFactory.releaseEditor(editor);
|
||||
}
|
||||
PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);
|
||||
PsiFile psiFile = psiFileFactory.createFileFromText(name, fileType, content, 0, true);
|
||||
PsiFile psiFile = psiFileFactory.createFileFromText(EASY_CODE_TEMPLATE, fileType, content, 0, true);
|
||||
// 标识为模板,让velocity跳过语法校验
|
||||
psiFile.getViewProvider().putUserData(FileTemplateManager.DEFAULT_TEMPLATE_PROPERTIES, FileTemplateManager.getInstance(project).getDefaultProperties());
|
||||
// 创建文档对象
|
||||
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
|
||||
assert document != null;
|
||||
|
|
|
@ -96,8 +96,10 @@
|
|||
<!-- uncomment to enable plugin in all products
|
||||
<depends>com.intellij.modules.lang</depends>
|
||||
-->
|
||||
<!--必须存在database插件-->
|
||||
<!--必须依赖Database Tool插件-->
|
||||
<depends>com.intellij.database</depends>
|
||||
<!--必须依赖Velocity插件-->
|
||||
<depends>com.intellij.velocity</depends>
|
||||
|
||||
<!--扩展点-->
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
|
@ -106,6 +108,8 @@
|
|||
<applicationService serviceImplementation="com.sjhy.plugin.tool.ConfigInfo"/>
|
||||
<!--系统设置面板-->
|
||||
<applicationConfigurable dynamic="true" instance="com.sjhy.plugin.ui.MainSetting"/>
|
||||
|
||||
<velocity.globalVariableProvider implementation="com.sjhy.plugin.provider.EasyCodeGlobalVariableProvider"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
|
|
Loading…
Reference in New Issue