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;
}
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;
}
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");
}
}
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()));
}
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;
}
Aggregations