EDU-227 Show balloon with link to tutorials and add action to help
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 28 Oct 2014 13:47:56 +0000 (16:47 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 28 Oct 2014 13:47:56 +0000 (16:47 +0300)
python/edu/learn-python/resources/META-INF/plugin.xml
python/edu/learn-python/src/com/jetbrains/python/edu/StudyInstructionPainter.java
python/edu/learn-python/src/com/jetbrains/python/edu/StudyTaskManager.java
python/edu/learn-python/src/com/jetbrains/python/edu/actions/StudyWatchTutorialAction.java [new file with mode: 0644]

index 328ce29de0e327f4c3b661212ccd86a65236f553..465d39252d355cce28e4cb3294c801ba8a838e2b 100644 (file)
@@ -22,8 +22,6 @@
 
   <depends>com.intellij.modules.lang</depends>
   <depends>com.intellij.modules.python</depends>
-  <application-components>
-  </application-components>
 
   <project-components>
     <component>
@@ -64,6 +62,9 @@
     <action id="WelcomeScreen.PythonIntro" class="com.jetbrains.python.edu.actions.StudyIntroductionCourseAction" icon="StudyIcons.EducationalProjectType">
       <add-to-group group-id="WelcomeScreen.QuickStart" anchor="first"/>
     </action>
+    <action id="StudyWatchTutorial" class="com.jetbrains.python.edu.actions.StudyWatchTutorialAction">
+      <add-to-group group-id="HelpMenu" anchor="first"/>
+    </action>
 
   </actions>
 
index b78111b442c82b9f6348c1ac37c6ed26836fd7c7..4fa323172bcccfa3efe71a95f6a9d8408df6d0d9 100644 (file)
@@ -33,7 +33,7 @@ public class StudyInstructionPainter extends EditorEmptyTextPainter {
     painter.appendLine("Reset current task file with Ctrl + Shift + X").smaller().withBullet();
     painter.appendLine("Check task with Alt + Ctrl + Enter").smaller().withBullet();
     painter.appendLine("Get hint for the task window using Ctrl + 7").smaller().withBullet();
-    painter.appendLine("To see your progress, open the 'Course Description' panel").smaller().withBullet();
+    painter.appendLine("To see your progress open the 'Course Description' panel").smaller().withBullet();
                        painter.draw(g, new PairFunction<Integer, Integer, Couple<Integer>>() {
                          @Override
                          public Couple<Integer> fun(Integer width, Integer height) {
index 9b935504bd5cc1685eccc40a5762120acf6a32e4..ec7caf38eac4b75371bebe037bc7b7b49323694a 100644 (file)
@@ -1,6 +1,12 @@
 package com.jetbrains.python.edu;
 
+import com.intellij.ide.BrowserUtil;
 import com.intellij.ide.ui.UISettings;
+import com.intellij.ide.util.PropertiesComponent;
+import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationListener;
+import com.intellij.notification.NotificationType;
+import com.intellij.notification.Notifications;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.actionSystem.ex.AnActionListener;
 import com.intellij.openapi.application.ApplicationManager;
@@ -14,11 +20,15 @@ import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.DumbAwareRunnable;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.startup.StartupManager;
+import com.intellij.openapi.ui.popup.Balloon;
+import com.intellij.openapi.ui.popup.JBPopupAdapter;
+import com.intellij.openapi.ui.popup.LightweightWindowEvent;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileAdapter;
 import com.intellij.openapi.vfs.VirtualFileEvent;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.openapi.wm.*;
+import com.intellij.util.ui.update.UiNotifyConnector;
 import com.intellij.util.xmlb.XmlSerializer;
 import com.jetbrains.python.edu.actions.*;
 import com.jetbrains.python.edu.course.Course;
@@ -32,7 +42,9 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
+import javax.swing.event.HyperlinkEvent;
 import java.lang.reflect.Method;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -145,9 +157,65 @@ public class StudyTaskManager implements ProjectComponent, PersistentStateCompon
               }
 
               final ToolWindow studyToolWindow = toolWindowManager.getToolWindow(toolWindowId);
+              class UrlOpeningListener implements NotificationListener {
+                private final boolean myExpireNotification;
+
+                public UrlOpeningListener(boolean expireNotification) {
+                  myExpireNotification = expireNotification;
+                }
+
+                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
+                  URL url = event.getURL();
+                  if (url == null) {
+                    BrowserUtil.browse(event.getDescription());
+                  }
+                  else {
+                    BrowserUtil.browse(url);
+                  }
+                  if (myExpireNotification) {
+                    notification.expire();
+                  }
+                }
+
+                @Override
+                public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
+                  if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+                    hyperlinkActivated(notification, event);
+                  }
+                }
+              }
               if (studyToolWindow != null) {
                 StudyUtils.updateStudyToolWindow(myProject);
                 studyToolWindow.show(null);
+                UiNotifyConnector.doWhenFirstShown(studyToolWindow.getComponent(), new Runnable() {
+                  @Override
+                  public void run() {
+                    if (PropertiesComponent.getInstance().getBoolean("StudyShowPopup", true)) {
+                      String content = "<html>If you'd like to learn" +
+                                       " more about PyCharm " +
+                                       "Educational Edition, " +
+                                       "click <a href=\"http://www.jetbrains.com/pycharm-educational/quickstart/\">here</a> to watch a tutorial</html>";
+                      final Notification notification =
+                        new Notification("Watch Tutorials!", "", content, NotificationType.INFORMATION, new UrlOpeningListener(true));
+                      Notifications.Bus.notify(notification);
+                      Balloon balloon = notification.getBalloon();
+                      if (balloon != null) {
+                        balloon.addListener(new JBPopupAdapter() {
+                          @Override
+                          public void onClosed(LightweightWindowEvent event) {
+                            notification.expire();
+                          }
+                        });
+                      }
+                      notification.whenExpired(new Runnable() {
+                        @Override
+                        public void run() {
+                          PropertiesComponent.getInstance().setValue("StudyShowPopup", String.valueOf(false));
+                        }
+                      });
+                    }
+                  }
+                });
               }
               addShortcut(StudyNextWindowAction.SHORTCUT, StudyNextWindowAction.ACTION_ID);
               addShortcut(StudyPrevWindowAction.SHORTCUT, StudyPrevWindowAction.ACTION_ID);
diff --git a/python/edu/learn-python/src/com/jetbrains/python/edu/actions/StudyWatchTutorialAction.java b/python/edu/learn-python/src/com/jetbrains/python/edu/actions/StudyWatchTutorialAction.java
new file mode 100644 (file)
index 0000000..abe38b9
--- /dev/null
@@ -0,0 +1,17 @@
+package com.jetbrains.python.edu.actions;
+
+import com.intellij.ide.BrowserUtil;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.project.DumbAwareAction;
+import org.jetbrains.annotations.NotNull;
+
+public class StudyWatchTutorialAction extends DumbAwareAction {
+  public StudyWatchTutorialAction() {
+    super("Learn more about PyCharm Educational Edition", null, null);
+  }
+
+  @Override
+  public void actionPerformed(@NotNull AnActionEvent e) {
+    BrowserUtil.browse("http://www.jetbrains.com/pycharm-educational/quickstart/");
+  }
+}