Search in sources :

Example 11 with PubRoot

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartFile(com.jetbrains.lang.dart.psi.DartFile) PsiDirectory(com.intellij.psi.PsiDirectory) PubRoot(io.flutter.pub.PubRoot) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with PubRoot

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();
}
Also used : ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) PubRoot(io.flutter.pub.PubRoot)

Example 13 with PubRoot

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/"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PubRoot(io.flutter.pub.PubRoot)

Example 14 with PubRoot

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));
    }
}
Also used : PubRoot(io.flutter.pub.PubRoot)

Example 15 with PubRoot

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PubRoot(io.flutter.pub.PubRoot)

Aggregations

PubRoot (io.flutter.pub.PubRoot)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 Nullable (org.jetbrains.annotations.Nullable)9 FlutterSdk (io.flutter.sdk.FlutterSdk)7 Project (com.intellij.openapi.project.Project)4 ExecutionException (com.intellij.execution.ExecutionException)3 OutputListener (com.intellij.execution.OutputListener)2 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)2 Module (com.intellij.openapi.module.Module)2 DartFile (com.jetbrains.lang.dart.psi.DartFile)2 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 PsiDirectory (com.intellij.psi.PsiDirectory)1