use of com.intellij.openapi.roots.ProjectFileIndex in project android by JetBrains.
the class CreateClassAction method isAvailable.
private boolean isAvailable(@NotNull DataContext dataContext) {
Project project = CommonDataKeys.PROJECT.getData(dataContext);
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (project == null || view == null || view.getDirectories().length == 0) {
return false;
}
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (PsiDirectory dir : view.getDirectories()) {
if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && checkPackageExists(dir)) {
return true;
}
}
return false;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project android by JetBrains.
the class CreateLibraryFromFilesAction method update.
@Override
public void update(@NotNull AnActionEvent e) {
final Project project = getEventProject(e);
boolean visible = false;
if (project != null && ModuleManager.getInstance(project).getModules().length > 0) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (VirtualFile root : getRoots(e)) {
if (!root.isInLocalFileSystem() && FileUtilRt.extensionEquals(root.getName(), "jar") && !fileIndex.isInLibraryClasses(root)) {
visible = true;
break;
}
}
}
Presentation presentation = e.getPresentation();
presentation.setVisible(visible);
presentation.setEnabled(visible);
}
use of com.intellij.openapi.roots.ProjectFileIndex in project android by JetBrains.
the class JavaSourceAction method isAvailable.
protected static boolean isAvailable(DataContext dataContext) {
final Module module = LangDataKeys.MODULE.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (module == null || view == null || view.getDirectories().length == 0 || AndroidFacet.getInstance(module) == null) {
return false;
}
final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
for (PsiDirectory dir : view.getDirectories()) {
if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && dirService.getPackage(dir) != null && !dirService.getPackage(dir).getQualifiedName().isEmpty()) {
return true;
}
}
return false;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project android by JetBrains.
the class LegacyNewAndroidComponentAction method isAvailable.
private static boolean isAvailable(DataContext dataContext) {
final Module module = LangDataKeys.MODULE.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (module == null || view == null || view.getDirectories().length == 0) {
return false;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null || facet.requiresAndroidModel()) {
return false;
}
final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
for (PsiDirectory dir : view.getDirectories()) {
if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && dirService.getPackage(dir) != null) {
return true;
}
}
return false;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project android by JetBrains.
the class IncludeModuleForFileAction method findTarget.
@Nullable
private static VirtualFile findTarget(@NotNull AnActionEvent e, @NotNull Project project) {
VirtualFile[] virtualFiles = VIRTUAL_FILE_ARRAY.getData(e.getDataContext());
if (virtualFiles != null && virtualFiles.length == 1) {
VirtualFile target = virtualFiles[0];
if (isModuleSourceRoot(target, project) || project.getBaseDir().equals(target)) {
// Module folders and project folder are ignored.
return null;
}
ProjectFileIndex projectIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (projectIndex.isExcluded(target)) {
// Excluded folders are ignored.
return null;
}
return target;
}
return null;
}
Aggregations