use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.
the class XsltDebuggerSession method openLocation.
@Nullable
public static Editor openLocation(Project project, @NotNull String uri, int lineNumber) {
try {
final VirtualFile file = VfsUtil.findFileByURL(new URI(uri).toURL());
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, lineNumber, 0);
descriptor.navigate(true);
return FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
} catch (MalformedURLException | URISyntaxException e) {
//To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
return null;
}
}
use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.
the class CCProjectComponent method transformFiles.
private static void transformFiles(Course course, Project project) {
List<VirtualFile> files = getAllAnswerTaskFiles(course, project);
for (VirtualFile answerFile : files) {
ApplicationManager.getApplication().runWriteAction(() -> {
String answerName = answerFile.getName();
String nameWithoutExtension = FileUtil.getNameWithoutExtension(answerName);
String name = FileUtil.getNameWithoutExtension(nameWithoutExtension) + "." + FileUtilRt.getExtension(answerName);
VirtualFile parent = answerFile.getParent();
VirtualFile file = parent.findChild(name);
try {
if (file != null) {
file.delete(CCProjectComponent.class);
}
VirtualFile windowsDescrFile = parent.findChild(FileUtil.getNameWithoutExtension(name) + EduNames.WINDOWS_POSTFIX);
if (windowsDescrFile != null) {
windowsDescrFile.delete(CCProjectComponent.class);
}
answerFile.rename(CCProjectComponent.class, name);
} catch (IOException e) {
LOG.error(e);
}
});
}
}
use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.
the class CCStudyActionListener method beforeCheck.
@Override
public void beforeCheck(AnActionEvent event) {
Project project = event.getProject();
if (project == null) {
return;
}
if (!CCUtils.isCourseCreator(project)) {
return;
}
VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(event.getDataContext());
if (virtualFile == null) {
return;
}
TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
if (taskFile == null) {
return;
}
Task task = taskFile.getTask();
VirtualFile taskDir = StudyUtils.getTaskDir(virtualFile);
if (taskDir == null) {
return;
}
CCUtils.updateResources(project, task, taskDir);
}
use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.
the class CCSubtaskChangeListener method subtaskChanged.
@Override
public void subtaskChanged(@NotNull Project project, @NotNull Task task, int oldSubtaskNumber, int newSubtaskNumber) {
VirtualFile taskDir = task.getTaskDir(project);
if (taskDir == null) {
return;
}
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
if (manager == null) {
return;
}
String testFileName = manager.getTestFileName();
if (newSubtaskNumber != 0) {
String nameWithoutExtension = FileUtil.getNameWithoutExtension(testFileName);
String extension = FileUtilRt.getExtension(testFileName);
testFileName = nameWithoutExtension + EduNames.SUBTASK_MARKER + newSubtaskNumber + "." + extension;
}
VirtualFile newTestFile = taskDir.findChild(testFileName);
if (newTestFile == null) {
return;
}
FileEditorManager editorManager = FileEditorManager.getInstance(project);
List<VirtualFile> testFiles = ContainerUtil.filter(taskDir.getChildren(), file -> CCUtils.isTestsFile(project, file) && editorManager.isFileOpen(file));
if (testFiles.isEmpty()) {
return;
}
Editor selectedTextEditor = editorManager.getSelectedTextEditor();
for (VirtualFile testFile : testFiles) {
editorManager.closeFile(testFile);
}
editorManager.openFile(newTestFile, true);
if (selectedTextEditor != null) {
reopenSelectedEditor(editorManager, selectedTextEditor);
}
}
use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.
the class CCUtils method updateHigherElements.
/**
* This method decreases index and updates directory names of
* all tasks/lessons that have higher index than specified object
*
* @param dirs directories that are used to get tasks/lessons
* @param getStudyItem function that is used to get task/lesson from VirtualFile. This function can return null
* @param threshold index is used as threshold
* @param prefix task or lesson directory name prefix
*/
public static void updateHigherElements(VirtualFile[] dirs, @NotNull final Function<VirtualFile, ? extends StudyItem> getStudyItem, final int threshold, final String prefix, final int delta) {
ArrayList<VirtualFile> dirsToRename = new ArrayList<>(Collections2.filter(Arrays.asList(dirs), new Predicate<VirtualFile>() {
@Override
public boolean apply(VirtualFile dir) {
final StudyItem item = getStudyItem.fun(dir);
if (item == null) {
return false;
}
int index = item.getIndex();
return index > threshold;
}
}));
Collections.sort(dirsToRename, (o1, o2) -> {
StudyItem item1 = getStudyItem.fun(o1);
StudyItem item2 = getStudyItem.fun(o2);
//if we delete some dir we should start increasing numbers in dir names from the end
return (-delta) * EduUtils.INDEX_COMPARATOR.compare(item1, item2);
});
for (final VirtualFile dir : dirsToRename) {
final StudyItem item = getStudyItem.fun(dir);
final int newIndex = item.getIndex() + delta;
item.setIndex(newIndex);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
dir.rename(this, prefix + newIndex);
} catch (IOException e) {
LOG.error(e);
}
}
});
}
}
Aggregations