Search in sources :

Example 26 with LocalFileSystem

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

the class JrtFileSystemImpl method checkSubscription.

private void checkSubscription() {
    if (mySubscribed.getAndSet(true))
        return;
    Application app = ApplicationManager.getApplication();
    app.getMessageBus().connect(app).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            Set<VirtualFile> toRefresh = null;
            for (VFileEvent event : events) {
                if (event.getFileSystem() instanceof LocalFileSystem && event instanceof VFileContentChangeEvent) {
                    VirtualFile file = event.getFile();
                    if (file != null && "release".equals(file.getName())) {
                        String homePath = file.getParent().getPath();
                        ArchiveHandler handler = myHandlers.remove(homePath);
                        if (handler != null) {
                            handler.dispose();
                            VirtualFile root = findFileByPath(composeRootPath(homePath));
                            if (root != null) {
                                ((NewVirtualFile) root).markDirtyRecursively();
                                if (toRefresh == null)
                                    toRefresh = ContainerUtil.newHashSet();
                                toRefresh.add(root);
                            }
                        }
                    }
                }
            }
            if (toRefresh != null) {
                boolean async = !ApplicationManager.getApplication().isUnitTestMode();
                RefreshQueue.getInstance().refresh(async, true, null, toRefresh);
            }
        }
    });
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveHandler(com.intellij.openapi.vfs.impl.ArchiveHandler) Set(java.util.Set) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) Application(com.intellij.openapi.application.Application)

Example 27 with LocalFileSystem

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

the class PsiDirectoryNode method contains.

@Override
public boolean contains(@NotNull VirtualFile file) {
    final PsiDirectory value = getValue();
    if (value == null) {
        return false;
    }
    VirtualFile directory = value.getVirtualFile();
    if (directory.getFileSystem() instanceof LocalFileSystem) {
        file = PathUtil.getLocalFile(file);
    }
    if (!VfsUtilCore.isAncestor(directory, file, false)) {
        return false;
    }
    final Project project = value.getProject();
    PsiFileSystemItemFilter filter = getFilter();
    if (filter != null) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        if (psiFile != null && !filter.shouldShow(psiFile))
            return false;
        PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(file);
        if (psiDirectory != null && !filter.shouldShow(psiDirectory))
            return false;
    }
    if (Registry.is("ide.hide.excluded.files")) {
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        return !fileIndex.isExcluded(file);
    } else {
        return !FileTypeRegistry.getInstance().isFileIgnored(file);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) PsiFile(com.intellij.psi.PsiFile)

Example 28 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-plugins by JetBrains.

the class FlexCompilationManager method refreshAndFindFileInWriteAction.

static VirtualFile refreshAndFindFileInWriteAction(final String outputFilePath, final String... possibleBaseDirs) {
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final Ref<VirtualFile> outputFileRef = new Ref<>();
    final Application app = ApplicationManager.getApplication();
    app.invokeAndWait(() -> outputFileRef.set(app.runWriteAction(new NullableComputable<VirtualFile>() {

        public VirtualFile compute() {
            VirtualFile outputFile = localFileSystem.refreshAndFindFileByPath(outputFilePath);
            //}
            if (outputFile == null) {
                for (final String baseDir : possibleBaseDirs) {
                    outputFile = localFileSystem.refreshAndFindFileByPath(baseDir + "/" + outputFilePath);
                    if (outputFile != null) {
                        break;
                    }
                }
            }
            if (outputFile == null)
                return null;
            // it's important because this file has just been created
            outputFile.refresh(false, false);
            return outputFile;
        }
    })));
    return outputFileRef.get();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Ref(com.intellij.openapi.util.Ref) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Application(com.intellij.openapi.application.Application)

Example 29 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project android by JetBrains.

the class AndroidJniFolderNode method getDirectories.

@NotNull
@Override
public PsiDirectory[] getDirectories() {
    Collection<File> sourceFolders = getModel().getSelectedVariant().getSourceFolders();
    List<PsiDirectory> psiDirectories = Lists.newArrayListWithExpectedSize(sourceFolders.size());
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    assert myProject != null;
    PsiManager psiManager = PsiManager.getInstance(myProject);
    for (File folder : sourceFolders) {
        VirtualFile virtualFile = fileSystem.findFileByIoFile(folder);
        if (virtualFile != null) {
            PsiDirectory dir = psiManager.findDirectory(virtualFile);
            if (dir != null) {
                psiDirectories.add(dir);
            }
        }
    }
    return psiDirectories.toArray(new PsiDirectory[psiDirectories.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) PsiManager(com.intellij.psi.PsiManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project android by JetBrains.

the class NativeAndroidLibraryNode method convertToVirtualFiles.

@NotNull
private static List<VirtualFile> convertToVirtualFiles(@NotNull Collection<File> files) {
    List<VirtualFile> result = Lists.newArrayListWithCapacity(files.size());
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    for (File file : files) {
        VirtualFile virtualFile = fileSystem.findFileByIoFile(file);
        if (virtualFile != null) {
            result.add(virtualFile);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NativeFile(com.android.builder.model.NativeFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)58 VirtualFile (com.intellij.openapi.vfs.VirtualFile)52 File (java.io.File)27 Nullable (org.jetbrains.annotations.Nullable)9 NotNull (org.jetbrains.annotations.NotNull)8 IOException (java.io.IOException)6 Project (com.intellij.openapi.project.Project)5 Change (com.intellij.openapi.vcs.changes.Change)5 Test (org.junit.Test)5 Module (com.intellij.openapi.module.Module)4 Application (com.intellij.openapi.application.Application)3 Library (com.intellij.openapi.roots.libraries.Library)3 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 PsiFile (com.intellij.psi.PsiFile)3 Notification (com.intellij.notification.Notification)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)2