Search in sources :

Example 56 with Presentation

use of com.intellij.openapi.actionSystem.Presentation in project intellij-community by JetBrains.

the class GeneratePluginClassAction method update.

public void update(final AnActionEvent e) {
    super.update(e);
    final Presentation presentation = e.getPresentation();
    if (presentation.isEnabled()) {
        final Project project = e.getProject();
        final Module module = e.getData(LangDataKeys.MODULE);
        if (project != null && module != null && PsiUtil.isPluginModule(module)) {
            final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
            if (view != null) {
                // from com.intellij.ide.actions.CreateClassAction.update()
                ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
                PsiDirectory[] dirs = view.getDirectories();
                for (PsiDirectory dir : dirs) {
                    if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
                        return;
                    }
                }
            }
        }
        presentation.setEnabledAndVisible(false);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Presentation(com.intellij.openapi.actionSystem.Presentation) Module(com.intellij.openapi.module.Module) IdeView(com.intellij.ide.IdeView)

Example 57 with Presentation

use of com.intellij.openapi.actionSystem.Presentation in project intellij-community by JetBrains.

the class RunTargetAction method update.

@Override
public void update(AnActionEvent e) {
    super.update(e);
    final Presentation presentation = e.getPresentation();
    Pair<AntBuildFileBase, AntDomTarget> antTarget = findAntTarget(e);
    if (antTarget == null) {
        presentation.setEnabled(false);
        presentation.setText(AntActionsBundle.message("action.RunTargetAction.text", ""));
    } else {
        presentation.setEnabled(true);
        presentation.setText(AntActionsBundle.message("action.RunTargetAction.text", "'" + antTarget.second.getName().getValue() + "'"));
    }
}
Also used : AntBuildFileBase(com.intellij.lang.ant.config.AntBuildFileBase) Presentation(com.intellij.openapi.actionSystem.Presentation) AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget)

Example 58 with Presentation

use of com.intellij.openapi.actionSystem.Presentation in project intellij-community by JetBrains.

the class StopAction method update.

public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    presentation.setEnabled(!myAntBuildMessageView.isStopped());
}
Also used : Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 59 with Presentation

use of com.intellij.openapi.actionSystem.Presentation in project intellij-community by JetBrains.

the class AddAntBuildFile method update.

public void update(@NotNull AnActionEvent e) {
    final Presentation presentation = e.getPresentation();
    final Project project = e.getProject();
    if (project != null) {
        final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        if (files != null && files.length > 0) {
            for (VirtualFile file : files) {
                final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
                if (!(psiFile instanceof XmlFile)) {
                    continue;
                }
                final XmlFile xmlFile = (XmlFile) psiFile;
                final XmlDocument document = xmlFile.getDocument();
                if (document == null) {
                    continue;
                }
                final XmlTag rootTag = document.getRootTag();
                if (rootTag == null) {
                    continue;
                }
                if (!"project".equals(rootTag.getName())) {
                    continue;
                }
                if (AntConfigurationBase.getInstance(project).getAntBuildFile(psiFile) != null) {
                    continue;
                }
                // found at least one candidate file
                enable(presentation);
                return;
            }
        }
    }
    disable(presentation);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) XmlDocument(com.intellij.psi.xml.XmlDocument) Presentation(com.intellij.openapi.actionSystem.Presentation) XmlTag(com.intellij.psi.xml.XmlTag)

Example 60 with Presentation

use of com.intellij.openapi.actionSystem.Presentation in project intellij-community by JetBrains.

the class AntBuildFilePropertiesAction method update.

public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    presentation.setEnabled(myAntExplorer.isBuildFileSelected());
}
Also used : Presentation(com.intellij.openapi.actionSystem.Presentation)

Aggregations

Presentation (com.intellij.openapi.actionSystem.Presentation)236 Project (com.intellij.openapi.project.Project)76 VirtualFile (com.intellij.openapi.vfs.VirtualFile)34 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)11 DataContext (com.intellij.openapi.actionSystem.DataContext)10 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)8 AnAction (com.intellij.openapi.actionSystem.AnAction)7 PsiFile (com.intellij.psi.PsiFile)6 IdeView (com.intellij.ide.IdeView)5 ActionManager (com.intellij.openapi.actionSystem.ActionManager)5 Editor (com.intellij.openapi.editor.Editor)5 File (java.io.File)5 Module (com.intellij.openapi.module.Module)4 ToolWindowManagerEx (com.intellij.openapi.wm.ex.ToolWindowManagerEx)4 PsiDirectory (com.intellij.psi.PsiDirectory)4 Course (com.jetbrains.edu.learning.courseFormat.Course)4 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)4 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)3 NotNull (org.jetbrains.annotations.NotNull)3 Before (org.junit.Before)3