Search in sources :

Example 16 with TemplateManager

use of com.intellij.codeInsight.template.TemplateManager in project intellij-plugins by JetBrains.

the class CreateToStringFix method processElements.

@Override
protected void processElements(@NotNull final Project project, @NotNull final Editor editor, @NotNull final Set<DartComponent> elementsToProcess) {
    final TemplateManager templateManager = TemplateManager.getInstance(project);
    anchor = doAddMethodsForOne(editor, templateManager, buildFunctionsText(templateManager, elementsToProcess), anchor);
}
Also used : TemplateManager(com.intellij.codeInsight.template.TemplateManager)

Example 17 with TemplateManager

use of com.intellij.codeInsight.template.TemplateManager in project intellij-plugins by JetBrains.

the class CreateConstructorFix method processElements.

@Override
protected void processElements(@NotNull final Project project, @NotNull final Editor editor, @NotNull final Set<DartComponent> elementsToProcess) {
    final TemplateManager templateManager = TemplateManager.getInstance(project);
    anchor = doAddMethodsForOne(editor, templateManager, buildFunctionsText(templateManager, elementsToProcess), anchor);
}
Also used : TemplateManager(com.intellij.codeInsight.template.TemplateManager)

Example 18 with TemplateManager

use of com.intellij.codeInsight.template.TemplateManager in project intellij-plugins by JetBrains.

the class AbstractStepDefinitionCreator method closeActiveTemplateBuilders.

protected void closeActiveTemplateBuilders(PsiFile file) {
    final Project project = file.getProject();
    final VirtualFile vFile = ObjectUtils.assertNotNull(file.getVirtualFile());
    final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile);
    FileEditorManager.getInstance(project).getAllEditors(vFile);
    FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
    final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    assert editor != null;
    final TemplateManager templateManager = TemplateManager.getInstance(file.getProject());
    final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
    final Template template = templateManager.getActiveTemplate(editor);
    if (templateState != null && template != null) {
        templateState.gotoEnd(false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) TemplateManager(com.intellij.codeInsight.template.TemplateManager) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) Template(com.intellij.codeInsight.template.Template)

Example 19 with TemplateManager

use of com.intellij.codeInsight.template.TemplateManager in project intellij-plugins by JetBrains.

the class CreateEventMetadataByMxmlAttributeFix method applyFix.

@Override
protected void applyFix(final Project project, final PsiElement psiElement, PsiFile file, Editor editor) {
    assert psiElement instanceof XmlAttribute;
    final XmlTag tag = (XmlTag) psiElement.getParent();
    final XmlElementDescriptor descriptor = tag.getDescriptor();
    PsiElement type = descriptor == null ? null : descriptor.getDeclaration();
    if (type == null) {
        // can not resolve
        return;
    }
    if (!FileModificationService.getInstance().preparePsiElementForWrite(type)) {
        return;
    }
    file = type.getContainingFile();
    editor = getEditor(project, file);
    if (editor == null) {
        return;
    }
    final boolean addingToMxml = type instanceof XmlFile;
    final TemplateManager templateManager = TemplateManager.getInstance(project);
    final Template template = templateManager.createTemplate("", "");
    template.setToReformat(true);
    if (addingToMxml) {
        template.addTextSegment("\n");
    }
    template.addTextSegment("[Event(name=\"" + myEventName + "\", type=\"");
    template.addVariable(new MyExpression(FlexCommonTypeNames.FLASH_EVENT_FQN), true);
    template.addTextSegment("\")]");
    if (!addingToMxml) {
        template.addTextSegment("\n");
    }
    final int offset;
    if (addingToMxml) {
        XmlTag metadataTag = WriteAction.compute(() -> createOrGetMetadataTag((XmlFile) type));
        offset = metadataTag.getValue().getTextRange().getStartOffset();
    } else {
        offset = type.getTextRange().getStartOffset();
    }
    navigate(project, editor, offset, file.getVirtualFile());
    templateManager.startTemplate(editor, template);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) TemplateManager(com.intellij.codeInsight.template.TemplateManager) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Template(com.intellij.codeInsight.template.Template)

Example 20 with TemplateManager

use of com.intellij.codeInsight.template.TemplateManager in project intellij-plugins by JetBrains.

the class GenerateFlexUnitMethodActionBase method getGenerateHandler.

protected BaseJSGenerateHandler getGenerateHandler() {
    return new BaseJSGenerateHandler() {

        protected String getTitleKey() {
            return null;
        }

        protected BaseCreateMethodsFix createFix(JSClass clazz) {
            return new BaseCreateMethodsFix(clazz) {

                public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
                    evalAnchor(editor, file);
                    final PsiElement addedElement = doAddOneMethod(project, "public function fake():void{}", anchor);
                    PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
                    final TemplateManager manager = TemplateManager.getInstance(project);
                    final Template template = manager.createTemplate("", "");
                    template.setToReformat(true);
                    buildTemplate(template, myJsClass);
                    final TextRange range = addedElement.getTextRange();
                    editor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), "");
                    editor.getCaretModel().moveToOffset(range.getStartOffset());
                    manager.startTemplate(editor, template);
                }
            };
        }

        protected boolean canHaveEmptySelectedElements() {
            return true;
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) TemplateManager(com.intellij.codeInsight.template.TemplateManager) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) BaseCreateMethodsFix(com.intellij.lang.javascript.validation.fixes.BaseCreateMethodsFix) Template(com.intellij.codeInsight.template.Template)

Aggregations

TemplateManager (com.intellij.codeInsight.template.TemplateManager)20 Template (com.intellij.codeInsight.template.Template)15 Editor (com.intellij.openapi.editor.Editor)9 Project (com.intellij.openapi.project.Project)7 PsiElement (com.intellij.psi.PsiElement)7 TemplateBuilderImpl (com.intellij.codeInsight.template.TemplateBuilderImpl)6 TextRange (com.intellij.openapi.util.TextRange)6 MacroCallNode (com.intellij.codeInsight.template.impl.MacroCallNode)4 Document (com.intellij.openapi.editor.Document)4 TemplateEditingAdapter (com.intellij.codeInsight.template.TemplateEditingAdapter)3 SuggestVariableNameMacro (com.intellij.codeInsight.template.macro.SuggestVariableNameMacro)3 RangeMarker (com.intellij.openapi.editor.RangeMarker)3 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)3 PsiFile (com.intellij.psi.PsiFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 Expression (com.intellij.codeInsight.template.Expression)2 TextExpression (com.intellij.codeInsight.template.impl.TextExpression)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 PsiReference (com.intellij.psi.PsiReference)2 XmlAttribute (com.intellij.psi.xml.XmlAttribute)2