Search in sources :

Example 6 with UnexpectedUndoException

use of com.intellij.openapi.command.undo.UnexpectedUndoException 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

UnexpectedUndoException (com.intellij.openapi.command.undo.UnexpectedUndoException)6 BasicUndoableAction (com.intellij.openapi.command.undo.BasicUndoableAction)3 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)3 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)2 GlobalUndoableAction (com.intellij.openapi.command.undo.GlobalUndoableAction)1 UndoableAction (com.intellij.openapi.command.undo.UndoableAction)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 AnswerPlaceholderSubtaskInfo (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo)1 THashSet (gnu.trove.THashSet)1 List (java.util.List)1 DClassElement (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement)1 DItemElement (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DItemElement)1 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)1