Search in sources :

Example 1 with LookupElementAction

use of com.intellij.codeInsight.lookup.LookupElementAction 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 LookupElementAction

use of com.intellij.codeInsight.lookup.LookupElementAction in project intellij-community by JetBrains.

the class LiveTemplateLookupActionProvider method fillActions.

@Override
public void fillActions(LookupElement element, final Lookup lookup, Consumer<LookupElementAction> consumer) {
    if (element instanceof LiveTemplateLookupElementImpl) {
        final TemplateImpl template = ((LiveTemplateLookupElementImpl) element).getTemplate();
        final TemplateImpl templateFromSettings = TemplateSettings.getInstance().getTemplate(template.getKey(), template.getGroupName());
        if (templateFromSettings != null) {
            consumer.consume(new LookupElementAction(PlatformIcons.EDIT, "Edit live template settings") {

                @Override
                public Result performLookupAction() {
                    final Project project = lookup.getProject();
                    ApplicationManager.getApplication().invokeLater(() -> {
                        if (project.isDisposed())
                            return;
                        final LiveTemplatesConfigurable configurable = new LiveTemplatesConfigurable();
                        ShowSettingsUtil.getInstance().editConfigurable(project, configurable, () -> configurable.getTemplateListPanel().editTemplate(template));
                    });
                    return Result.HIDE_LOOKUP;
                }
            });
            consumer.consume(new LookupElementAction(AllIcons.Actions.Delete, String.format("Disable '%s' template", template.getKey())) {

                @Override
                public Result performLookupAction() {
                    ApplicationManager.getApplication().invokeLater(() -> templateFromSettings.setDeactivated(true));
                    return Result.HIDE_LOOKUP;
                }
            });
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) LookupElementAction(com.intellij.codeInsight.lookup.LookupElementAction)

Example 3 with LookupElementAction

use of com.intellij.codeInsight.lookup.LookupElementAction in project intellij-community by JetBrains.

the class ImportStaticLookupActionProvider method fillActions.

@Override
public void fillActions(final LookupElement element, Lookup lookup, Consumer<LookupElementAction> consumer) {
    final StaticallyImportable item = element.as(StaticallyImportable.CLASS_CONDITION_KEY);
    if (item == null || !item.canBeImported()) {
        return;
    }
    final Icon checkIcon = PlatformIcons.CHECK_ICON;
    final Icon icon = item.willBeImported() ? checkIcon : EmptyIcon.create(checkIcon);
    consumer.consume(new LookupElementAction(icon, "Import statically") {

        @Override
        public Result performLookupAction() {
            item.setShouldBeImported(!item.willBeImported());
            return new Result.ChooseItem(element);
        }
    });
}
Also used : LookupElementAction(com.intellij.codeInsight.lookup.LookupElementAction) EmptyIcon(com.intellij.util.ui.EmptyIcon)

Example 4 with LookupElementAction

use of com.intellij.codeInsight.lookup.LookupElementAction in project intellij-community by JetBrains.

the class PostfixTemplateLookupActionProvider method fillActions.

@Override
public void fillActions(LookupElement element, final Lookup lookup, Consumer<LookupElementAction> consumer) {
    if (element instanceof PostfixTemplateLookupElement) {
        final PostfixTemplateLookupElement templateLookupElement = (PostfixTemplateLookupElement) element;
        final PostfixTemplate template = templateLookupElement.getPostfixTemplate();
        consumer.consume(new LookupElementAction(PlatformIcons.EDIT, "Edit postfix templates settings") {

            @Override
            public Result performLookupAction() {
                final Project project = lookup.getProject();
                ApplicationManager.getApplication().invokeLater(() -> {
                    if (project.isDisposed())
                        return;
                    final PostfixTemplatesConfigurable configurable = new PostfixTemplatesConfigurable();
                    ShowSettingsUtil.getInstance().editConfigurable(project, configurable, () -> {
                        PostfixTemplatesCheckboxTree templatesTree = configurable.getTemplatesTree();
                        if (templatesTree != null) {
                            templatesTree.selectTemplate(template, PostfixTemplatesUtils.getLangForProvider(templateLookupElement.getProvider()));
                        }
                    });
                });
                return Result.HIDE_LOOKUP;
            }
        });
        final PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance();
        if (settings != null && settings.isTemplateEnabled(template, templateLookupElement.getProvider())) {
            consumer.consume(new LookupElementAction(AllIcons.Actions.Delete, String.format("Disable '%s' template", template.getKey())) {

                @Override
                public Result performLookupAction() {
                    ApplicationManager.getApplication().invokeLater(() -> settings.disableTemplate(template, templateLookupElement.getProvider()));
                    return Result.HIDE_LOOKUP;
                }
            });
        }
    }
}
Also used : PostfixTemplate(com.intellij.codeInsight.template.postfix.templates.PostfixTemplate) Project(com.intellij.openapi.project.Project) PostfixTemplatesCheckboxTree(com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesCheckboxTree) LookupElementAction(com.intellij.codeInsight.lookup.LookupElementAction) PostfixTemplatesConfigurable(com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesConfigurable) PostfixTemplatesSettings(com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings)

Aggregations

LookupElementAction (com.intellij.codeInsight.lookup.LookupElementAction)4 Project (com.intellij.openapi.project.Project)3 EmmetCompositeConfigurable (com.intellij.application.options.emmet.EmmetCompositeConfigurable)1 XmlEmmetConfigurable (com.intellij.application.options.emmet.XmlEmmetConfigurable)1 ZenCodingTemplate (com.intellij.codeInsight.template.emmet.ZenCodingTemplate)1 ZenCodingGenerator (com.intellij.codeInsight.template.emmet.generators.ZenCodingGenerator)1 CustomLiveTemplateLookupElement (com.intellij.codeInsight.template.impl.CustomLiveTemplateLookupElement)1 PostfixTemplatesCheckboxTree (com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesCheckboxTree)1 PostfixTemplatesConfigurable (com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesConfigurable)1 PostfixTemplatesSettings (com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings)1 PostfixTemplate (com.intellij.codeInsight.template.postfix.templates.PostfixTemplate)1 Configurable (com.intellij.openapi.options.Configurable)1 PsiElement (com.intellij.psi.PsiElement)1 EmptyIcon (com.intellij.util.ui.EmptyIcon)1