use of org.stepik.core.SupportedLanguages in project intellij-plugins by StepicOrg.
the class StudyToolWindow method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (stepNode == null) {
return;
}
SupportedLanguages language = (SupportedLanguages) languageBox.getSelectedItem();
if (language == null) {
return;
}
final StepNode targetNode = stepNode;
executor.execute(() -> {
final SupportedLanguages[] selectedLang = new SupportedLanguages[1];
ApplicationManager.getApplication().invokeAndWait(() -> selectedLang[0] = (SupportedLanguages) languageBox.getSelectedItem());
if (selectedLang[0] != null) {
ProgrammingLanguageUtils.switchProgrammingLanguage(project, targetNode, selectedLang[0]);
if (selectedLang[0] != targetNode.getCurrentLang()) {
ApplicationManager.getApplication().invokeLater(() -> languageBox.setSelectedItem(targetNode.getCurrentLang()));
}
}
});
}
use of org.stepik.core.SupportedLanguages in project intellij-plugins by StepicOrg.
the class ProgrammingLanguageUtils method switchProgrammingLanguage.
public static void switchProgrammingLanguage(@NotNull Project project, @NotNull StepNode targetStepNode, @NotNull SupportedLanguages language) {
if (!targetStepNode.getSupportedLanguages().contains(language)) {
return;
}
SupportedLanguages currentLang = targetStepNode.getCurrentLang();
String currentMainFileName = currentLang.getMainFileName();
String mainFilePath = String.join("/", targetStepNode.getPath(), EduNames.SRC, currentMainFileName);
VirtualFile mainFile = project.getBaseDir().findFileByRelativePath(mainFilePath);
boolean mainFileExists = mainFile != null;
if (currentLang == language && mainFileExists) {
return;
}
if (currentMainFileName.equals(language.getMainFileName()) && mainFileExists) {
targetStepNode.setCurrentLang(language);
Metrics.switchLanguage(project, targetStepNode, SUCCESSFUL);
return;
}
PsiDirectory src = getOrCreateSrcPsiDirectory(project, targetStepNode);
if (src == null) {
return;
}
PsiDirectory hide = getOrCreatePsiDirectory(project, src, EduNames.HIDE);
if (hide == null) {
return;
}
PsiFile second = findFile(src, language.getMainFileName());
boolean moveSecond = second == null;
if (moveSecond) {
second = getOrCreateMainFile(project, hide.getVirtualFile(), language, targetStepNode);
if (second == null) {
logger.error("Can't create Main file: " + language.getMainFileName());
return;
}
}
PsiFile first = findFile(hide, currentMainFileName);
boolean moveFirst = first == null;
if (moveFirst) {
first = findFile(src, currentMainFileName);
moveFirst = !second.isEquivalentTo(first);
}
targetStepNode.setCurrentLang(language);
ArrayList<VirtualFile> needClose = closeStepNodeFile(project, targetStepNode);
PsiFile finalSecond = second;
PsiFile finalFirst = first;
boolean finalMoveFirst = moveFirst;
ApplicationManager.getApplication().invokeAndWait(() -> {
FileEditorManager.getInstance(project).openFile(finalSecond.getVirtualFile(), true);
FileEditorManager editorManager = FileEditorManager.getInstance(project);
needClose.forEach(editorManager::closeFile);
exchangeFiles(src, hide, finalFirst, finalSecond, finalMoveFirst, moveSecond);
ProjectView.getInstance(project).selectPsiElement(finalSecond, false);
});
Metrics.switchLanguage(project, targetStepNode, SUCCESSFUL);
}
use of org.stepik.core.SupportedLanguages in project intellij-plugins by StepicOrg.
the class StepNode method getSupportedLanguages.
@NotNull
public List<SupportedLanguages> getSupportedLanguages() {
if (supportedLanguages == null) {
supportedLanguages = new ArrayList<>();
BlockView block;
Step data = getData();
if (data == null) {
return supportedLanguages;
}
block = data.getBlock();
if (getType() == StepType.CODE) {
BlockViewOptions options = block.getOptions();
Map<String, String> templates = options.getCodeTemplates();
templates.keySet().forEach(key -> {
SupportedLanguages language = SupportedLanguages.langOfName(key);
if (language != INVALID && !supportedLanguages.contains(language)) {
supportedLanguages.add(language);
}
});
}
}
return supportedLanguages;
}
use of org.stepik.core.SupportedLanguages in project intellij-plugins by StepicOrg.
the class StepikSendAction method getSubmissionId.
@Nullable
private static Long getSubmissionId(@NotNull Project project, @NotNull StepikApiClient stepikApiClient, @NotNull StepNode stepNode, long intAttemptId) {
SupportedLanguages currentLang = stepNode.getCurrentLang();
String code = getCode(project, stepNode, currentLang);
if (code == null) {
logger.info(String.format("Sending step failed: id=%s. Step content is null", stepNode.getId()));
return null;
}
Submissions submissions;
try {
submissions = stepikApiClient.submissions().post().attempt(intAttemptId).language(currentLang.getName()).code(code).execute();
if (submissions.isEmpty()) {
notifyFailed(project, stepNode, "Submissions is empty", null);
return null;
}
} catch (StepikClientException e) {
notifyFailed(project, stepNode, "Failed post submission", e);
return null;
}
return submissions.getFirst().getId();
}
use of org.stepik.core.SupportedLanguages in project intellij-plugins by StepicOrg.
the class JavaWizardStep method onWizardFinished.
@Override
public void onWizardFinished() throws CommitStepException {
if (!(valid && leaving)) {
return;
}
SupportedLanguages selectedLang = panel.getLanguage();
generator.setDefaultLang(selectedLang);
StudyObject studyObject = panel.getSelectedStudyObject();
generator.createCourseNodeUnderProgress(project, studyObject);
long id = studyObject.getId();
if (id == 0) {
return;
}
boolean wasEnrollment = ProjectWizardUtils.enrollmentCourse(studyObject);
if (wasEnrollment) {
logger.warn("User didn't enrollment on course: " + id);
}
String messageTemplate = "Leaving step the project wizard with the selected study object: type=%s, id = %s, name = %s";
logger.info(String.format(messageTemplate, studyObject.getClass().getSimpleName(), id, studyObject.getTitle()));
}
Aggregations