From 0db3d58252053e2afd87613281f22596f7152f62 Mon Sep 17 00:00:00 2001 From: Alexey Utkin Date: Fri, 12 Jan 2018 16:17:27 +0300 Subject: [PATCH] CPP-2906 OC-13262 Code Fold of control flow statements (if/else, do/while, for, switch) Disable the action for languages without `Collapse Block` handlers --- .../folding/impl/actions/CollapseBlockAction.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseBlockAction.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseBlockAction.java index 2a9bed699e74..cc99902c34fd 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseBlockAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseBlockAction.java @@ -11,16 +11,25 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class CollapseBlockAction extends BaseCodeInsightAction { @NotNull @Override protected CodeInsightActionHandler getHandler() { return new CodeInsightActionHandler() { public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) { - CollapseBlockHandler.EP_NAME - .allForLanguage(file.getLanguage()) - .forEach(handler->handler.invoke(project, editor, file)); + getHandlersForFile(file).forEach(handler->handler.invoke(project, editor, file)); } }; } + + protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { + return !getHandlersForFile(file).isEmpty(); + } + + @NotNull + private static List getHandlersForFile(@NotNull PsiFile file) { + return CollapseBlockHandler.EP_NAME.allForLanguage(file.getLanguage()); + } }