Search in sources :

Example 1 with PostfixTemplate

use of com.intellij.codeInsight.template.postfix.templates.PostfixTemplate in project intellij-community by JetBrains.

the class PostfixTemplatesCheckboxTree method initTree.

public void initTree(@NotNull MultiMap<String, PostfixTemplate> langToTemplates) {
    myRoot.removeAllChildren();
    for (Map.Entry<String, Collection<PostfixTemplate>> entry : langToTemplates.entrySet()) {
        String id = entry.getKey();
        Language language = Language.findLanguageByID(id);
        String langName = language != null ? language.getDisplayName() : id;
        CheckedTreeNode langNode = new CheckedTreeNode(langName);
        myRoot.add(langNode);
        for (PostfixTemplate template : entry.getValue()) {
            CheckedTreeNode templateNode = new PostfixTemplateCheckedTreeNode(template, langName);
            langNode.add(templateNode);
        }
    }
    myModel.nodeStructureChanged(myRoot);
    TreeUtil.expandAll(this);
    setSelectionRow(0);
}
Also used : PostfixTemplate(com.intellij.codeInsight.template.postfix.templates.PostfixTemplate) Language(com.intellij.lang.Language) Collection(java.util.Collection) CheckedTreeNode(com.intellij.ui.CheckedTreeNode) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap)

Example 2 with PostfixTemplate

use of com.intellij.codeInsight.template.postfix.templates.PostfixTemplate 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

PostfixTemplate (com.intellij.codeInsight.template.postfix.templates.PostfixTemplate)2 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 Language (com.intellij.lang.Language)1 Project (com.intellij.openapi.project.Project)1 CheckedTreeNode (com.intellij.ui.CheckedTreeNode)1 MultiMap (com.intellij.util.containers.MultiMap)1 Collection (java.util.Collection)1 Map (java.util.Map)1