Search in sources :

Example 11 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class CCDeleteAllAnswerPlaceholdersAction method update.

@Override
public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    presentation.setEnabledAndVisible(false);
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    if (!CCUtils.isCourseCreator(project)) {
        return;
    }
    DataContext context = e.getDataContext();
    VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
    if (file == null) {
        return;
    }
    TaskFile taskFile = StudyUtils.getTaskFile(project, file);
    if (taskFile == null || taskFile.getAnswerPlaceholders().isEmpty()) {
        return;
    }
    presentation.setEnabledAndVisible(true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 12 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class CCDeleteAllAnswerPlaceholdersAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext context = e.getDataContext();
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
    final Project project = e.getProject();
    if (file == null || project == null) {
        return;
    }
    final TaskFile taskFile = StudyUtils.getTaskFile(project, file);
    if (taskFile == null) {
        return;
    }
    Editor editor = CommonDataKeys.EDITOR.getData(context);
    if (editor == null) {
        FileEditorManager instance = FileEditorManager.getInstance(project);
        if (!instance.isFileOpen(file)) {
            return;
        }
        FileEditor fileEditor = instance.getSelectedEditor(file);
        if (!(fileEditor instanceof TextEditor)) {
            return;
        }
        editor = ((TextEditor) fileEditor).getEditor();
    }
    List<AnswerPlaceholder> placeholders = new ArrayList<>(taskFile.getAnswerPlaceholders());
    final ClearPlaceholders action = new ClearPlaceholders(taskFile, placeholders, editor);
    EduUtils.runUndoableAction(project, ACTION_NAME, action, UndoConfirmationPolicy.REQUEST_CONFIRMATION);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) DataContext(com.intellij.openapi.actionSystem.DataContext) FileEditor(com.intellij.openapi.fileEditor.FileEditor) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ArrayList(java.util.ArrayList) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 13 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class CCDeleteAnswerPlaceholder method deletePlaceholder.

private static void deletePlaceholder(@NotNull CCState state) {
    Project project = state.getProject();
    TaskFile taskFile = state.getTaskFile();
    AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
    EduUtils.runUndoableAction(project, "Delete Answer Placeholder", new CCAddAnswerPlaceholder.AddAction(answerPlaceholder, taskFile, state.getEditor()) {

        @Override
        public void undo() throws UnexpectedUndoException {
            super.redo();
        }

        @Override
        public void redo() throws UnexpectedUndoException {
            super.undo();
        }
    });
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) UnexpectedUndoException(com.intellij.openapi.command.undo.UnexpectedUndoException)

Example 14 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class StudyFillPlaceholdersAction method update.

@Override
public void update(AnActionEvent e) {
    StudyUtils.updateAction(e);
    final Project project = e.getProject();
    if (project != null) {
        Course course = StudyTaskManager.getInstance(project).getCourse();
        Presentation presentation = e.getPresentation();
        if (course != null && !EduNames.STUDY.equals(course.getCourseMode())) {
            presentation.setEnabled(false);
            presentation.setVisible(true);
            return;
        }
        StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
        StudyState studyState = new StudyState(studyEditor);
        if (!studyState.isValid()) {
            presentation.setEnabledAndVisible(false);
            return;
        }
        TaskFile taskFile = studyState.getTaskFile();
        if (taskFile.getActivePlaceholders().isEmpty()) {
            presentation.setEnabledAndVisible(false);
        }
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) StudyState(com.jetbrains.edu.learning.StudyState) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Course(com.jetbrains.edu.learning.courseFormat.Course) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 15 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class StudyFillPlaceholdersAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project != null) {
        StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
        StudyState studyState = new StudyState(studyEditor);
        if (!studyState.isValid()) {
            return;
        }
        TaskFile taskFile = studyState.getTaskFile();
        final Document document = studyState.getEditor().getDocument();
        for (AnswerPlaceholder placeholder : taskFile.getActivePlaceholders()) {
            String answer = placeholder.getPossibleAnswer();
            if (answer == null) {
                continue;
            }
            EduUtils.replaceAnswerPlaceholder(document, placeholder, placeholder.getRealLength(), answer);
        }
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) StudyState(com.jetbrains.edu.learning.StudyState) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Document(com.intellij.openapi.editor.Document)

Aggregations

TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)30 Project (com.intellij.openapi.project.Project)14 Editor (com.intellij.openapi.editor.Editor)11 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)11 Map (java.util.Map)10 Course (com.jetbrains.edu.learning.courseFormat.Course)9 Task (com.jetbrains.edu.learning.courseFormat.Task)8 Document (com.intellij.openapi.editor.Document)7 PsiFile (com.intellij.psi.PsiFile)7 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)7 File (java.io.File)6 Nullable (org.jetbrains.annotations.Nullable)6 FileEditor (com.intellij.openapi.fileEditor.FileEditor)5 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)4 Lesson (com.jetbrains.edu.learning.courseFormat.Lesson)4 Presentation (com.intellij.openapi.actionSystem.Presentation)3 EduDocumentListener (com.jetbrains.edu.learning.core.EduDocumentListener)3 AnswerPlaceholderSubtaskInfo (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo)3 ExecutionException (com.intellij.execution.ExecutionException)2