Search in sources :

Example 11 with AnswerPlaceholder

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

the class CCChangePlaceholderVisibility method performAnswerPlaceholderAction.

@Override
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
    AnswerPlaceholder placeholder = state.getAnswerPlaceholder();
    if (placeholder == null) {
        return;
    }
    EduUtils.runUndoableAction(state.getProject(), getName(), new BasicUndoableAction(state.getEditor().getDocument()) {

        @Override
        public void undo() throws UnexpectedUndoException {
            setVisible(placeholder, isVisible(), state);
        }

        @Override
        public void redo() throws UnexpectedUndoException {
            setVisible(placeholder, !isVisible(), state);
        }
    }, UndoConfirmationPolicy.REQUEST_CONFIRMATION);
}
Also used : AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) UnexpectedUndoException(com.intellij.openapi.command.undo.UnexpectedUndoException) BasicUndoableAction(com.intellij.openapi.command.undo.BasicUndoableAction)

Example 12 with AnswerPlaceholder

use of com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder 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 AnswerPlaceholder

use of com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder 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 AnswerPlaceholder

use of com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder 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)

Example 15 with AnswerPlaceholder

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

the class CCSubtaskPlaceholderAction method performAnswerPlaceholderAction.

@Override
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
    Editor editor = state.getEditor();
    final int offset = editor.getCaretModel().getOffset();
    TaskFile taskFile = state.getTaskFile();
    int subtaskIndex = state.getTaskFile().getTask().getActiveSubtaskIndex();
    AnswerPlaceholder existingPlaceholder = StudyUtils.getAnswerPlaceholder(offset, taskFile.getAnswerPlaceholders());
    if (existingPlaceholder == null) {
        return;
    }
    AnswerPlaceholderSubtaskInfo info = getInfo(state, subtaskIndex, existingPlaceholder);
    if (info == null) {
        return;
    }
    EduUtils.runUndoableAction(state.getProject(), getTitle(), new BasicUndoableAction(state.getEditor().getDocument()) {

        @Override
        public void undo() throws UnexpectedUndoException {
            undoAction(existingPlaceholder, subtaskIndex, info);
            StudyUtils.drawAllAnswerPlaceholders(editor, taskFile);
        }

        @Override
        public void redo() throws UnexpectedUndoException {
            redoAction(existingPlaceholder, subtaskIndex, info);
            StudyUtils.drawAllAnswerPlaceholders(editor, taskFile);
        }
    });
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) AnswerPlaceholderSubtaskInfo(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo) UnexpectedUndoException(com.intellij.openapi.command.undo.UnexpectedUndoException) Editor(com.intellij.openapi.editor.Editor) BasicUndoableAction(com.intellij.openapi.command.undo.BasicUndoableAction)

Aggregations

AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)25 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)12 Document (com.intellij.openapi.editor.Document)9 Editor (com.intellij.openapi.editor.Editor)7 Project (com.intellij.openapi.project.Project)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 AnswerPlaceholderSubtaskInfo (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo)4 UnexpectedUndoException (com.intellij.openapi.command.undo.UnexpectedUndoException)3 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)3 TextRange (com.intellij.openapi.util.TextRange)3 PsiFile (com.intellij.psi.PsiFile)3 File (java.io.File)3 BasicUndoableAction (com.intellij.openapi.command.undo.BasicUndoableAction)2 StudyState (com.jetbrains.edu.learning.StudyState)2 EduDocumentListener (com.jetbrains.edu.learning.core.EduDocumentListener)2 Course (com.jetbrains.edu.learning.courseFormat.Course)2 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)2 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 Gson (com.google.gson.Gson)1