Search in sources :

Example 81 with Project

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

the class RestPythonUtil method updateSphinxQuickStartRequiredAction.

public static Presentation updateSphinxQuickStartRequiredAction(final AnActionEvent e) {
    final Presentation presentation = e.getPresentation();
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project != null) {
        Module module = e.getData(LangDataKeys.MODULE);
        if (module == null) {
            Module[] modules = ModuleManager.getInstance(project).getModules();
            module = modules.length == 0 ? null : modules[0];
        }
        if (module != null) {
            final Sdk sdk = PythonSdkType.findPythonSdk(module);
            if (sdk != null) {
                final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
                final PyPackage sphinx = packages != null ? PyPackageUtil.findPackage(packages, "Sphinx") : null;
                presentation.setEnabled(sphinx != null);
            }
        }
    }
    return presentation;
}
Also used : Project(com.intellij.openapi.project.Project) PyPackage(com.jetbrains.python.packaging.PyPackage) Sdk(com.intellij.openapi.projectRoots.Sdk) Presentation(com.intellij.openapi.actionSystem.Presentation) Module(com.intellij.openapi.module.Module)

Example 82 with Project

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

the class SphinxConfigurationProducer method createConfigurationByElement.

protected RunnerAndConfigurationSettings createConfigurationByElement(final Location location, final ConfigurationContext context) {
    PsiElement element = location.getPsiElement();
    if (!(element instanceof PsiDirectory))
        return null;
    mySourceFile = (PsiDirectory) element;
    boolean hasRstFile = false;
    boolean hasConf = false;
    for (PsiFile file : mySourceFile.getFiles()) {
        if ("conf.py".equals(file.getName()))
            hasConf = true;
        if (file instanceof RestFile) {
            hasRstFile = true;
        }
    }
    if (!hasRstFile || !hasConf)
        return null;
    final Project project = mySourceFile.getProject();
    RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context);
    SphinxRunConfiguration configuration = (SphinxRunConfiguration) settings.getConfiguration();
    final VirtualFile vFile = mySourceFile.getVirtualFile();
    configuration.setInputFile(vFile.getPath());
    configuration.setName(((PsiDirectory) element).getName());
    if (configuration.getTask().isEmpty())
        configuration.setTask("html");
    final VirtualFile parent = vFile.getParent();
    if (parent != null) {
        configuration.setWorkingDirectory(parent.getPath());
    }
    configuration.setName(configuration.suggestedName());
    Module module = ModuleUtil.findModuleForPsiElement(element);
    if (module != null) {
        configuration.setUseModuleSdk(true);
        configuration.setModule(module);
    }
    return settings;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) RestFile(com.jetbrains.rest.RestFile) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 83 with Project

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

the class SphinxBaseCommand method execute.

public void execute(@NotNull final Module module) {
    final Project project = module.getProject();
    try {
        if (!setWorkDir(module))
            return;
        final ProcessHandler process = createProcess(module);
        new RunContentExecutor(project, process).withFilter(new PythonTracebackFilter(project)).withTitle("reStructuredText").withRerun(() -> execute(module)).withAfterCompletion(getAfterTask(module)).run();
    } catch (ExecutionException e) {
        Messages.showErrorDialog(e.getMessage(), "ReStructuredText Error");
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProcessHandler(com.intellij.execution.process.ProcessHandler) RunContentExecutor(com.intellij.execution.RunContentExecutor) ExecutionException(com.intellij.execution.ExecutionException) PythonTracebackFilter(com.jetbrains.python.run.PythonTracebackFilter)

Example 84 with Project

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

the class DomUtil method getContextElement.

@Nullable
public static DomElement getContextElement(@Nullable final Editor editor) {
    if (editor == null)
        return null;
    final Project project = editor.getProject();
    if (project == null)
        return null;
    final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (!(file instanceof XmlFile)) {
        return null;
    }
    return getDomElement(file.findElementAt(editor.getCaretModel().getOffset()));
}
Also used : Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 85 with Project

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

the class DomUtil method getDomElement.

@Nullable
public static DomElement getDomElement(@Nullable final PsiElement element) {
    if (element == null)
        return null;
    final Project project = element.getProject();
    final DomManager domManager = DomManager.getDomManager(project);
    final XmlAttribute attr = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    if (attr != null) {
        final GenericAttributeValue value = domManager.getDomElement(attr);
        if (value != null)
            return value;
    }
    XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
    while (tag != null) {
        final DomElement domElement = domManager.getDomElement(tag);
        if (domElement != null)
            return domElement;
        tag = tag.getParentTag();
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Project (com.intellij.openapi.project.Project)3623 VirtualFile (com.intellij.openapi.vfs.VirtualFile)874 NotNull (org.jetbrains.annotations.NotNull)580 Nullable (org.jetbrains.annotations.Nullable)478 Module (com.intellij.openapi.module.Module)368 PsiFile (com.intellij.psi.PsiFile)334 Editor (com.intellij.openapi.editor.Editor)301 PsiElement (com.intellij.psi.PsiElement)292 ArrayList (java.util.ArrayList)214 File (java.io.File)212 Document (com.intellij.openapi.editor.Document)180 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)172 List (java.util.List)158 IOException (java.io.IOException)107 TextRange (com.intellij.openapi.util.TextRange)99 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)96 IncorrectOperationException (com.intellij.util.IncorrectOperationException)95 Presentation (com.intellij.openapi.actionSystem.Presentation)94 DataContext (com.intellij.openapi.actionSystem.DataContext)92 PsiDirectory (com.intellij.psi.PsiDirectory)90