本文整理汇总了Java中com.intellij.ide.fileTemplates.FileTemplateManager.getAllTemplates方法的典型用法代码示例。如果您正苦于以下问题:Java FileTemplateManager.getAllTemplates方法的具体用法?Java FileTemplateManager.getAllTemplates怎么用?Java FileTemplateManager.getAllTemplates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.ide.fileTemplates.FileTemplateManager
的用法示例。
在下文中一共展示了FileTemplateManager.getAllTemplates方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllFileTemplatesVariables
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
public Set<String> getAllFileTemplatesVariables() {
Set<String> result = new TreeSet<String>();
List<FileTemplate> allTemplates = new ArrayList<FileTemplate>();
FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance();
FileTemplate[] templates = fileTemplateManager.getAllTemplates();
FileTemplate[] patterns = fileTemplateManager.getAllPatterns();
FileTemplate[] codeTemplates = fileTemplateManager.getAllCodeTemplates();
FileTemplate[] j2eeTemplates = fileTemplateManager.getAllJ2eeTemplates();
allTemplates.addAll(Arrays.asList(templates));
allTemplates.addAll(Arrays.asList(codeTemplates));
allTemplates.addAll(Arrays.asList(j2eeTemplates));
allTemplates.addAll(Arrays.asList(patterns));
for (FileTemplate template : allTemplates) {
try {
String[] variables = FileTemplateUtil.calculateAttributes(template.getText(), new Properties(), true, myProject);
result.addAll(Arrays.asList(variables));
} catch (ParseException e) {
logger.warn("Parsing exception", e);
}
}
return result;
}
示例2: doRunInWrite
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
private void doRunInWrite() {
String text = FileReaderUtil.readFile(fileFrom);
if (text == null) {
ReportHelper.setState(ExecutionState.FAILED);
ReportHelper.putReport(new FailedActionReport(this, Localizer.get("error.ReadFileContent"), "FileReaderUtil.readFile return null"));
return;
}
FileTemplateManager ftm = FileTemplateHelper.getManagerInstance(project);
FileTemplate oldTemplate = ftm.getTemplate(StringTools.getNameWithoutExtension(fileFrom.getName()));
if (oldTemplate != null) {
ftm.removeTemplate(oldTemplate);
// ftm.saveAllTemplates();
}
FileTemplate[] templates = ftm.getAllTemplates();
FileTemplate template = FileTemplateUtil.createTemplate(
StringTools.getNameWithoutExtension(fileFrom.getName()),
StringTools.getExtensionFromName(fileFrom.getName()),
text, templates
);
ftm.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(ArrayUtil.append(templates, template)));
ReportHelper.putReport(new SuccessActionReport(this, toString()));
}
示例3: actionPerformed
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e){
Project project = assertNotNull(e.getData(CommonDataKeys.PROJECT));
String fileText = assertNotNull(e.getData(PlatformDataKeys.FILE_TEXT));
VirtualFile file = assertNotNull(e.getData(CommonDataKeys.VIRTUAL_FILE));
String extension = assertNotNull(file.getExtension());
String nameWithoutExtension = file.getNameWithoutExtension();
PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
for(SaveFileAsTemplateHandler handler: Extensions.getExtensions(SaveFileAsTemplateHandler.EP_NAME)) {
String textFromHandler = handler.getTemplateText(psiFile, fileText, nameWithoutExtension);
if (textFromHandler != null) {
fileText = textFromHandler;
break;
}
}
FileTemplateManager templateManager = FileTemplateManager.getInstance(project);
FileTemplate[] templates = templateManager.getAllTemplates();
FileTemplate template = FileTemplateUtil.createTemplate(nameWithoutExtension, extension, fileText, templates);
FileTemplateConfigurable configurable = new FileTemplateConfigurable(project);
configurable.setProportion(0.6f);
configurable.setTemplate(template, FileTemplateManagerImpl.getInstanceImpl(project).getDefaultTemplateDescription());
SaveFileAsTemplateDialog dialog = new SaveFileAsTemplateDialog(project, configurable);
if (dialog.showAndGet()) {
templateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(ArrayUtil.append(templates, template)));
}
}