use of com.intellij.codeInsight.template.CustomTemplateCallback 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.CustomTemplateCallback in project intellij-community by JetBrains.
the class PostfixLiveTemplate method getLookupElements.
@NotNull
@Override
public Collection<? extends CustomLiveTemplateLookupElement> getLookupElements(@NotNull PsiFile file, @NotNull Editor editor, int offset) {
Collection<CustomLiveTemplateLookupElement> result = ContainerUtil.newHashSet();
CustomTemplateCallback callback = new CustomTemplateCallback(editor, file);
for (PostfixTemplateProvider provider : LanguagePostfixTemplate.LANG_EP.allForLanguage(getLanguage(callback))) {
String key = computeTemplateKeyWithoutContextChecking(callback);
if (key != null && editor.getCaretModel().getCaretCount() == 1) {
Condition<PostfixTemplate> isApplicationTemplateFunction = createIsApplicationTemplateFunction(provider, key, file, editor);
for (PostfixTemplate postfixTemplate : provider.getTemplates()) {
if (isApplicationTemplateFunction.value(postfixTemplate)) {
result.add(new PostfixTemplateLookupElement(this, postfixTemplate, postfixTemplate.getKey(), provider, false));
}
}
}
}
return result;
}
use of com.intellij.codeInsight.template.CustomTemplateCallback in project intellij-community by JetBrains.
the class PostfixTemplatesCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
Editor editor = parameters.getEditor();
if (!isCompletionEnabled(parameters) || LiveTemplateCompletionContributor.shouldShowAllTemplates() || editor.getCaretModel().getCaretCount() != 1) {
/*
disabled or covered with {@link com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor}
*/
return;
}
PsiFile originalFile = parameters.getOriginalFile();
PostfixLiveTemplate postfixLiveTemplate = getPostfixLiveTemplate(originalFile, editor);
if (postfixLiveTemplate != null) {
postfixLiveTemplate.addCompletions(parameters, result.withPrefixMatcher(new MyPrefixMatcher(result.getPrefixMatcher().getPrefix())));
String possibleKey = postfixLiveTemplate.computeTemplateKeyWithoutContextChecking(new CustomTemplateCallback(editor, originalFile));
if (possibleKey != null) {
result = result.withPrefixMatcher(possibleKey);
result.restartCompletionOnPrefixChange(StandardPatterns.string().oneOf(postfixLiveTemplate.getAllTemplateKeys(originalFile, parameters.getOffset())));
}
}
}
use of com.intellij.codeInsight.template.CustomTemplateCallback in project intellij-community by JetBrains.
the class WrapWithCustomTemplateAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Document document = myEditor.getDocument();
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file != null) {
ReadonlyStatusHandler.getInstance(myFile.getProject()).ensureFilesWritable(file);
}
String selection = myEditor.getSelectionModel().getSelectedText(true);
if (selection != null) {
selection = selection.trim();
PsiDocumentManager.getInstance(myFile.getProject()).commitAllDocuments();
myTemplate.wrap(selection, new CustomTemplateCallback(myEditor, myFile));
}
}
Aggregations