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);
}
}
}
}
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);
}
}
}
}
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;
}
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;
}
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();
}
}
}
Aggregations