Search in sources :

Example 1 with CustomLiveTemplateLookupElement

use of com.intellij.codeInsight.template.impl.CustomLiveTemplateLookupElement in project intellij-community by JetBrains.

the class EmmetLookupActionProvider method fillActions.

@Override
public void fillActions(LookupElement element, final Lookup lookup, Consumer<LookupElementAction> consumer) {
    if (element instanceof CustomLiveTemplateLookupElement && ((CustomLiveTemplateLookupElement) element).getCustomLiveTemplate() instanceof ZenCodingTemplate) {
        final PsiElement context = lookup.getPsiElement();
        final ZenCodingGenerator generator = context != null ? ZenCodingTemplate.findApplicableDefaultGenerator(context, false) : null;
        if (generator != null) {
            consumer.consume(new LookupElementAction(PlatformIcons.EDIT, "Edit Emmet settings") {

                @Override
                public Result performLookupAction() {
                    final Project project = lookup.getProject();
                    ApplicationManager.getApplication().invokeLater(() -> {
                        if (project.isDisposed())
                            return;
                        final Configurable generatorSpecificConfigurable = generator.createConfigurable();
                        Configurable configurable = generatorSpecificConfigurable != null ? generatorSpecificConfigurable : new XmlEmmetConfigurable();
                        ShowSettingsUtil.getInstance().editConfigurable(project, new EmmetCompositeConfigurable(configurable));
                    });
                    return Result.HIDE_LOOKUP;
                }
            });
            consumer.consume(new LookupElementAction(AllIcons.Actions.Delete, "Disable Emmet") {

                @Override
                public Result performLookupAction() {
                    ApplicationManager.getApplication().invokeLater(generator::disableEmmet);
                    return Result.HIDE_LOOKUP;
                }
            });
        }
    }
}
Also used : ZenCodingTemplate(com.intellij.codeInsight.template.emmet.ZenCodingTemplate) Project(com.intellij.openapi.project.Project) CustomLiveTemplateLookupElement(com.intellij.codeInsight.template.impl.CustomLiveTemplateLookupElement) LookupElementAction(com.intellij.codeInsight.lookup.LookupElementAction) EmmetCompositeConfigurable(com.intellij.application.options.emmet.EmmetCompositeConfigurable) ZenCodingGenerator(com.intellij.codeInsight.template.emmet.generators.ZenCodingGenerator) Configurable(com.intellij.openapi.options.Configurable) XmlEmmetConfigurable(com.intellij.application.options.emmet.XmlEmmetConfigurable) EmmetCompositeConfigurable(com.intellij.application.options.emmet.EmmetCompositeConfigurable) XmlEmmetConfigurable(com.intellij.application.options.emmet.XmlEmmetConfigurable) PsiElement(com.intellij.psi.PsiElement)

Example 2 with CustomLiveTemplateLookupElement

use of com.intellij.codeInsight.template.impl.CustomLiveTemplateLookupElement 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;
}
Also used : CustomLiveTemplateLookupElement(com.intellij.codeInsight.template.impl.CustomLiveTemplateLookupElement) PostfixTemplateLookupElement(com.intellij.codeInsight.template.postfix.completion.PostfixTemplateLookupElement) CustomTemplateCallback(com.intellij.codeInsight.template.CustomTemplateCallback) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CustomLiveTemplateLookupElement (com.intellij.codeInsight.template.impl.CustomLiveTemplateLookupElement)2 EmmetCompositeConfigurable (com.intellij.application.options.emmet.EmmetCompositeConfigurable)1 XmlEmmetConfigurable (com.intellij.application.options.emmet.XmlEmmetConfigurable)1 LookupElementAction (com.intellij.codeInsight.lookup.LookupElementAction)1 CustomTemplateCallback (com.intellij.codeInsight.template.CustomTemplateCallback)1 ZenCodingTemplate (com.intellij.codeInsight.template.emmet.ZenCodingTemplate)1 ZenCodingGenerator (com.intellij.codeInsight.template.emmet.generators.ZenCodingGenerator)1 PostfixTemplateLookupElement (com.intellij.codeInsight.template.postfix.completion.PostfixTemplateLookupElement)1 Configurable (com.intellij.openapi.options.Configurable)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 NotNull (org.jetbrains.annotations.NotNull)1