use of com.jetbrains.edu.learning.courseFormat.UserTest in project intellij-community by JetBrains.
the class StudyRunAction method update.
@Override
public void update(AnActionEvent e) {
EduUtils.enableAction(e, false);
final Project project = e.getProject();
if (project != null) {
StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
if (studyEditor != null) {
final List<UserTest> userTests = StudyTaskManager.getInstance(project).getUserTests(studyEditor.getTaskFile().getTask());
if (!userTests.isEmpty()) {
EduUtils.enableAction(e, true);
}
}
}
}
use of com.jetbrains.edu.learning.courseFormat.UserTest in project intellij-community by JetBrains.
the class StudyEditInputAction method createUserTest.
private static UserTest createUserTest(@NotNull final VirtualFile testsDir, @NotNull final Task currentTask, StudyTaskManager studyTaskManager) {
UserTest userTest = new UserTest();
List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
int testNum = userTests.size() + 1;
String inputName = EduNames.USER_TEST_INPUT + testNum;
File inputFile = new File(testsDir.getPath(), inputName);
String outputName = EduNames.USER_TEST_OUTPUT + testNum;
File outputFile = new File(testsDir.getPath(), outputName);
userTest.setInput(inputFile.getPath());
userTest.setOutput(outputFile.getPath());
studyTaskManager.addUserTest(currentTask, userTest);
return userTest;
}
use of com.jetbrains.edu.learning.courseFormat.UserTest in project intellij-community by JetBrains.
the class StudyEditInputAction method update.
@Override
public void update(final AnActionEvent e) {
EduUtils.enableAction(e, false);
final Project project = e.getProject();
if (project != null) {
StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
if (studyEditor != null) {
final List<UserTest> userTests = StudyTaskManager.getInstance(project).getUserTests(studyEditor.getTaskFile().getTask());
if (!userTests.isEmpty()) {
EduUtils.enableAction(e, true);
}
}
}
}
use of com.jetbrains.edu.learning.courseFormat.UserTest in project intellij-community by JetBrains.
the class StudyEditInputAction method showInput.
public void showInput(final Project project) {
final Editor selectedEditor = StudyUtils.getSelectedEditor(project);
if (selectedEditor != null) {
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
final VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
assert openedFile != null;
TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
assert taskFile != null;
final Task currentTask = taskFile.getTask();
tabbedPane = new JBEditorTabs(project, ActionManager.getInstance(), IdeFocusManager.findInstance(), project);
tabbedPane.addListener(new TabsListener.Adapter() {
@Override
public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
if (newSelection.getIcon() != null) {
int tabCount = tabbedPane.getTabCount();
VirtualFile taskDir = StudyUtils.getTaskDir(openedFile);
VirtualFile testsDir = taskDir.findChild(EduNames.USER_TESTS);
assert testsDir != null;
UserTest userTest = createUserTest(testsDir, currentTask, studyTaskManager);
userTest.setEditable(true);
StudyTestContentPanel testContentPanel = new StudyTestContentPanel(userTest);
TabInfo testTab = addTestTab(tabbedPane.getTabCount(), testContentPanel, currentTask, true);
myEditableTabs.put(testTab, userTest);
tabbedPane.addTabSilently(testTab, tabCount - 1);
tabbedPane.select(testTab, true);
}
}
});
List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
int i = 1;
for (UserTest userTest : userTests) {
String inputFileText = StudyUtils.getFileText(null, userTest.getInput(), false, "UTF-8");
String outputFileText = StudyUtils.getFileText(null, userTest.getOutput(), false, "UTF-8");
StudyTestContentPanel myContentPanel = new StudyTestContentPanel(userTest);
myContentPanel.addInputContent(inputFileText);
myContentPanel.addOutputContent(outputFileText);
TabInfo testTab = addTestTab(i, myContentPanel, currentTask, userTest.isEditable());
tabbedPane.addTabSilently(testTab, i - 1);
if (userTest.isEditable()) {
myEditableTabs.put(testTab, userTest);
}
i++;
}
TabInfo plusTab = new TabInfo(new JPanel());
plusTab.setIcon(PlatformIcons.ADD_ICON);
tabbedPane.addTabSilently(plusTab, tabbedPane.getTabCount());
final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), tabbedPane.getComponent()).setResizable(true).setMovable(true).setRequestFocus(true).createPopup();
StudyEditor selectedStudyEditor = StudyUtils.getSelectedStudyEditor(project);
assert selectedStudyEditor != null;
hint.showInCenterOf(selectedStudyEditor.getComponent());
hint.addListener(new HintClosedListener(currentTask, studyTaskManager));
}
}
Aggregations