mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moved userTests to interactive-learning
This commit is contained in:
+32
-1
@@ -14,10 +14,14 @@ import com.intellij.util.containers.hash.HashMap;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import com.jetbrains.edu.courseFormat.*;
|
||||
import com.jetbrains.edu.learning.courseFormat.StudyStatus;
|
||||
import com.jetbrains.edu.learning.courseFormat.UserTest;
|
||||
import com.jetbrains.edu.learning.courseGeneration.StudyGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -37,6 +41,7 @@ import java.util.Map;
|
||||
public class StudyTaskManager implements PersistentStateComponent<StudyTaskManager>, DumbAware {
|
||||
private Course myCourse;
|
||||
public Map<AnswerPlaceholder, StudyStatus> myStudyStatusMap = new HashMap<AnswerPlaceholder, StudyStatus>();
|
||||
public Map<Task, List<UserTest>> myUserTests = new HashMap<Task, List<UserTest>>();
|
||||
|
||||
private StudyTaskManager() {
|
||||
}
|
||||
@@ -57,6 +62,33 @@ public class StudyTaskManager implements PersistentStateComponent<StudyTaskManag
|
||||
myStudyStatusMap.put(placeholder, status);
|
||||
}
|
||||
|
||||
public void addUserTest(@NotNull final Task task, UserTest userTest) {
|
||||
List<UserTest> userTests = myUserTests.get(task);
|
||||
if (userTests == null) {
|
||||
userTests = new ArrayList<UserTest>();
|
||||
myUserTests.put(task, userTests);
|
||||
}
|
||||
userTests.add(userTest);
|
||||
}
|
||||
|
||||
public void setUserTests(@NotNull final Task task, @NotNull final List<UserTest> userTests) {
|
||||
myUserTests.put(task, userTests);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<UserTest> getUserTests(@NotNull final Task task) {
|
||||
final List<UserTest> userTests = myUserTests.get(task);
|
||||
return userTests != null ? userTests : Collections.<UserTest>emptyList();
|
||||
}
|
||||
|
||||
public void removeUserTest(@NotNull final Task task, @NotNull final UserTest userTest) {
|
||||
final List<UserTest> userTests = myUserTests.get(task);
|
||||
if (userTests != null) {
|
||||
userTests.remove(userTest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setStatus(Task task, StudyStatus status) {
|
||||
for (TaskFile taskFile : task.getTaskFiles().values()) {
|
||||
setStatus(taskFile, status);
|
||||
@@ -130,7 +162,6 @@ public class StudyTaskManager implements PersistentStateComponent<StudyTaskManag
|
||||
public boolean hasFailedTaskWindows(@NotNull final TaskFile taskFile) {
|
||||
return taskFile.getAnswerPlaceholders().size() > 0 && getStatus(taskFile) == StudyStatus.Failed;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public StudyTaskManager getState() {
|
||||
|
||||
+20
-11
@@ -23,9 +23,9 @@ import com.intellij.util.PlatformIcons;
|
||||
import com.jetbrains.edu.StudyNames;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.courseFormat.UserTest;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.courseFormat.UserTest;
|
||||
import com.jetbrains.edu.learning.editor.StudyEditor;
|
||||
import com.jetbrains.edu.learning.ui.StudyTestContentPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -50,7 +50,7 @@ public class StudyEditInputAction extends DumbAwareAction {
|
||||
if (selectedEditor != null) {
|
||||
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
|
||||
final VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
|
||||
StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
|
||||
final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
|
||||
assert openedFile != null;
|
||||
TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
|
||||
assert taskFile != null;
|
||||
@@ -64,7 +64,7 @@ public class StudyEditInputAction extends DumbAwareAction {
|
||||
VirtualFile taskDir = openedFile.getParent();
|
||||
VirtualFile testsDir = taskDir.findChild(StudyNames.USER_TESTS);
|
||||
assert testsDir != null;
|
||||
UserTest userTest = createUserTest(testsDir, currentTask);
|
||||
UserTest userTest = createUserTest(testsDir, currentTask, studyTaskManager);
|
||||
userTest.setEditable(true);
|
||||
StudyTestContentPanel testContentPanel = new StudyTestContentPanel(userTest);
|
||||
TabInfo testTab = addTestTab(tabbedPane.getTabCount(), testContentPanel, currentTask, true);
|
||||
@@ -74,7 +74,8 @@ public class StudyEditInputAction extends DumbAwareAction {
|
||||
}
|
||||
}
|
||||
});
|
||||
List<UserTest> userTests = currentTask.getUserTests();
|
||||
|
||||
List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
|
||||
int i = 1;
|
||||
for (UserTest userTest : userTests) {
|
||||
String inputFileText = StudyUtils.getFileText(null, userTest.getInput(), false, "UTF-8");
|
||||
@@ -101,7 +102,7 @@ public class StudyEditInputAction extends DumbAwareAction {
|
||||
StudyEditor selectedStudyEditor = StudyEditor.getSelectedStudyEditor(project);
|
||||
assert selectedStudyEditor != null;
|
||||
hint.showInCenterOf(selectedStudyEditor.getComponent());
|
||||
hint.addListener(new HintClosedListener(currentTask));
|
||||
hint.addListener(new HintClosedListener(currentTask, studyTaskManager));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,9 +123,11 @@ public class StudyEditInputAction extends DumbAwareAction {
|
||||
StudyUtils.synchronize();
|
||||
}
|
||||
|
||||
private static UserTest createUserTest(@NotNull final VirtualFile testsDir, @NotNull final Task currentTask) {
|
||||
private static UserTest createUserTest(@NotNull final VirtualFile testsDir,
|
||||
@NotNull final Task currentTask,
|
||||
StudyTaskManager studyTaskManager) {
|
||||
UserTest userTest = new UserTest();
|
||||
List<UserTest> userTests = currentTask.getUserTests();
|
||||
List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
|
||||
int testNum = userTests.size() + 1;
|
||||
String inputName = StudyNames.USER_TEST_INPUT + testNum;
|
||||
File inputFile = new File(testsDir.getPath(), inputName);
|
||||
@@ -132,7 +135,7 @@ public class StudyEditInputAction extends DumbAwareAction {
|
||||
File outputFile = new File(testsDir.getPath(), outputName);
|
||||
userTest.setInput(inputFile.getPath());
|
||||
userTest.setOutput(outputFile.getPath());
|
||||
userTests.add(userTest);
|
||||
studyTaskManager.addUserTest(currentTask, userTest);
|
||||
return userTest;
|
||||
}
|
||||
|
||||
@@ -155,13 +158,16 @@ public class StudyEditInputAction extends DumbAwareAction {
|
||||
|
||||
private static class HintClosedListener extends JBPopupAdapter {
|
||||
private final Task myTask;
|
||||
private HintClosedListener(@NotNull final Task task) {
|
||||
private final StudyTaskManager myStudyTaskManager;
|
||||
|
||||
private HintClosedListener(@NotNull final Task task, StudyTaskManager studyTaskManager) {
|
||||
myTask = task;
|
||||
myStudyTaskManager = studyTaskManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed(LightweightWindowEvent event) {
|
||||
for (final UserTest userTest : myTask.getUserTests()) {
|
||||
for (final UserTest userTest : myStudyTaskManager.getUserTests(myTask)) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -206,7 +212,10 @@ public class StudyEditInputAction extends DumbAwareAction {
|
||||
} else {
|
||||
LOG.error("failed to delete user tests");
|
||||
}
|
||||
myTask.getUserTests().remove(userTest);
|
||||
final Project project = e.getProject();
|
||||
if (project != null) {
|
||||
StudyTaskManager.getInstance(project).removeUserTest(myTask, userTest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.jetbrains.edu.courseFormat;
|
||||
package com.jetbrains.edu.learning.courseFormat;
|
||||
|
||||
public class UserTest {
|
||||
private String input;
|
||||
+4
-1
@@ -36,8 +36,10 @@ import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.learning.StudyDocumentListener;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.actions.*;
|
||||
import com.jetbrains.edu.learning.courseFormat.UserTest;
|
||||
import icons.InteractiveLearningIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -204,7 +206,8 @@ public class StudyEditor implements TextEditor {
|
||||
myNextTaskButton = addButton(taskActionsPanel, StudyNextStudyTaskAction.ACTION_ID, AllIcons.Actions.Forward, StudyNextStudyTaskAction.SHORTCUT);
|
||||
myRefreshButton = addButton(taskActionsPanel, StudyRefreshTaskFileAction.ACTION_ID, AllIcons.Actions.Refresh, StudyRefreshTaskFileAction.SHORTCUT);
|
||||
final JButton myShowHintButton = addButton(taskActionsPanel, StudyShowHintAction.ACTION_ID, InteractiveLearningIcons.ShowHint, StudyShowHintAction.SHORTCUT);
|
||||
if (!taskFile.getTask().getUserTests().isEmpty()) {
|
||||
final List<UserTest> userTests = StudyTaskManager.getInstance(myProject).getUserTests(taskFile.getTask());
|
||||
if (!userTests.isEmpty()) {
|
||||
final JButton runButton = addButton(taskActionsPanel, StudyRunAction.ACTION_ID, AllIcons.General.Run, null);
|
||||
runButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package com.jetbrains.edu.learning.ui;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.jetbrains.edu.courseFormat.UserTest;
|
||||
import com.jetbrains.edu.learning.courseFormat.UserTest;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -7,9 +7,7 @@ import com.jetbrains.edu.StudyNames;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -24,8 +22,6 @@ public class Task {
|
||||
private String testsText;
|
||||
|
||||
@Transient private Lesson myLesson;
|
||||
private List<UserTest> userTests = new ArrayList<UserTest>();
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -59,20 +55,10 @@ public class Task {
|
||||
this.testsText = testsText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Map<String, TaskFile> getTaskFiles() {
|
||||
return taskFiles;
|
||||
}
|
||||
|
||||
public List<UserTest> getUserTests() {
|
||||
return userTests;
|
||||
}
|
||||
|
||||
public void setUserTests(@NotNull final List<UserTest> userTests) {
|
||||
this.userTests = userTests;
|
||||
}
|
||||
|
||||
public boolean isTaskFile(@NotNull final String fileName) {
|
||||
return taskFiles.get(fileName) != null;
|
||||
}
|
||||
@@ -105,4 +91,30 @@ public class Task {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Task task = (Task)o;
|
||||
|
||||
if (myIndex != task.myIndex) return false;
|
||||
if (name != null ? !name.equals(task.name) : task.name != null) return false;
|
||||
if (taskFiles != null ? !taskFiles.equals(task.taskFiles) : task.taskFiles != null) return false;
|
||||
if (text != null ? !text.equals(task.text) : task.text != null) return false;
|
||||
if (testsText != null ? !testsText.equals(task.testsText) : task.testsText != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + myIndex;
|
||||
result = 31 * result + (taskFiles != null ? taskFiles.hashCode() : 0);
|
||||
result = 31 * result + (text != null ? text.hashCode() : 0);
|
||||
result = 31 * result + (testsText != null ? testsText.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user