use of com.intellij.codeInsight.template.impl.InvokeTemplateAction in project intellij-community by JetBrains.
the class IterateOverIterableIntention method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final TemplateImpl template = getTemplate();
SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
final PsiExpression iterableExpression = getIterableExpression(editor, file);
LOG.assertTrue(iterableExpression != null);
TextRange textRange = iterableExpression.getTextRange();
selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
}
new InvokeTemplateAction(template, editor, project, new HashSet<>()).perform();
}
use of com.intellij.codeInsight.template.impl.InvokeTemplateAction in project intellij-community by JetBrains.
the class SurroundWithHandler method doBuildSurroundActions.
@Nullable
private static List<AnAction> doBuildSurroundActions(Project project, Editor editor, PsiFile file, Map<Surrounder, PsiElement[]> surrounders) {
final List<AnAction> applicable = new ArrayList<>();
boolean hasEnabledSurrounders = false;
Set<Character> usedMnemonicsSet = new HashSet<>();
int index = 0;
for (Map.Entry<Surrounder, PsiElement[]> entry : surrounders.entrySet()) {
Surrounder surrounder = entry.getKey();
PsiElement[] elements = entry.getValue();
if (surrounder.isApplicable(elements)) {
char mnemonic;
if (index < 9) {
mnemonic = (char) ('0' + index + 1);
} else if (index == 9) {
mnemonic = '0';
} else {
mnemonic = (char) ('A' + index - 10);
}
index++;
usedMnemonicsSet.add(Character.toUpperCase(mnemonic));
applicable.add(new InvokeSurrounderAction(surrounder, project, editor, elements, mnemonic));
hasEnabledSurrounders = true;
}
}
List<CustomLiveTemplate> customTemplates = TemplateManagerImpl.listApplicableCustomTemplates(editor, file, true);
List<TemplateImpl> templates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, true);
if (!templates.isEmpty() || !customTemplates.isEmpty()) {
applicable.add(new Separator("Live templates"));
}
for (TemplateImpl template : templates) {
applicable.add(new InvokeTemplateAction(template, editor, project, usedMnemonicsSet));
hasEnabledSurrounders = true;
}
for (CustomLiveTemplate customTemplate : customTemplates) {
applicable.add(new WrapWithCustomTemplateAction(customTemplate, editor, file, usedMnemonicsSet));
hasEnabledSurrounders = true;
}
if (!templates.isEmpty() || !customTemplates.isEmpty()) {
applicable.add(Separator.getInstance());
applicable.add(new ConfigureTemplatesAction());
}
return hasEnabledSurrounders ? applicable : null;
}
Aggregations