Search in sources :

Example 1 with VirtualDirectoryImpl

use of com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl in project intellij-community by JetBrains.

the class StudyProjectGenerator method openFirstTask.

public static void openFirstTask(@NotNull final Course course, @NotNull final Project project) {
    LocalFileSystem.getInstance().refresh(false);
    final Lesson firstLesson = StudyUtils.getFirst(course.getLessons());
    if (firstLesson == null)
        return;
    final Task firstTask = StudyUtils.getFirst(firstLesson.getTaskList());
    if (firstTask == null)
        return;
    final VirtualFile taskDir = firstTask.getTaskDir(project);
    if (taskDir == null)
        return;
    final Map<String, TaskFile> taskFiles = firstTask.getTaskFiles();
    VirtualFile activeVirtualFile = null;
    for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
        final String relativePath = entry.getKey();
        final TaskFile taskFile = entry.getValue();
        taskDir.refresh(false, true);
        final VirtualFile virtualFile = taskDir.findFileByRelativePath(relativePath);
        if (virtualFile != null) {
            if (!taskFile.getActivePlaceholders().isEmpty()) {
                activeVirtualFile = virtualFile;
            }
        }
    }
    if (activeVirtualFile != null) {
        final PsiFile file = PsiManager.getInstance(project).findFile(activeVirtualFile);
        ProjectView.getInstance(project).select(file, activeVirtualFile, false);
        final FileEditor[] editors = FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
        if (editors.length == 0) {
            return;
        }
        final FileEditor studyEditor = editors[0];
        if (studyEditor instanceof StudyEditor) {
            StudyUtils.selectFirstAnswerPlaceholder((StudyEditor) studyEditor, project);
        }
        FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
    } else {
        String first = StudyUtils.getFirst(taskFiles.keySet());
        if (first != null) {
            NewVirtualFile firstFile = ((VirtualDirectoryImpl) taskDir).refreshAndFindChild(first);
            if (firstFile != null) {
                FileEditorManager.getInstance(project).openFile(firstFile, true);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) PsiFile(com.intellij.psi.PsiFile) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

Example 2 with VirtualDirectoryImpl

use of com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl in project intellij-community by JetBrains.

the class PlatformTestCase method addSubTree.

private static void addSubTree(VirtualFile root, Set<VirtualFile> to) {
    if (root instanceof VirtualDirectoryImpl) {
        for (VirtualFile child : ((VirtualDirectoryImpl) root).getCachedChildren()) {
            if (child instanceof VirtualDirectoryImpl) {
                to.add(child);
                addSubTree(child, to);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl)

Example 3 with VirtualDirectoryImpl

use of com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl in project scss-lint-plugin by idok.

the class FileUtils method getAllFilesInDirectory.

public static List<String> getAllFilesInDirectory(VirtualFile directory, String target, String replacement) {
    List<String> files = new ArrayList<String>();
    VirtualFile[] children = directory.getChildren();
    for (VirtualFile child : children) {
        if (child instanceof VirtualDirectoryImpl) {
            files.addAll(getAllFilesInDirectory(child, target, replacement));
        } else if (child instanceof VirtualFileImpl) {
            files.add(child.getPath().replace(target, replacement));
        }
    }
    return files;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) ArrayList(java.util.ArrayList) VirtualFileImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl)

Example 4 with VirtualDirectoryImpl

use of com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl in project WebStormRequireJsPlugin by Fedott.

the class FileUtils method getAllFilesInDirectory.

public static List<String> getAllFilesInDirectory(VirtualFile directory, String target, String replacement) {
    List<String> files = new ArrayList<String>();
    VirtualFile[] children = directory.getChildren();
    for (VirtualFile child : children) {
        if (child instanceof VirtualDirectoryImpl) {
            files.addAll(getAllFilesInDirectory(child, target, replacement));
        } else if (child instanceof VirtualFileImpl) {
            files.add(child.getPath().replace(target, replacement));
        }
    }
    return files;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) ArrayList(java.util.ArrayList) VirtualFileImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl)

Example 5 with VirtualDirectoryImpl

use of com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl in project intellij-community by JetBrains.

the class RefreshWorker method processQueue.

private void processQueue(NewVirtualFileSystem fs, PersistentFS persistence) throws RefreshCancelledException {
    TObjectHashingStrategy<String> strategy = FilePathHashingStrategy.create(fs.isCaseSensitive());
    while (!myRefreshQueue.isEmpty()) {
        Pair<NewVirtualFile, FileAttributes> pair = myRefreshQueue.pullFirst();
        NewVirtualFile file = pair.first;
        boolean fileDirty = file.isDirty();
        if (LOG.isTraceEnabled())
            LOG.trace("file=" + file + " dirty=" + fileDirty);
        if (!fileDirty)
            continue;
        checkCancelled(file);
        FileAttributes attributes = pair.second != null ? pair.second : fs.getAttributes(file);
        if (attributes == null) {
            scheduleDeletion(file);
            file.markClean();
            continue;
        }
        NewVirtualFile parent = file.getParent();
        if (parent != null && checkAndScheduleFileTypeChange(parent, file, attributes)) {
            // ignore everything else
            file.markClean();
            continue;
        }
        if (file.isDirectory()) {
            boolean fullSync = ((VirtualDirectoryImpl) file).allChildrenLoaded();
            if (fullSync) {
                fullDirRefresh(fs, persistence, strategy, (VirtualDirectoryImpl) file);
            } else {
                partialDirRefresh(fs, strategy, (VirtualDirectoryImpl) file);
            }
        } else {
            long currentTimestamp = persistence.getTimeStamp(file);
            long upToDateTimestamp = attributes.lastModified;
            long currentLength = persistence.getLastRecordedLength(file);
            long upToDateLength = attributes.length;
            if (currentTimestamp != upToDateTimestamp || currentLength != upToDateLength) {
                scheduleUpdateContent(file);
            }
        }
        boolean currentWritable = persistence.isWritable(file);
        boolean upToDateWritable = attributes.isWritable();
        if (LOG_ATTRIBUTES.isDebugEnabled()) {
            LOG_ATTRIBUTES.debug("file=" + file + " writable vfs=" + file.isWritable() + " persistence=" + currentWritable + " real=" + upToDateWritable);
        }
        if (currentWritable != upToDateWritable) {
            scheduleAttributeChange(file, VirtualFile.PROP_WRITABLE, currentWritable, upToDateWritable);
        }
        if (SystemInfo.isWindows) {
            boolean currentHidden = file.is(VFileProperty.HIDDEN);
            boolean upToDateHidden = attributes.isHidden();
            if (currentHidden != upToDateHidden) {
                scheduleAttributeChange(file, VirtualFile.PROP_HIDDEN, currentHidden, upToDateHidden);
            }
        }
        if (attributes.isSymLink()) {
            String currentTarget = file.getCanonicalPath();
            String upToDateTarget = fs.resolveSymLink(file);
            String upToDateVfsTarget = upToDateTarget != null ? FileUtil.toSystemIndependentName(upToDateTarget) : null;
            if (!Comparing.equal(currentTarget, upToDateVfsTarget)) {
                scheduleAttributeChange(file, VirtualFile.PROP_SYMLINK_TARGET, currentTarget, upToDateVfsTarget);
            }
        }
        if (myIsRecursive || !file.isDirectory()) {
            file.markClean();
        }
    }
}
Also used : VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) FileAttributes(com.intellij.openapi.util.io.FileAttributes)

Aggregations

VirtualDirectoryImpl (com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)2 VirtualFileImpl (com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl)2 ArrayList (java.util.ArrayList)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 FileAttributes (com.intellij.openapi.util.io.FileAttributes)1 PsiFile (com.intellij.psi.PsiFile)1 Lesson (com.jetbrains.edu.learning.courseFormat.Lesson)1 Task (com.jetbrains.edu.learning.courseFormat.Task)1 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)1 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)1