Search in sources :

Example 1 with PostfixTemplatesConfigurable

use of com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesConfigurable 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)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 Project (com.intellij.openapi.project.Project)1