From 1607b588cdb9676e3ae0d459a53eb27d3ca94aa8 Mon Sep 17 00:00:00 2001 From: Valentina Kiryushkina Date: Mon, 15 May 2017 16:55:19 +0300 Subject: [PATCH 1/7] Use MessageBus to wait for authorization finished --- .../learning/stepic/StepicStudyOptions.java | 40 +++++-------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/python/educational-core/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.java b/python/educational-core/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.java index 25cc37c97b40..2142a072646f 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.java @@ -15,23 +15,19 @@ */ package com.jetbrains.edu.learning.stepic; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.project.DefaultProjectFactory; import com.intellij.ui.HoverHyperlinkLabel; import com.intellij.ui.HyperlinkAdapter; import com.intellij.ui.components.JBCheckBox; import com.intellij.ui.components.JBLabel; import com.jetbrains.edu.learning.StudySettings; -import com.jetbrains.edu.learning.StudyUtils; import com.jetbrains.edu.learning.settings.StudyOptionsProvider; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.HyperlinkEvent; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeUnit; public class StepicStudyOptions implements StudyOptionsProvider { private JPanel myPane; @@ -61,32 +57,16 @@ public class StepicStudyOptions implements StudyOptionsProvider { @Override protected void hyperlinkActivated(HyperlinkEvent e) { - StudySettings studySettings = StudySettings.getInstance(); - StepicUser oldUser = studySettings.getUser(); - EduStepicConnector.doAuthorize(() -> showDialog()); - - ProgressManager.getInstance() - .runProcessWithProgressSynchronously(() -> { - ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); - StudyUtils.execCancelable(waitForUserToBeSet(studySettings, oldUser)); - }, "Authorizing", - true, - DefaultProjectFactory.getInstance().getDefaultProject()); - } - - @NotNull - private Callable waitForUserToBeSet(StudySettings studySettings, StepicUser oldUser) { - return () -> { - StepicUser newUser = studySettings.getUser(); - while (newUser == null || newUser.equals(oldUser)) { - TimeUnit.MILLISECONDS.sleep(500); - newUser = studySettings.getUser(); + ApplicationManager.getApplication().getMessageBus().connect().subscribe(StudySettings.SETTINGS_CHANGED, () -> { + StepicUser user = StudySettings.getInstance().getUser(); + if (user != null && !user.equals(myStepicUser)) { + StudySettings.getInstance().setUser(myStepicUser); + myStepicUser = user; + updateLoginLabels(myStepicUser); } - StudySettings.getInstance().setUser(myStepicUser); - myStepicUser = newUser; - updateLoginLabels(myStepicUser); - return null; - }; + }); + + EduStepicConnector.doAuthorize(() -> showDialog()); } }; } From 5e9a479fd58cc8ba649289f1f89dd206c5989c62 Mon Sep 17 00:00:00 2001 From: Valentina Kiryushkina Date: Mon, 15 May 2017 17:02:00 +0300 Subject: [PATCH 2/7] Add stepik widget for educational projects only --- .../com/jetbrains/edu/learning/StudyProjectComponent.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/educational-core/src/com/jetbrains/edu/learning/StudyProjectComponent.java b/python/educational-core/src/com/jetbrains/edu/learning/StudyProjectComponent.java index 607343b87e07..85b5889ee1ca 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/StudyProjectComponent.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/StudyProjectComponent.java @@ -95,6 +95,7 @@ public class StudyProjectComponent implements ProjectComponent { instance.setHideToolStripes(false); instance.fireUISettingsChanged(); registerShortcuts(); + addStepicWidget(); EduUsagesCollector.projectTypeOpened(course.isAdaptive() ? EduNames.ADAPTIVE : EduNames.STUDY); } }))); @@ -110,6 +111,10 @@ public class StudyProjectComponent implements ProjectComponent { } }); + selectStep(); + } + + private void addStepicWidget() { StudyStepicUserWidget widget = StudyUtils.getStepicWidget(); if (widget == null) { StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject); @@ -118,8 +123,6 @@ public class StudyProjectComponent implements ProjectComponent { else { widget.update(); } - - selectStep(); } private void selectStep() { From be794cc71b5bc00e3a33920fc2280ca2c08e0255 Mon Sep 17 00:00:00 2001 From: Valentina Kiryushkina Date: Mon, 15 May 2017 18:48:56 +0300 Subject: [PATCH 3/7] Minor Change "Authorize on Stepik" to "Log in to Stepik" --- .../jetbrains/edu/coursecreator/stepik/CCStepicConnector.java | 4 ++-- .../edu/learning/builtInServer/EduStepikRestService.java | 4 ++-- .../edu/learning/stepic/EduAdaptiveStepicConnector.java | 2 +- .../com/jetbrains/edu/learning/stepic/StepicStudyOptions.java | 2 +- .../com/jetbrains/edu/learning/ui/StudyStepicUserWidget.java | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python/educational-core/src/com/jetbrains/edu/coursecreator/stepik/CCStepicConnector.java b/python/educational-core/src/com/jetbrains/edu/coursecreator/stepik/CCStepicConnector.java index 0000b9d289e7..8d0b13ac66df 100644 --- a/python/educational-core/src/com/jetbrains/edu/coursecreator/stepik/CCStepicConnector.java +++ b/python/educational-core/src/com/jetbrains/edu/coursecreator/stepik/CCStepicConnector.java @@ -331,9 +331,9 @@ public class CCStepicConnector { private static void showStepicNotification(@NotNull Project project, @NotNull NotificationType notificationType, @NotNull String failedActionName) { - String text = "Authorize on Stepik to " + failedActionName; + String text = "Log in to Stepik to " + failedActionName; Notification notification = new Notification("Stepik", "Failed to " + failedActionName, text, notificationType); - notification.addAction(new AnAction("Authorize") { + notification.addAction(new AnAction("Log in") { @Override public void actionPerformed(AnActionEvent e) { diff --git a/python/educational-core/src/com/jetbrains/edu/learning/builtInServer/EduStepikRestService.java b/python/educational-core/src/com/jetbrains/edu/learning/builtInServer/EduStepikRestService.java index 23e7e3f409e2..f5dd5d3c6e15 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/builtInServer/EduStepikRestService.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/builtInServer/EduStepikRestService.java @@ -122,14 +122,14 @@ public class EduStepikRestService extends RestService { if (stepicUser != null) { StudySettings.getInstance().setUser(stepicUser); sendHtmlResponse(request, context, "/oauthResponsePages/okPage.html"); - showStepicNotification(NotificationType.INFORMATION, "Authorized as " + stepicUser.getFirstName() + " " + stepicUser.getLastName()); + showStepicNotification(NotificationType.INFORMATION, "Logged in as " + stepicUser.getFirstName() + " " + stepicUser.getLastName()); focusOnApplicationWindow(); return null; } } sendHtmlResponse(request, context, "/oauthResponsePages/errorPage.html"); - showStepicNotification(NotificationType.ERROR, "Failed to authorize"); + showStepicNotification(NotificationType.ERROR, "Failed to log in"); return "Couldn't find code parameter for Stepik OAuth"; } diff --git a/python/educational-core/src/com/jetbrains/edu/learning/stepic/EduAdaptiveStepicConnector.java b/python/educational-core/src/com/jetbrains/edu/learning/stepic/EduAdaptiveStepicConnector.java index 2a6c9ac41d70..a09bb0b7236b 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/stepic/EduAdaptiveStepicConnector.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/stepic/EduAdaptiveStepicConnector.java @@ -300,7 +300,7 @@ public class EduAdaptiveStepicConnector { if (user == null) { LOG.warn("Can't get next recommendation: user is null"); ApplicationManager.getApplication().invokeLater(() -> StudyUtils.showErrorPopupOnToolbar(project, - "Can't get next recommendation: you're not authorized")); + "Can't get next recommendation: you're not logged in")); return; } diff --git a/python/educational-core/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.java b/python/educational-core/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.java index 2142a072646f..2fb8dbc82f3a 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.java @@ -102,7 +102,7 @@ public class StepicStudyOptions implements StudyOptionsProvider { if (stepicUser == null) { myUsernameLabel.setText("You're not logged in"); - myHoverHyperlinkLabel.setText("Authorize on Stepik"); + myHoverHyperlinkLabel.setText("Log in to Stepik"); myListener = createAuthorizeListener(); myHoverHyperlinkLabel.addHyperlinkListener(myListener); diff --git a/python/educational-core/src/com/jetbrains/edu/learning/ui/StudyStepicUserWidget.java b/python/educational-core/src/com/jetbrains/edu/learning/ui/StudyStepicUserWidget.java index cc9492dff1b6..3aab044aec2b 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/ui/StudyStepicUserWidget.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/ui/StudyStepicUserWidget.java @@ -92,7 +92,7 @@ public class StudyStepicUserWidget implements IconLikeCustomStatusBarWidget { setLayout(layout); if (user == null) { - createUserPanel("You're not logged in", "Authorize on Stepik", createAuthorizeUserListener()); + createUserPanel("You're not logged in", "Log in to Stepik", createAuthorizeUserListener()); } else { String firstName = user.getFirstName(); From cb0134d9c7cf939cbfb33f9cce525221f12c4f2e Mon Sep 17 00:00:00 2001 From: Valentina Kiryushkina Date: Mon, 15 May 2017 18:58:08 +0300 Subject: [PATCH 4/7] Minor User correct preposition --- .../src/com/jetbrains/python/edu/PyStudyInstructionPainter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/educational-python/src/com/jetbrains/python/edu/PyStudyInstructionPainter.java b/python/educational-python/src/com/jetbrains/python/edu/PyStudyInstructionPainter.java index f2c9dc8c63df..e165c8b02901 100644 --- a/python/educational-python/src/com/jetbrains/python/edu/PyStudyInstructionPainter.java +++ b/python/educational-python/src/com/jetbrains/python/edu/PyStudyInstructionPainter.java @@ -23,6 +23,6 @@ public class PyStudyInstructionPainter extends EditorEmptyTextPainter { appendAction(painter, "Reset current task file", getActionShortcutText(StudyRefreshTaskFileAction.ACTION_ID)); appendAction(painter, "Check task", getActionShortcutText(StudyCheckAction.ACTION_ID)); appendAction(painter, "Get hint for the answer placeholder", getActionShortcutText(StudyShowHintAction.ACTION_ID)); - appendAction(painter, "Open this task in Stepik", getActionShortcutText(StudyOpenTaskInStepikAction.ACTION_ID)); + appendAction(painter, "Open this task on Stepik", getActionShortcutText(StudyOpenTaskInStepikAction.ACTION_ID)); } } \ No newline at end of file From b6cdc615a3f74ddb038515a3a0d286368e7b2bec Mon Sep 17 00:00:00 2001 From: Valentina Kiryushkina Date: Thu, 18 May 2017 20:20:14 +0300 Subject: [PATCH 5/7] Use link to open task on Stepik instead of action on task description toolbar --- .../resources/META-INF/plugin.xml | 3 - .../resources/code-mirror/template.html | 23 ++++- .../edu/learning/EduPluginConfigurator.java | 3 +- .../jetbrains/edu/learning/StudyUtils.java | 16 +++- .../actions/StudyOpenTaskInStepikAction.java | 90 ------------------- .../python/edu/PyStudyInstructionPainter.java | 1 - 6 files changed, 35 insertions(+), 101 deletions(-) delete mode 100644 python/educational-core/src/com/jetbrains/edu/learning/actions/StudyOpenTaskInStepikAction.java diff --git a/python/educational-core/resources/META-INF/plugin.xml b/python/educational-core/resources/META-INF/plugin.xml index 3fe650f261e5..4ea7ae62660b 100644 --- a/python/educational-core/resources/META-INF/plugin.xml +++ b/python/educational-core/resources/META-INF/plugin.xml @@ -83,9 +83,6 @@ - - diff --git a/python/educational-core/resources/code-mirror/template.html b/python/educational-core/resources/code-mirror/template.html index e7d2348fab7c..1614b950ac3f 100644 --- a/python/educational-core/resources/code-mirror/template.html +++ b/python/educational-core/resources/code-mirror/template.html @@ -21,18 +21,37 @@ +
${code} +