Search in sources :

Example 1 with StepNode

use of org.stepik.core.courseFormat.StepNode in project intellij-plugins by StepicOrg.

the class StepikSendAction method check.

private void check(@NotNull Project project) {
    logger.info("Start checking step");
    StudyNode<?, ?> selected = StepikProjectManager.getSelected(project);
    if (!(selected instanceof StepNode)) {
        logger.info("Stop checking step: step is null or is not StepNode ");
        return;
    }
    StepNode stepNode = (StepNode) selected;
    String title = "Checking Step: " + stepNode.getName();
    ProgressManager.getInstance().run(new Task.Backgroundable(project, title) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            StepikApiClient stepikApiClient = authAndGetStepikApiClient(true);
            if (!isAuthenticated()) {
                return;
            }
            Long submissionId = sendStep(stepikApiClient, project, stepNode);
            if (submissionId == null) {
                return;
            }
            Metrics.sendAction(project, stepNode, SUCCESSFUL);
            SendAction.checkStepStatus(project, stepikApiClient, stepNode, submissionId, indicator);
            logger.info(String.format("Finish checking step: id=%s", stepNode.getId()));
        }
    });
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) Task(com.intellij.openapi.progress.Task) StepNode(org.stepik.core.courseFormat.StepNode) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 2 with StepNode

use of org.stepik.core.courseFormat.StepNode 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()));
            }
        }
    });
}
Also used : SupportedLanguages(org.stepik.core.SupportedLanguages) StepNode(org.stepik.core.courseFormat.StepNode)

Example 3 with StepNode

use of org.stepik.core.courseFormat.StepNode in project intellij-plugins by StepicOrg.

the class AbstractStepAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    StepNode stepNode = getCurrentStep(e.getProject());
    e.getPresentation().setEnabled(stepNode != null && !stepNode.getWasDeleted());
}
Also used : StepNode(org.stepik.core.courseFormat.StepNode)

Example 4 with StepNode

use of org.stepik.core.courseFormat.StepNode in project intellij-plugins by StepicOrg.

the class OpenInBrowserAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    super.update(e);
    Presentation presentation = e.getPresentation();
    Project project = e.getProject();
    StepNode stepNode = getCurrentStep(project);
    if (stepNode == null) {
        presentation.setDescription(DESCRIPTION);
        return;
    }
    String link = getLink(project, stepNode);
    presentation.setDescription(link);
}
Also used : Project(com.intellij.openapi.project.Project) StepNode(org.stepik.core.courseFormat.StepNode) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 5 with StepNode

use of org.stepik.core.courseFormat.StepNode in project intellij-plugins by StepicOrg.

the class StepikResetStepAction method resetFile.

private static void resetFile(@Nullable final Project project) {
    StepNode stepNode = getCurrentCodeStepNode(project);
    if (stepNode == null) {
        return;
    }
    VirtualFile src = getOrCreateSrcDirectory(project, stepNode, true);
    if (src == null) {
        return;
    }
    String mainFileName = stepNode.getCurrentLang().getMainFileName();
    VirtualFile mainFile = src.findChild(mainFileName);
    if (mainFile != null) {
        FileDocumentManager documentManager = FileDocumentManager.getInstance();
        Document document = documentManager.getDocument(mainFile);
        if (document != null) {
            resetDocument(project, document, stepNode);
            if (!project.isDisposed()) {
                ProjectView.getInstance(project).refresh();
                WolfTheProblemSolver.getInstance(project).clearProblems(mainFile);
            }
            StepikProjectManager.updateSelection(project);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StepNode(org.stepik.core.courseFormat.StepNode) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document)

Aggregations

StepNode (org.stepik.core.courseFormat.StepNode)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 StudyNode (org.stepik.core.courseFormat.StudyNode)6 Project (com.intellij.openapi.project.Project)4 StepikApiClient (org.stepik.api.client.StepikApiClient)4 SupportedLanguages (org.stepik.core.SupportedLanguages)4 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)4 Document (com.intellij.openapi.editor.Document)3 File (java.io.File)3 NotNull (org.jetbrains.annotations.NotNull)3 Submission (org.stepik.api.objects.submissions.Submission)3 StepikProjectManager (org.stepik.core.StepikProjectManager)3 Presentation (com.intellij.openapi.actionSystem.Presentation)2 Application (com.intellij.openapi.application.Application)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 IOException (java.io.IOException)2