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);
}
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);
}
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();
}
});
}
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);
}
}
}
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);
}
});
}
Aggregations