Search in sources :

Example 11 with FileTemplate

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());
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ExecutionException(com.intellij.execution.ExecutionException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 12 with FileTemplate

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);
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 13 with FileTemplate

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);
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 14 with FileTemplate

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);
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 15 with FileTemplate

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;
}
Also used : Pattern(java.util.regex.Pattern) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) Map(java.util.Map) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) HashMap(java.util.HashMap)

Aggregations

FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)66 FileTemplateManager (com.intellij.ide.fileTemplates.FileTemplateManager)20 Project (com.intellij.openapi.project.Project)13 IOException (java.io.IOException)12 PsiFile (com.intellij.psi.PsiFile)10 Properties (java.util.Properties)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 PsiDirectory (com.intellij.psi.PsiDirectory)7 NotNull (org.jetbrains.annotations.NotNull)7 PsiElement (com.intellij.psi.PsiElement)6 Module (com.intellij.openapi.module.Module)5 File (java.io.File)5 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)5 Nullable (org.jetbrains.annotations.Nullable)4 Editor (com.intellij.openapi.editor.Editor)3 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)3 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)2