use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class FlutterIconProvider method getIcon.
@Nullable
public Icon getIcon(@NotNull final PsiElement element, @Iconable.IconFlags final int flags) {
final Project project = element.getProject();
if (!FlutterModuleUtils.usesFlutter(project))
return null;
// Directories.
if (element instanceof PsiDirectory) {
final VirtualFile file = ((PsiDirectory) element).getVirtualFile();
if (!file.isInLocalFileSystem())
return null;
// Show an icon for flutter modules.
final PubRoot pubRoot = PubRoot.forDirectory(file);
if (pubRoot != null && pubRoot.declaresFlutter()) {
return FlutterIcons.Flutter;
}
final PubRoot root = PubRoot.forDirectory(file.getParent());
if (root == null)
return null;
// TODO(devoncarew): should we just make the folder a source kind?
if (file.equals(root.getLib()))
return AllIcons.Modules.SourceRoot;
if (Objects.equals(file, root.getAndroidDir()))
return AllIcons.Nodes.KeymapTools;
if (Objects.equals(file, root.getiOsDir()))
return AllIcons.Nodes.KeymapTools;
if (file.isDirectory() && file.getName().equals(".idea"))
return AllIcons.Modules.GeneratedFolder;
}
// Files.
if (element instanceof DartFile) {
final DartFile dartFile = (DartFile) element;
final VirtualFile file = dartFile.getVirtualFile();
if (!file.isInLocalFileSystem())
return null;
// TODO(pq): consider pushing up to the Dart Plugin.
if (FlutterUtils.isInTestDir(dartFile) && file.getName().endsWith("_test.dart")) {
return TEST_FILE;
}
}
return null;
}
use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class FlutterStudioProjectOpenProcessor method canOpenProject.
@Override
public boolean canOpenProject(@Nullable VirtualFile file) {
if (file == null)
return false;
ApplicationInfo info = ApplicationInfo.getInstance();
final PubRoot root = PubRoot.forDirectory(file);
return root != null && root.declaresFlutter();
}
use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class FlutterUtils method isInTestDir.
public static boolean isInTestDir(@Nullable DartFile file) {
if (file == null)
return false;
final PubRoot root = PubRoot.forFile(file.getVirtualFile());
if (root == null)
return false;
if (!FlutterModuleUtils.isFlutterModule(root.getModule(file.getProject())))
return false;
final VirtualFile candidate = FlutterRunConfigurationProducer.getFlutterEntryFile(file, false, false);
if (candidate == null)
return false;
final String relativePath = root.getRelativePath(candidate);
return relativePath != null && (relativePath.startsWith("test/"));
}
use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class ProjectOpenActivity method runActivity.
@Override
public void runActivity(@NotNull Project project) {
if (!FlutterModuleUtils.usesFlutter(project)) {
// Don't do anything until the second time.
return;
}
PubRoot root = PubRoot.singleForProjectWithRefresh(project);
if (root == null) {
return;
}
if (!downloadDependencies(project, root)) {
return;
}
root = root.refresh();
if (root != null && !root.hasUpToDatePackages()) {
Notifications.Bus.notify(new PackagesOutOfDateNotification(project));
}
}
use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class FlutterPackagesExplorerActionGroup method isFlutterPubspec.
private static boolean isFlutterPubspec(@NotNull AnActionEvent e) {
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
final PubRoot root = file == null ? null : PubRoot.forDirectory(file.getParent());
return root != null && root.getPubspec().equals(file) && root.declaresFlutter();
}
Aggregations