use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class PyStudyDirectoryProjectGenerator method configureProject.
@Override
public void configureProject(@NotNull final Project project, @NotNull final VirtualFile baseDir, @NotNull PyNewProjectSettings settings, @NotNull Module module, @Nullable PyProjectSynchronizer synchronizer) {
myGenerator.generateProject(project, baseDir);
final String testHelper = "test_helper.py";
if (baseDir.findChild(testHelper) != null)
return;
final FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate("test_helper");
final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir);
if (projectDir == null)
return;
try {
FileTemplateUtil.createFromTemplate(template, testHelper, null, projectDir);
} catch (Exception exception) {
LOG.error("Can't copy test_helper.py " + exception.getMessage());
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class FTManager method updateTemplates.
public void updateTemplates(@NotNull Collection<FileTemplate> newTemplates) {
final Set<String> toDisable = new HashSet<>();
for (DefaultTemplate template : myDefaultTemplates) {
toDisable.add(template.getQualifiedName());
}
for (FileTemplate template : newTemplates) {
toDisable.remove(((FileTemplateBase) template).getQualifiedName());
}
restoreDefaults(toDisable);
for (FileTemplate template : newTemplates) {
final FileTemplateBase _template = addTemplate(template.getName(), template.getExtension());
_template.setText(template.getText());
_template.setReformatCode(template.isReformatCode());
_template.setLiveTemplateEnabled(template.isLiveTemplateEnabled());
}
saveTemplates(true);
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class FileTemplateTab method init.
public void init(FileTemplate[] templates) {
final FileTemplate oldSelection = getSelectedTemplate();
final String oldSelectionName = oldSelection != null ? ((FileTemplateBase) oldSelection).getQualifiedName() : null;
myTemplates.clear();
FileTemplate newSelection = null;
for (FileTemplate original : templates) {
final FileTemplateBase copy = (FileTemplateBase) original.clone();
if (oldSelectionName != null && oldSelectionName.equals(copy.getQualifiedName())) {
newSelection = copy;
}
myTemplates.add(copy);
}
initSelection(newSelection);
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class FileTemplateTabAsList method initSelection.
@Override
protected void initSelection(FileTemplate selection) {
myModel = new MyListModel();
myList.setModel(myModel);
for (FileTemplate template : myTemplates) {
myModel.addElement(template);
}
if (selection != null) {
selectTemplate(selection);
} else if (myList.getModel().getSize() > 0) {
myList.setSelectedIndex(0);
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class SaveProjectAsTemplateAction method getEncodedContent.
private static String getEncodedContent(VirtualFile virtualFile, Project project, Map<String, String> parameters, String fileHeaderTemplateName, boolean shouldEscape) throws IOException {
String text = VfsUtilCore.loadText(virtualFile);
final FileTemplate template = FileTemplateManager.getInstance(project).getDefaultTemplate(fileHeaderTemplateName);
final String templateText = template.getText();
final Pattern pattern = FileTemplateUtil.getTemplatePattern(template, project, new TIntObjectHashMap<>());
String result = convertTemplates(text, pattern, templateText, shouldEscape);
result = ProjectTemplateFileProcessor.encodeFile(result, virtualFile, project);
for (Map.Entry<String, String> entry : parameters.entrySet()) {
result = result.replace(entry.getKey(), "${" + entry.getValue() + "}");
}
return result;
}
Aggregations