package com.jetbrains.edu.coursecreator.actions;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.edu.learning.StudyUtils;
import com.jetbrains.edu.learning.courseFormat.Course;
import com.jetbrains.edu.learning.courseFormat.Task;
import com.jetbrains.edu.learning.courseFormat.TaskFile;

import java.io.IOException;
import java.util.Map;

public class CCHideFromStudent extends CCTaskFileActionBase {

  private static final Logger LOG = Logger.getInstance(CCHideFromStudent.class);

  @Override
  protected void performAction(VirtualFile file, Task task, Course course, Project project) {
    Map<String, TaskFile> taskFiles = task.getTaskFiles();
    TaskFile taskFile = StudyUtils.getTaskFile(project, file);
    if (taskFile == null) {
      return;
    }
    String name = file.getName();
    VirtualFile patternFile = StudyUtils.getPatternFile(taskFile, name);
    ApplicationManager.getApplication().runWriteAction(() -> {
      if (patternFile != null) {
        try {
          patternFile.delete(CCHideFromStudent.class);
        }
        catch (IOException e) {
          LOG.info(e);
        }
      }
    });
    taskFiles.remove(name);
  }

  @Override
  protected boolean isAvailable(Project project, VirtualFile file) {
    return StudyUtils.getTaskFile(project, file) != null;
  }
}

@@ -146,24 +146,249 @@
 tic.Logger;%0A
+import com.intellij.openapi.editor.Editor;%0Aimport com.intellij.openapi.fileEditor.FileEditor;%0Aimport com.intellij.openapi.fileEditor.FileEditorManager;%0Aimport com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorImpl;%0A
 import com.i
@@ -1145,24 +1145,451 @@
 turn;%0A    %7D%0A
+    if (!taskFile.getAnswerPlaceholders().isEmpty() && FileEditorManager.getInstance(project).isFileOpen(file)) %7B%0A      for (FileEditor fileEditor : FileEditorManager.getInstance(project).getEditors(file)) %7B%0A        if (fileEditor instanceof PsiAwareTextEditorImpl) %7B%0A          Editor editor = ((PsiAwareTextEditorImpl)fileEditor).getEditor();%0A          editor.getMarkupModel().removeAllHighlighters();%0A        %7D%0A      %7D%0A    %7D%0A
     String n

remove placeholders if file was hidden from student