use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class CCUtils method updateResources.
public static void updateResources(Project project, Task task, VirtualFile taskDir) {
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
VirtualFile lessonVF = taskDir.getParent();
if (lessonVF == null) {
return;
}
String taskResourcesPath = FileUtil.join(course.getCourseDirectory(), lessonVF.getName(), taskDir.getName());
File taskResourceFile = new File(taskResourcesPath);
if (!taskResourceFile.exists()) {
if (!taskResourceFile.mkdirs()) {
LOG.info("Failed to create resources for task " + taskResourcesPath);
}
}
VirtualFile studentDir = LocalFileSystem.getInstance().findFileByIoFile(taskResourceFile);
if (studentDir == null) {
return;
}
for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
String name = entry.getKey();
VirtualFile answerFile = taskDir.findFileByRelativePath(name);
if (answerFile == null) {
continue;
}
ApplicationManager.getApplication().runWriteAction(() -> {
EduUtils.createStudentFile(CCUtils.class, project, answerFile, studentDir, null, task.getActiveSubtaskIndex());
});
}
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class CCVirtualFileListener method fileCreated.
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
VirtualFile createdFile = event.getFile();
if (createdFile.isDirectory()) {
return;
}
if (createdFile.getPath().contains(CCUtils.GENERATED_FILES_FOLDER)) {
return;
}
Project project = ProjectUtil.guessProjectForFile(createdFile);
if (project == null) {
return;
}
if (project.getBasePath() != null && !FileUtil.isAncestor(project.getBasePath(), createdFile.getPath(), true)) {
return;
}
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null || !CCUtils.isCourseCreator(project)) {
return;
}
TaskFile taskFile = StudyUtils.getTaskFile(project, createdFile);
if (taskFile != null) {
return;
}
String taskRelativePath = StudyUtils.pathRelativeToTask(createdFile);
CCLanguageManager manager = CCUtils.getStudyLanguageManager(course);
if (manager != null && manager.doNotPackFile(new File(createdFile.getPath()))) {
return;
}
if (CCUtils.isTestsFile(project, createdFile) || StudyUtils.isTaskDescriptionFile(createdFile.getName()) || taskRelativePath.contains(EduNames.WINDOW_POSTFIX) || taskRelativePath.contains(EduNames.WINDOWS_POSTFIX) || taskRelativePath.contains(EduNames.ANSWERS_POSTFIX)) {
return;
}
VirtualFile taskVF = StudyUtils.getTaskDir(createdFile);
if (taskVF == null) {
return;
}
Task task = StudyUtils.getTask(project, taskVF);
if (task == null) {
return;
}
CCUtils.createResourceFile(createdFile, course, taskVF);
task.addTaskFile(taskRelativePath, 1);
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyEditInputAction method showInput.
public void showInput(final Project project) {
final Editor selectedEditor = StudyUtils.getSelectedEditor(project);
if (selectedEditor != null) {
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
final VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
assert openedFile != null;
TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
assert taskFile != null;
final Task currentTask = taskFile.getTask();
tabbedPane = new JBEditorTabs(project, ActionManager.getInstance(), IdeFocusManager.findInstance(), project);
tabbedPane.addListener(new TabsListener.Adapter() {
@Override
public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
if (newSelection.getIcon() != null) {
int tabCount = tabbedPane.getTabCount();
VirtualFile taskDir = StudyUtils.getTaskDir(openedFile);
VirtualFile testsDir = taskDir.findChild(EduNames.USER_TESTS);
assert testsDir != null;
UserTest userTest = createUserTest(testsDir, currentTask, studyTaskManager);
userTest.setEditable(true);
StudyTestContentPanel testContentPanel = new StudyTestContentPanel(userTest);
TabInfo testTab = addTestTab(tabbedPane.getTabCount(), testContentPanel, currentTask, true);
myEditableTabs.put(testTab, userTest);
tabbedPane.addTabSilently(testTab, tabCount - 1);
tabbedPane.select(testTab, true);
}
}
});
List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
int i = 1;
for (UserTest userTest : userTests) {
String inputFileText = StudyUtils.getFileText(null, userTest.getInput(), false, "UTF-8");
String outputFileText = StudyUtils.getFileText(null, userTest.getOutput(), false, "UTF-8");
StudyTestContentPanel myContentPanel = new StudyTestContentPanel(userTest);
myContentPanel.addInputContent(inputFileText);
myContentPanel.addOutputContent(outputFileText);
TabInfo testTab = addTestTab(i, myContentPanel, currentTask, userTest.isEditable());
tabbedPane.addTabSilently(testTab, i - 1);
if (userTest.isEditable()) {
myEditableTabs.put(testTab, userTest);
}
i++;
}
TabInfo plusTab = new TabInfo(new JPanel());
plusTab.setIcon(PlatformIcons.ADD_ICON);
tabbedPane.addTabSilently(plusTab, tabbedPane.getTabCount());
final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), tabbedPane.getComponent()).setResizable(true).setMovable(true).setRequestFocus(true).createPopup();
StudyEditor selectedStudyEditor = StudyUtils.getSelectedStudyEditor(project);
assert selectedStudyEditor != null;
hint.showInCenterOf(selectedStudyEditor.getComponent());
hint.addListener(new HintClosedListener(currentTask, studyTaskManager));
}
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyTypeHandlerDelegate method handleTyping.
@NotNull
private static Result handleTyping(Project project, Editor editor, PsiFile file) {
if (!StudyUtils.isStudentProject(project)) {
return Result.CONTINUE;
}
TaskFile taskFile = StudyUtils.getTaskFile(project, file.getVirtualFile());
if (taskFile == null || !taskFile.getTask().hasSubtasks()) {
return Result.CONTINUE;
}
int offset = editor.getCaretModel().getOffset();
boolean insidePlaceholder = taskFile.getAnswerPlaceholder(offset) != null;
if (!insidePlaceholder) {
HintManager.getInstance().showInformationHint(editor, "Text outside of placeholders is not editable in this task");
}
return insidePlaceholder ? Result.CONTINUE : Result.STOP;
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class CCSubtaskPlaceholderAction method update.
@Override
public void update(AnActionEvent e) {
Presentation presentation = e.getPresentation();
presentation.setEnabledAndVisible(false);
CCState state = getState(e);
if (state == null) {
return;
}
TaskFile taskFile = state.getTaskFile();
if (!taskFile.getTask().hasSubtasks()) {
return;
}
int offset = state.getEditor().getCaretModel().getOffset();
if (isAvailable(taskFile, offset)) {
presentation.setEnabledAndVisible(true);
}
}
Aggregations