use of com.intellij.codeInsight.template.CustomLiveTemplate in project intellij-community by JetBrains.
the class ListTemplatesHandler method getCustomTemplatesLookupItems.
public static MultiMap<String, CustomLiveTemplateLookupElement> getCustomTemplatesLookupItems(@NotNull Editor editor, @NotNull PsiFile file, int offset) {
final MultiMap<String, CustomLiveTemplateLookupElement> result = MultiMap.create();
CustomTemplateCallback customTemplateCallback = new CustomTemplateCallback(editor, file);
for (CustomLiveTemplate customLiveTemplate : TemplateManagerImpl.listApplicableCustomTemplates(editor, file, false)) {
if (customLiveTemplate instanceof CustomLiveTemplateBase) {
String customTemplatePrefix = ((CustomLiveTemplateBase) customLiveTemplate).computeTemplateKeyWithoutContextChecking(customTemplateCallback);
if (customTemplatePrefix != null) {
result.putValues(customTemplatePrefix, ((CustomLiveTemplateBase) customLiveTemplate).getLookupElements(file, editor, offset));
}
}
}
return result;
}
use of com.intellij.codeInsight.template.CustomLiveTemplate in project intellij-community by JetBrains.
the class LiveTemplateCompletionContributor method showCustomLiveTemplates.
private static void showCustomLiveTemplates(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile file = parameters.getPosition().getContainingFile();
Editor editor = parameters.getEditor();
for (CustomLiveTemplate customLiveTemplate : TemplateManagerImpl.listApplicableCustomTemplates(editor, file, false)) {
if (customLiveTemplate instanceof CustomLiveTemplateBase) {
((CustomLiveTemplateBase) customLiveTemplate).addCompletions(parameters, result);
}
}
}
use of com.intellij.codeInsight.template.CustomLiveTemplate in project intellij-community by JetBrains.
the class SurroundWithTemplateHandler method createActionGroup.
@Nullable
public static DefaultActionGroup createActionGroup(Project project, Editor editor, PsiFile file) {
if (!editor.getSelectionModel().hasSelection()) {
editor.getSelectionModel().selectLineAtCaret();
if (!editor.getSelectionModel().hasSelection())
return null;
}
List<CustomLiveTemplate> customTemplates = TemplateManagerImpl.listApplicableCustomTemplates(editor, file, true);
List<TemplateImpl> templates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, true);
if (templates.isEmpty() && customTemplates.isEmpty()) {
HintManager.getInstance().showErrorHint(editor, CodeInsightBundle.message("templates.surround.no.defined"));
return null;
}
Set<Character> usedMnemonicsSet = new HashSet<>();
DefaultActionGroup group = new DefaultActionGroup();
for (TemplateImpl template : templates) {
group.add(new InvokeTemplateAction(template, editor, project, usedMnemonicsSet));
}
for (CustomLiveTemplate customTemplate : customTemplates) {
group.add(new WrapWithCustomTemplateAction(customTemplate, editor, file, usedMnemonicsSet));
}
return group;
}
use of com.intellij.codeInsight.template.CustomLiveTemplate 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