package com.rudeshko.csscomb;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.psi.PsiFile;

public class CssCombAction extends AnAction {
    public void actionPerformed(AnActionEvent e) {
        PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
        if (psiFile != null) {
            psiFile.acceptChildren(new CSSCombVisitor());
        }
    }

    @Override
    public void update(AnActionEvent e) {
        e.getPresentation().setEnabled(isCss(e));
    }

    private boolean isCss(AnActionEvent e) {
        PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
        return psiFile != null && "CSS".equals(psiFile.getLanguage().getDisplayName());
    }
}

@@ -24,16 +24,58 @@
 scomb;%0A%0A
+import com.intellij.lang.css.CSSLanguage;%0A
 import c
@@ -117,16 +117,16 @@
 Action;%0A
-
 import c
@@ -389,39 +389,35 @@
 e = 
-e.
 get
-Data(LangDataKeys.PSI_FILE
+PsiFileFromActionEvent(e
 );%0A 
@@ -709,39 +709,35 @@
 e = 
-e.
 get
-Data(LangDataKeys.PSI_FILE
+PsiFileFromActionEvent(e
 );%0A 
@@ -773,21 +773,8 @@
  && 
-%22CSS%22.equals(
 psiF
@@ -795,24 +795,166 @@
 e().
-getDisplayName()
+isKindOf(CSSLanguage.INSTANCE);%0A%0A    %7D%0A%0A    private static PsiFile getPsiFileFromActionEvent(AnActionEvent e) %7B%0A        return e.getData(LangDataKeys.PSI_FILE
 );%0A 

Correct way to detect file language