mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
renamed taswk windows to answer placeholders
This commit is contained in:
@@ -58,10 +58,10 @@
|
||||
<action id="AddTaskWindow" class="com.jetbrains.edu.coursecreator.actions.CCAddAnswerPlaceholder">
|
||||
<add-to-group group-id="EditorPopupMenu" anchor="before" relative-to-action="CopyReference"/>
|
||||
</action>
|
||||
<action id="ShowTaskWindowDetails" class="com.jetbrains.edu.coursecreator.actions.CCShowTaskWindowDetails">
|
||||
<action id="ShowTaskWindowDetails" class="com.jetbrains.edu.coursecreator.actions.CCShowAnswerPlaceholderDetails">
|
||||
<add-to-group group-id="EditorPopupMenu" anchor="before" relative-to-action="CopyReference"/>
|
||||
</action>
|
||||
<action id="DeleteTaskWindow" class="com.jetbrains.edu.coursecreator.actions.CCDeleteTaskWindow">
|
||||
<action id="DeleteTaskWindow" class="com.jetbrains.edu.coursecreator.actions.CCDeleteAnswerPlaceholder">
|
||||
<add-to-group group-id="EditorPopupMenu" anchor="before" relative-to-action="CopyReference"/>
|
||||
</action>
|
||||
<action id="ShowPreview" class="com.jetbrains.edu.coursecreator.actions.CCShowPreview">
|
||||
|
||||
+10
-10
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class CCDocumentListener extends DocumentAdapter {
|
||||
private final TaskFile myTaskFile;
|
||||
private final List<TaskWindowWrapper> myTaskWindows = new ArrayList<TaskWindowWrapper>();
|
||||
private final List<AnswerPlaceholedrWrapper> myAnswerPlaceholders = new ArrayList<AnswerPlaceholedrWrapper>();
|
||||
|
||||
|
||||
public CCDocumentListener(TaskFile taskFile) {
|
||||
@@ -30,12 +30,12 @@ public abstract class CCDocumentListener extends DocumentAdapter {
|
||||
@Override
|
||||
public void beforeDocumentChange(DocumentEvent e) {
|
||||
Document document = e.getDocument();
|
||||
myTaskWindows.clear();
|
||||
myAnswerPlaceholders.clear();
|
||||
for (AnswerPlaceholder answerPlaceholder : myTaskFile.getAnswerPlaceholders()) {
|
||||
int twStart = answerPlaceholder.getRealStartOffset(document);
|
||||
int length = useLength() ? answerPlaceholder.getLength() : answerPlaceholder.getPossibleAnswerLength();
|
||||
int twEnd = twStart + length;
|
||||
myTaskWindows.add(new TaskWindowWrapper(answerPlaceholder, twStart, twEnd));
|
||||
myAnswerPlaceholders.add(new AnswerPlaceholedrWrapper(answerPlaceholder, twStart, twEnd));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,16 +46,16 @@ public abstract class CCDocumentListener extends DocumentAdapter {
|
||||
Document document = e.getDocument();
|
||||
int offset = e.getOffset();
|
||||
int change = event.getNewLength() - event.getOldLength();
|
||||
for (TaskWindowWrapper taskWindowWrapper : myTaskWindows) {
|
||||
int twStart = taskWindowWrapper.getTwStart();
|
||||
for (AnswerPlaceholedrWrapper answerPlaceholedrWrapper : myAnswerPlaceholders) {
|
||||
int twStart = answerPlaceholedrWrapper.getTwStart();
|
||||
if (twStart > offset) {
|
||||
twStart += change;
|
||||
}
|
||||
int twEnd = taskWindowWrapper.getTwEnd();
|
||||
int twEnd = answerPlaceholedrWrapper.getTwEnd();
|
||||
if (twEnd >= offset) {
|
||||
twEnd += change;
|
||||
}
|
||||
AnswerPlaceholder answerPlaceholder = taskWindowWrapper.getAnswerPlaceholder();
|
||||
AnswerPlaceholder answerPlaceholder = answerPlaceholedrWrapper.getAnswerPlaceholder();
|
||||
int line = document.getLineNumber(twStart);
|
||||
int start = twStart - document.getLineStartOffset(line);
|
||||
int length = twEnd - twStart;
|
||||
@@ -64,7 +64,7 @@ public abstract class CCDocumentListener extends DocumentAdapter {
|
||||
if (useLength()) {
|
||||
answerPlaceholder.setLength(length);
|
||||
} else {
|
||||
answerPlaceholder.setPossibleAnswer(document.getText(TextRange.create(start, start + length )));
|
||||
answerPlaceholder.setPossibleAnswer(document.getText(TextRange.create(start, start + length)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,12 +72,12 @@ public abstract class CCDocumentListener extends DocumentAdapter {
|
||||
|
||||
protected abstract boolean useLength();
|
||||
|
||||
private static class TaskWindowWrapper {
|
||||
private static class AnswerPlaceholedrWrapper {
|
||||
public AnswerPlaceholder myAnswerPlaceholder;
|
||||
public int myTwStart;
|
||||
public int myTwEnd;
|
||||
|
||||
public TaskWindowWrapper(AnswerPlaceholder answerPlaceholder, int twStart, int twEnd) {
|
||||
public AnswerPlaceholedrWrapper(AnswerPlaceholder answerPlaceholder, int twStart, int twEnd) {
|
||||
myAnswerPlaceholder = answerPlaceholder;
|
||||
myTwStart = twStart;
|
||||
myTwEnd = twEnd;
|
||||
|
||||
+3
-3
@@ -9,9 +9,9 @@ import com.intellij.openapi.editor.event.EditorFactoryListener;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.edu.EduAnswerPlaceholderDeleteHandler;
|
||||
import com.jetbrains.edu.EduAnswerPlaceholderPainter;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduTaskWindowDeleteHandler;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.TaskFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -47,8 +47,8 @@ public class CCEditorFactoryListener implements EditorFactoryListener {
|
||||
CCProjectService.addDocumentListener(editor.getDocument(), listener);
|
||||
editor.getDocument().addDocumentListener(listener);
|
||||
EditorActionManager.getInstance()
|
||||
.setReadonlyFragmentModificationHandler(editor.getDocument(), new EduTaskWindowDeleteHandler(editor));
|
||||
service.drawTaskWindows(virtualFile, editor);
|
||||
.setReadonlyFragmentModificationHandler(editor.getDocument(), new EduAnswerPlaceholderDeleteHandler(editor));
|
||||
service.drawAnswerPlaceholders(virtualFile, editor);
|
||||
editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
|
||||
EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, false);
|
||||
}
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ public class CCProjectService implements PersistentStateComponent<CCProjectServi
|
||||
return task.getTaskFile(fileName);
|
||||
}
|
||||
|
||||
public void drawTaskWindows(@NotNull final VirtualFile virtualFile, @NotNull final Editor editor) {
|
||||
public void drawAnswerPlaceholders(@NotNull final VirtualFile virtualFile, @NotNull final Editor editor) {
|
||||
TaskFile taskFile = getTaskFile(virtualFile);
|
||||
if (taskFile == null) {
|
||||
return;
|
||||
|
||||
+5
-5
@@ -20,7 +20,7 @@ import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.coursecreator.CCProjectService;
|
||||
import com.jetbrains.edu.coursecreator.ui.CreateTaskWindowDialog;
|
||||
import com.jetbrains.edu.coursecreator.ui.CCCreateAnswerPlaceholderDialog;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -33,7 +33,7 @@ public class CCAddAnswerPlaceholder extends DumbAwareAction {
|
||||
}
|
||||
|
||||
|
||||
private static boolean areTaskWindowsIntersect(@NotNull final TaskFile taskFile, @NotNull final Document document, int start, int end) {
|
||||
private static boolean arePlaceholdersIntersect(@NotNull final TaskFile taskFile, @NotNull final Document document, int start, int end) {
|
||||
List<AnswerPlaceholder> answerPlaceholders = taskFile.getAnswerPlaceholders();
|
||||
for (AnswerPlaceholder existingAnswerPlaceholder : answerPlaceholders) {
|
||||
int twStart = existingAnswerPlaceholder.getRealStartOffset(document);
|
||||
@@ -75,7 +75,7 @@ public class CCAddAnswerPlaceholder extends DumbAwareAction {
|
||||
if (taskFile == null) {
|
||||
return;
|
||||
}
|
||||
if (areTaskWindowsIntersect(taskFile, document, start, end)) {
|
||||
if (arePlaceholdersIntersect(taskFile, document, start, end)) {
|
||||
return;
|
||||
}
|
||||
final AnswerPlaceholder answerPlaceholder = new AnswerPlaceholder();
|
||||
@@ -83,7 +83,7 @@ public class CCAddAnswerPlaceholder extends DumbAwareAction {
|
||||
answerPlaceholder.setStart(realStart);
|
||||
answerPlaceholder.setPossibleAnswer(model.getSelectedText());
|
||||
|
||||
CreateTaskWindowDialog dlg = new CreateTaskWindowDialog(project, answerPlaceholder, lesson.getIndex(),
|
||||
CCCreateAnswerPlaceholderDialog dlg = new CCCreateAnswerPlaceholderDialog(project, answerPlaceholder, lesson.getIndex(),
|
||||
task.getIndex(), file.getVirtualFile().getNameWithoutExtension(),
|
||||
taskFile.getAnswerPlaceholders().size() + 1);
|
||||
dlg.show();
|
||||
@@ -150,7 +150,7 @@ public class CCAddAnswerPlaceholder extends DumbAwareAction {
|
||||
presentation.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
if (areTaskWindowsIntersect(taskFile, editor.getDocument(), start, end)) {
|
||||
if (arePlaceholdersIntersect(taskFile, editor.getDocument(), start, end)) {
|
||||
presentation.setVisible(false);
|
||||
presentation.setEnabled(false);
|
||||
return;
|
||||
|
||||
+4
-4
@@ -16,9 +16,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
abstract public class CCTaskWindowAction extends DumbAwareAction {
|
||||
abstract public class CCAnswerPlaceholderAction extends DumbAwareAction {
|
||||
|
||||
protected CCTaskWindowAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
|
||||
protected CCAnswerPlaceholderAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
|
||||
super(text, description, icon);
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ abstract public class CCTaskWindowAction extends DumbAwareAction {
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
performTaskWindowAction(state);
|
||||
performAnswerPlaceholderAction(state);
|
||||
}
|
||||
|
||||
protected abstract void performTaskWindowAction(@NotNull final CCState state);
|
||||
protected abstract void performAnswerPlaceholderAction(@NotNull final CCState state);
|
||||
|
||||
protected static class CCState {
|
||||
private TaskFile myTaskFile;
|
||||
+4
-4
@@ -154,7 +154,7 @@ public class CCCreateCourseArchive extends DumbAwareAction {
|
||||
Collections.sort(taskFile.getAnswerPlaceholders(), new AnswerPlaceholderComparator());
|
||||
for (int i = taskFile.getAnswerPlaceholders().size() - 1; i >= 0; i--) {
|
||||
final AnswerPlaceholder answerPlaceholder = taskFile.getAnswerPlaceholders().get(i);
|
||||
replaceTaskWindow(project, document, answerPlaceholder);
|
||||
replaceAnswerPlaceholder(project, document, answerPlaceholder);
|
||||
}
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
@Override
|
||||
@@ -170,9 +170,9 @@ public class CCCreateCourseArchive extends DumbAwareAction {
|
||||
document.removeDocumentListener(listener);
|
||||
}
|
||||
|
||||
private static void replaceTaskWindow(@NotNull final Project project,
|
||||
@NotNull final Document document,
|
||||
@NotNull final AnswerPlaceholder answerPlaceholder) {
|
||||
private static void replaceAnswerPlaceholder(@NotNull final Project project,
|
||||
@NotNull final Document document,
|
||||
@NotNull final AnswerPlaceholder answerPlaceholder) {
|
||||
final String taskText = answerPlaceholder.getTaskText();
|
||||
final int lineStartOffset = document.getLineStartOffset(answerPlaceholder.getLine());
|
||||
final int offset = lineStartOffset + answerPlaceholder.getStart();
|
||||
|
||||
+4
-4
@@ -13,14 +13,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CCDeleteTaskWindow extends CCTaskWindowAction {
|
||||
public class CCDeleteAnswerPlaceholder extends CCAnswerPlaceholderAction {
|
||||
|
||||
public CCDeleteTaskWindow() {
|
||||
public CCDeleteAnswerPlaceholder() {
|
||||
super("Delete Answer Placeholder","Delete answer placeholder", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performTaskWindowAction(@NotNull CCState state) {
|
||||
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
|
||||
Project project = state.getProject();
|
||||
PsiFile psiFile = state.getFile();
|
||||
final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
|
||||
@@ -32,7 +32,7 @@ public class CCDeleteTaskWindow extends CCTaskWindowAction {
|
||||
answerPlaceholders.remove(answerPlaceholder);
|
||||
final Editor editor = state.getEditor();
|
||||
editor.getMarkupModel().removeAllHighlighters();
|
||||
CCProjectService.getInstance(project).drawTaskWindows(psiFile.getVirtualFile(), editor);
|
||||
CCProjectService.getInstance(project).drawAnswerPlaceholders(psiFile.getVirtualFile(), editor);
|
||||
EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, false);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -8,17 +8,17 @@ import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.coursecreator.CCProjectService;
|
||||
import com.jetbrains.edu.coursecreator.ui.CreateTaskWindowDialog;
|
||||
import com.jetbrains.edu.coursecreator.ui.CCCreateAnswerPlaceholderDialog;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CCShowTaskWindowDetails extends CCTaskWindowAction {
|
||||
public class CCShowAnswerPlaceholderDetails extends CCAnswerPlaceholderAction {
|
||||
|
||||
public CCShowTaskWindowDetails() {
|
||||
public CCShowAnswerPlaceholderDetails() {
|
||||
super("Edit Answer Placeholder", "Edit answer placeholder", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performTaskWindowAction(@NotNull CCState state) {
|
||||
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
|
||||
final Project project = state.getProject();
|
||||
final CCProjectService service = CCProjectService.getInstance(project);
|
||||
PsiFile file = state.getFile();
|
||||
@@ -29,7 +29,7 @@ public class CCShowTaskWindowDetails extends CCTaskWindowAction {
|
||||
final Task task = service.getTask(taskDir.getVirtualFile().getPath());
|
||||
final TaskFile taskFile = state.getTaskFile();
|
||||
AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
|
||||
CreateTaskWindowDialog dlg = new CreateTaskWindowDialog(project, answerPlaceholder, lesson.getIndex(), task.getIndex(),
|
||||
CCCreateAnswerPlaceholderDialog dlg = new CCCreateAnswerPlaceholderDialog(project, answerPlaceholder, lesson.getIndex(), task.getIndex(),
|
||||
file.getVirtualFile().getNameWithoutExtension(),
|
||||
taskFile.getAnswerPlaceholders().size() + 1);
|
||||
dlg.setTitle("Edit Answer Placeholder");
|
||||
+13
-11
@@ -11,31 +11,33 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class CreateTaskWindowDialog extends DialogWrapper {
|
||||
public class CCCreateAnswerPlaceholderDialog extends DialogWrapper {
|
||||
|
||||
private static final String ourTitle = "Add Answer Placeholder";
|
||||
private final AnswerPlaceholder myAnswerPlaceholder;
|
||||
private final CreateTaskWindowPanel myPanel;
|
||||
private final CCCreateAnswerPlaceholderPanel myPanel;
|
||||
private final Project myProject;
|
||||
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
public CreateTaskWindowDialog(@NotNull final Project project, @NotNull final AnswerPlaceholder answerPlaceholder, int lessonIndex,
|
||||
int taskIndex, String taskFileName, int taskWindowIndex) {
|
||||
public CCCreateAnswerPlaceholderDialog(@NotNull final Project project,
|
||||
@NotNull final AnswerPlaceholder answerPlaceholder,
|
||||
int lessonIndex, int taskIndex, String taskFileName,
|
||||
int answerPlaceholderIndex) {
|
||||
super(project, true);
|
||||
setTitle(ourTitle);
|
||||
myAnswerPlaceholder = answerPlaceholder;
|
||||
myPanel = new CreateTaskWindowPanel(this);
|
||||
String generatedHintName = EduNames.LESSON + lessonIndex + EduNames.TASK + taskIndex + taskFileName + "_" + taskWindowIndex;
|
||||
myPanel = new CCCreateAnswerPlaceholderPanel(this);
|
||||
String generatedHintName = EduNames.LESSON + lessonIndex + EduNames.TASK + taskIndex + taskFileName + "_" + answerPlaceholderIndex;
|
||||
myPanel.setGeneratedHintName(generatedHintName);
|
||||
if (answerPlaceholder.getHint() != null) {
|
||||
setHintText(answerPlaceholder);
|
||||
}
|
||||
myProject = project;
|
||||
String taskWindowTaskText = answerPlaceholder.getTaskText();
|
||||
myPanel.setTaskWindowText(taskWindowTaskText != null ? taskWindowTaskText : "");
|
||||
String answerPlaceholderTaskText = answerPlaceholder.getTaskText();
|
||||
myPanel.setAnswerPlaceholderText(answerPlaceholderTaskText != null ? answerPlaceholderTaskText : "");
|
||||
String hintName = answerPlaceholder.getHint();
|
||||
myPanel.setHintText(hintName != null ? hintName : "");
|
||||
init();
|
||||
@@ -52,9 +54,9 @@ public class CreateTaskWindowDialog extends DialogWrapper {
|
||||
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
String taskWindowText = myPanel.getAnswerPlaceholderText();
|
||||
myAnswerPlaceholder.setTaskText(StringUtil.notNullize(taskWindowText));
|
||||
myAnswerPlaceholder.setLength(StringUtil.notNullize(taskWindowText).length());
|
||||
String answerPlaceholderText = myPanel.getAnswerPlaceholderText();
|
||||
myAnswerPlaceholder.setTaskText(StringUtil.notNullize(answerPlaceholderText));
|
||||
myAnswerPlaceholder.setLength(StringUtil.notNullize(answerPlaceholderText).length());
|
||||
myAnswerPlaceholder.setHint(myPanel.getHintText());
|
||||
super.doOKAction();
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.edu.coursecreator.ui.CreateTaskWindowPanel">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.edu.coursecreator.ui.CCCreateAnswerPlaceholderPanel">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
@@ -58,7 +58,7 @@
|
||||
<color color="-6709600"/>
|
||||
</border>
|
||||
<children>
|
||||
<component id="2e28f" class="javax.swing.JTextField" binding="myTaskWindowText">
|
||||
<component id="2e28f" class="javax.swing.JTextField" binding="myAnswerPlaceholderText">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
+9
-9
@@ -5,17 +5,17 @@ import java.awt.*;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
public class CreateTaskWindowPanel extends JPanel {
|
||||
public class CCCreateAnswerPlaceholderPanel extends JPanel {
|
||||
|
||||
private final CreateTaskWindowDialog myDialog;
|
||||
private final CCCreateAnswerPlaceholderDialog myDialog;
|
||||
private JPanel myPanel;
|
||||
private JTextArea myHintText;
|
||||
private JCheckBox myCreateHintCheckBox;
|
||||
private JLabel myHintTextLabel;
|
||||
private JTextField myTaskWindowText;
|
||||
private JTextField myAnswerPlaceholderText;
|
||||
private String myGeneratedHintName = "";
|
||||
|
||||
public CreateTaskWindowPanel(CreateTaskWindowDialog dialog) {
|
||||
public CCCreateAnswerPlaceholderPanel(CCCreateAnswerPlaceholderDialog dialog) {
|
||||
super(new BorderLayout());
|
||||
add(myPanel, BorderLayout.CENTER);
|
||||
myDialog = dialog;
|
||||
@@ -32,7 +32,7 @@ public class CreateTaskWindowPanel extends JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
myTaskWindowText.grabFocus();
|
||||
myAnswerPlaceholderText.grabFocus();
|
||||
}
|
||||
|
||||
private void enableHint(boolean isEnable) {
|
||||
@@ -40,8 +40,8 @@ public class CreateTaskWindowPanel extends JPanel {
|
||||
myHintTextLabel.setEnabled(isEnable);
|
||||
}
|
||||
|
||||
public void setTaskWindowText(String taskWindowText) {
|
||||
myTaskWindowText.setText(taskWindowText);
|
||||
public void setAnswerPlaceholderText(String answerPlaceholderText) {
|
||||
myAnswerPlaceholderText.setText(answerPlaceholderText);
|
||||
}
|
||||
|
||||
public void setHintText(String hintText) {
|
||||
@@ -49,7 +49,7 @@ public class CreateTaskWindowPanel extends JPanel {
|
||||
}
|
||||
|
||||
public String getAnswerPlaceholderText() {
|
||||
return myTaskWindowText.getText();
|
||||
return myAnswerPlaceholderText.getText();
|
||||
}
|
||||
|
||||
public String getHintText() {
|
||||
@@ -69,6 +69,6 @@ public class CreateTaskWindowPanel extends JPanel {
|
||||
}
|
||||
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myTaskWindowText;
|
||||
return myAnswerPlaceholderText;
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
*/
|
||||
public class StudyDocumentListener extends DocumentAdapter {
|
||||
private final TaskFile myTaskFile;
|
||||
private List<TaskWindowWrapper> myTaskWindows = new ArrayList<TaskWindowWrapper>();
|
||||
private List<AnswerPlaceholderWrapper> myAnswerPlaceholders = new ArrayList<AnswerPlaceholderWrapper>();
|
||||
|
||||
public StudyDocumentListener(@NotNull final TaskFile taskFile) {
|
||||
myTaskFile = taskFile;
|
||||
@@ -34,11 +34,11 @@ public class StudyDocumentListener extends DocumentAdapter {
|
||||
}
|
||||
myTaskFile.setHighlightErrors(true);
|
||||
final Document document = e.getDocument();
|
||||
myTaskWindows.clear();
|
||||
myAnswerPlaceholders.clear();
|
||||
for (AnswerPlaceholder answerPlaceholder : myTaskFile.getAnswerPlaceholders()) {
|
||||
int twStart = answerPlaceholder.getRealStartOffset(document);
|
||||
int twEnd = twStart + answerPlaceholder.getLength();
|
||||
myTaskWindows.add(new TaskWindowWrapper(answerPlaceholder, twStart, twEnd));
|
||||
myAnswerPlaceholders.add(new AnswerPlaceholderWrapper(answerPlaceholder, twStart, twEnd));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,16 +52,16 @@ public class StudyDocumentListener extends DocumentAdapter {
|
||||
final Document document = e.getDocument();
|
||||
int offset = e.getOffset();
|
||||
int change = event.getNewLength() - event.getOldLength();
|
||||
for (TaskWindowWrapper taskWindowWrapper : myTaskWindows) {
|
||||
int twStart = taskWindowWrapper.getTwStart();
|
||||
for (AnswerPlaceholderWrapper answerPlaceholderWrapper : myAnswerPlaceholders) {
|
||||
int twStart = answerPlaceholderWrapper.getTwStart();
|
||||
if (twStart > offset) {
|
||||
twStart += change;
|
||||
}
|
||||
int twEnd = taskWindowWrapper.getTwEnd();
|
||||
int twEnd = answerPlaceholderWrapper.getTwEnd();
|
||||
if (twEnd >= offset) {
|
||||
twEnd += change;
|
||||
}
|
||||
final AnswerPlaceholder answerPlaceholder = taskWindowWrapper.getAnswerPlaceholder();
|
||||
final AnswerPlaceholder answerPlaceholder = answerPlaceholderWrapper.getAnswerPlaceholder();
|
||||
int line = document.getLineNumber(twStart);
|
||||
int start = twStart - document.getLineStartOffset(line);
|
||||
int length = twEnd - twStart;
|
||||
@@ -72,12 +72,12 @@ public class StudyDocumentListener extends DocumentAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
private static class TaskWindowWrapper {
|
||||
private static class AnswerPlaceholderWrapper {
|
||||
public AnswerPlaceholder myAnswerPlaceholder;
|
||||
public int myTwStart;
|
||||
public int myTwEnd;
|
||||
|
||||
public TaskWindowWrapper(AnswerPlaceholder answerPlaceholder, int twStart, int twEnd) {
|
||||
public AnswerPlaceholderWrapper(AnswerPlaceholder answerPlaceholder, int twStart, int twEnd) {
|
||||
myAnswerPlaceholder = answerPlaceholder;
|
||||
myTwStart = twStart;
|
||||
myTwEnd = twEnd;
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ public class StudyTaskManager implements PersistentStateComponent<StudyTaskManag
|
||||
return JBColor.BLUE;
|
||||
}
|
||||
|
||||
public boolean hasFailedTaskWindows(@NotNull final TaskFile taskFile) {
|
||||
public boolean hasFailedAnswerPlaceholders(@NotNull final TaskFile taskFile) {
|
||||
return taskFile.getAnswerPlaceholders().size() > 0 && getStatus(taskFile) == StudyStatus.Failed;
|
||||
}
|
||||
@Nullable
|
||||
|
||||
+2
-2
@@ -27,9 +27,9 @@ import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.edu.EduAnswerPlaceholderDeleteHandler;
|
||||
import com.jetbrains.edu.EduAnswerPlaceholderPainter;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduTaskWindowDeleteHandler;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.*;
|
||||
import com.jetbrains.edu.learning.editor.StudyEditor;
|
||||
@@ -292,7 +292,7 @@ public class StudyUtils {
|
||||
}
|
||||
final Document document = editor.getDocument();
|
||||
EditorActionManager.getInstance()
|
||||
.setReadonlyFragmentModificationHandler(document, new EduTaskWindowDeleteHandler(editor));
|
||||
.setReadonlyFragmentModificationHandler(document, new EduAnswerPlaceholderDeleteHandler(editor));
|
||||
EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, true);
|
||||
editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
|
||||
}
|
||||
|
||||
+10
-10
@@ -90,7 +90,7 @@ public class StudyCheckAction extends DumbAwareAction {
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawAllTaskWindows(@NotNull final Project project, @NotNull final Task task, @NotNull final VirtualFile taskDir) {
|
||||
private static void drawAllPlaceholders(@NotNull final Project project, @NotNull final Task task, @NotNull final VirtualFile taskDir) {
|
||||
for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
TaskFile taskFile = entry.getValue();
|
||||
@@ -198,7 +198,7 @@ public class StudyCheckAction extends DumbAwareAction {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
StudyUtils.updateStudyToolWindow(project);
|
||||
drawAllTaskWindows(project, task, taskDir);
|
||||
drawAllPlaceholders(project, task, taskDir);
|
||||
ProjectView.getInstance(project).refresh();
|
||||
deleteWindowDescriptions(task, taskDir);
|
||||
selectedEditor.getCheckButton().setEnabled(true);
|
||||
@@ -261,7 +261,7 @@ public class StudyCheckAction extends DumbAwareAction {
|
||||
});
|
||||
}
|
||||
showTestResultPopUp(failedMessage, MessageType.ERROR.getPopupBackground(), project);
|
||||
navigateToFailedTaskWindow(studyState, task, taskDir, project);
|
||||
navigateToFailedPlaceholder(studyState, task, taskDir, project);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -269,20 +269,20 @@ public class StudyCheckAction extends DumbAwareAction {
|
||||
};
|
||||
}
|
||||
|
||||
private static void navigateToFailedTaskWindow(@NotNull final StudyState studyState,
|
||||
@NotNull final Task task,
|
||||
@NotNull final VirtualFile taskDir,
|
||||
@NotNull final Project project) {
|
||||
private static void navigateToFailedPlaceholder(@NotNull final StudyState studyState,
|
||||
@NotNull final Task task,
|
||||
@NotNull final VirtualFile taskDir,
|
||||
@NotNull final Project project) {
|
||||
TaskFile selectedTaskFile = studyState.getTaskFile();
|
||||
Editor editor = studyState.getEditor();
|
||||
TaskFile taskFileToNavigate = selectedTaskFile;
|
||||
VirtualFile fileToNavigate = studyState.getVirtualFile();
|
||||
final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
|
||||
if (!taskManager.hasFailedTaskWindows(selectedTaskFile)) {
|
||||
if (!taskManager.hasFailedAnswerPlaceholders(selectedTaskFile)) {
|
||||
for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
TaskFile taskFile = entry.getValue();
|
||||
if (taskManager.hasFailedTaskWindows(taskFile)) {
|
||||
if (taskManager.hasFailedAnswerPlaceholders(taskFile)) {
|
||||
taskFileToNavigate = taskFile;
|
||||
VirtualFile virtualFile = taskDir.findChild(name);
|
||||
if (virtualFile == null) {
|
||||
@@ -309,7 +309,7 @@ public class StudyCheckAction extends DumbAwareAction {
|
||||
}
|
||||
});
|
||||
|
||||
StudyNavigator.navigateToFirstFailedTaskWindow(editor, taskFileToNavigate);
|
||||
StudyNavigator.navigateToFirstFailedAnswerPlaceholder(editor, taskFileToNavigate);
|
||||
}
|
||||
|
||||
private void runSmartTestProcess(@NotNull final VirtualFile taskDir,
|
||||
|
||||
+3
-3
@@ -80,7 +80,7 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
|
||||
}
|
||||
});
|
||||
|
||||
StudyNavigator.navigateToFirstTaskWindow(editor, taskFile);
|
||||
StudyNavigator.navigateToFirstAnswerPlaceholder(editor, taskFile);
|
||||
showBalloon(project, "You can start again now", MessageType.INFO);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
|
||||
if (!resetDocument(project, document, taskFile, name)) {
|
||||
return false;
|
||||
}
|
||||
resetTaskWindows(taskFile, project);
|
||||
resetAnswerPlaceholders(taskFile, project);
|
||||
ProjectView.getInstance(project).refresh();
|
||||
StudyUtils.updateStudyToolWindow(project);
|
||||
return true;
|
||||
@@ -107,7 +107,7 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
|
||||
Disposer.register(project, balloon);
|
||||
}
|
||||
|
||||
private static void resetTaskWindows(TaskFile selectedTaskFile, Project project) {
|
||||
private static void resetAnswerPlaceholders(TaskFile selectedTaskFile, Project project) {
|
||||
final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
|
||||
for (AnswerPlaceholder answerPlaceholder : selectedTaskFile.getAnswerPlaceholders()) {
|
||||
answerPlaceholder.reset();
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ abstract public class StudyWindowNavigationAction extends DumbAwareAction {
|
||||
if (nextAnswerPlaceholder == null) {
|
||||
return;
|
||||
}
|
||||
StudyNavigator.navigateToTaskWindow(selectedEditor, nextAnswerPlaceholder, selectedTaskFile);
|
||||
StudyNavigator.navigateToAnswerPlaceholder(selectedEditor, nextAnswerPlaceholder, selectedTaskFile);
|
||||
selectedTaskFile.setSelectedAnswerPlaceholder(nextAnswerPlaceholder);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ public class StudyEditorFactoryListener implements EditorFactoryListener {
|
||||
if (openedFile != null) {
|
||||
final TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
|
||||
if (taskFile != null) {
|
||||
StudyNavigator.navigateToFirstTaskWindow(editor, taskFile);
|
||||
StudyNavigator.navigateToFirstAnswerPlaceholder(editor, taskFile);
|
||||
editor.addEditorMouseListener(new WindowSelectionListener(taskFile));
|
||||
StudyEditor.addDocumentListener(document, new StudyDocumentListener(taskFile));
|
||||
WolfTheProblemSolver.getInstance(project).clearProblems(openedFile);
|
||||
|
||||
+8
-8
@@ -60,7 +60,7 @@ public class StudyNavigator {
|
||||
return lesson.getCourse().getLessons().get(lesson.getIndex() - 1);
|
||||
}
|
||||
|
||||
public static void navigateToFirstFailedTaskWindow(@NotNull final Editor editor, @NotNull final TaskFile taskFile) {
|
||||
public static void navigateToFirstFailedAnswerPlaceholder(@NotNull final Editor editor, @NotNull final TaskFile taskFile) {
|
||||
final Project project = editor.getProject();
|
||||
if (project == null) return;
|
||||
for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
|
||||
@@ -68,26 +68,26 @@ public class StudyNavigator {
|
||||
if (status != StudyStatus.Failed) {
|
||||
continue;
|
||||
}
|
||||
navigateToTaskWindow(editor, answerPlaceholder, taskFile);
|
||||
navigateToAnswerPlaceholder(editor, answerPlaceholder, taskFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void navigateToTaskWindow(@NotNull final Editor editor, @NotNull final AnswerPlaceholder answerPlaceholder,
|
||||
@NotNull final TaskFile taskFile) {
|
||||
public static void navigateToAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder answerPlaceholder,
|
||||
@NotNull final TaskFile taskFile) {
|
||||
if (!answerPlaceholder.isValid(editor.getDocument())) {
|
||||
return;
|
||||
}
|
||||
taskFile.setSelectedAnswerPlaceholder(answerPlaceholder);
|
||||
LogicalPosition taskWindowStart = new LogicalPosition(answerPlaceholder.getLine(), answerPlaceholder.getStart());
|
||||
editor.getCaretModel().moveToLogicalPosition(taskWindowStart);
|
||||
LogicalPosition placeholderStart = new LogicalPosition(answerPlaceholder.getLine(), answerPlaceholder.getStart());
|
||||
editor.getCaretModel().moveToLogicalPosition(placeholderStart);
|
||||
}
|
||||
|
||||
|
||||
public static void navigateToFirstTaskWindow(@NotNull final Editor editor, @NotNull final TaskFile taskFile) {
|
||||
public static void navigateToFirstAnswerPlaceholder(@NotNull final Editor editor, @NotNull final TaskFile taskFile) {
|
||||
if (!taskFile.getAnswerPlaceholders().isEmpty()) {
|
||||
AnswerPlaceholder firstAnswerPlaceholder = StudyUtils.getFirst(taskFile.getAnswerPlaceholders());
|
||||
navigateToTaskWindow(editor, firstAnswerPlaceholder, taskFile);
|
||||
navigateToAnswerPlaceholder(editor, firstAnswerPlaceholder, taskFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -6,11 +6,11 @@ import com.intellij.openapi.editor.ReadOnlyFragmentModificationException;
|
||||
import com.intellij.openapi.editor.actionSystem.ReadonlyFragmentModificationHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EduTaskWindowDeleteHandler implements ReadonlyFragmentModificationHandler {
|
||||
public class EduAnswerPlaceholderDeleteHandler implements ReadonlyFragmentModificationHandler {
|
||||
|
||||
private final Editor myEditor;
|
||||
|
||||
public EduTaskWindowDeleteHandler(@NotNull final Editor editor) {
|
||||
public EduAnswerPlaceholderDeleteHandler(@NotNull final Editor editor) {
|
||||
myEditor = editor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user