Search in sources :

Example 1 with PostfixTemplatesSettings

use of com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings in project intellij-community by JetBrains.

the class TemplatesCompletionTest method tearDown.

@Override
public void tearDown() throws Exception {
    try {
        PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance();
        assertNotNull(settings);
        settings.setLangDisabledTemplates(ContainerUtil.newHashMap());
        settings.setPostfixTemplatesEnabled(true);
        settings.setTemplatesCompletionEnabled(true);
    } finally {
        super.tearDown();
    }
}
Also used : PostfixTemplatesSettings(com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings)

Example 2 with PostfixTemplatesSettings

use of com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings 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)

Example 3 with PostfixTemplatesSettings

use of com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings in project intellij-community by JetBrains.

the class PostfixLiveTemplate method isApplicable.

@Override
public boolean isApplicable(PsiFile file, int offset, boolean wrapping) {
    PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance();
    if (wrapping || file == null || settings == null || !settings.isPostfixTemplatesEnabled()) {
        return false;
    }
    Language language = PsiUtilCore.getLanguageAtOffset(file, offset);
    for (PostfixTemplateProvider provider : LanguagePostfixTemplate.LANG_EP.allForLanguage(language)) {
        if (StringUtil.isNotEmpty(computeTemplateKeyWithoutContextChecking(provider, file.getText(), offset + 1))) {
            return true;
        }
    }
    return false;
}
Also used : Language(com.intellij.lang.Language) PostfixTemplatesSettings(com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings)

Example 4 with PostfixTemplatesSettings

use of com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings in project intellij-community by JetBrains.

the class TemplatesCompletionTest method testDoNotShowTemplateIfTemplateCompletionIsDisabled.

public void testDoNotShowTemplateIfTemplateCompletionIsDisabled() {
    PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance();
    assertNotNull(settings);
    settings.setTemplatesCompletionEnabled(false);
    doAutoPopupTest("instanceof", null);
}
Also used : PostfixTemplatesSettings(com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings)

Example 5 with PostfixTemplatesSettings

use of com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings in project intellij-community by JetBrains.

the class TemplatesCompletionTest method testDoNotShowTemplateIfPluginIsDisabled.

public void testDoNotShowTemplateIfPluginIsDisabled() {
    PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance();
    assertNotNull(settings);
    settings.setPostfixTemplatesEnabled(false);
    doAutoPopupTest("instanceof", null);
}
Also used : PostfixTemplatesSettings(com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings)

Aggregations

PostfixTemplatesSettings (com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings)6 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 PostfixTemplate (com.intellij.codeInsight.template.postfix.templates.PostfixTemplate)1 Language (com.intellij.lang.Language)1 Project (com.intellij.openapi.project.Project)1