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);
}
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);
}
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);
}
}
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);
}
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;
}
};
}
Aggregations