new editing mode for task description panel
authorliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 22 Mar 2016 11:15:15 +0000 (14:15 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 22 Mar 2016 11:15:15 +0000 (14:15 +0300)
20 files changed:
python/educational-core/course-creator/resources/META-INF/plugin.xml
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCStudyActionsProvider.java [new file with mode: 0644]
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCEditTaskTextAction.java [new file with mode: 0644]
python/educational-core/student/resources/META-INF/plugin.xml
python/educational-core/student/src/com/jetbrains/edu/learning/StudyActionsProvider.java [new file with mode: 0644]
python/educational-core/student/src/com/jetbrains/edu/learning/StudyBasePluginConfigurator.java
python/educational-core/student/src/com/jetbrains/edu/learning/StudyProjectComponent.java
python/educational-core/student/src/com/jetbrains/edu/learning/StudyTaskManager.java
python/educational-core/student/src/com/jetbrains/edu/learning/StudyUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyActionWithShortcut.java [moved from python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyToolbarAction.java with 58% similarity]
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshTaskFileAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyShowHintAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyTaskNavigationAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyWindowNavigationAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/ui/StudyJavaFxToolWindow.java
python/educational-core/student/src/com/jetbrains/edu/learning/ui/StudySwingToolWindow.java
python/educational-core/student/src/com/jetbrains/edu/learning/ui/StudyToolWindow.java
python/educational-core/student/student.iml
python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java

index 131d9f5b46d8376e25b441cc526e1f9fa0442954..24da17d3f29c45f6a1c40e5e394e5f069e253fa9 100644 (file)
@@ -24,6 +24,9 @@
     <renameHandler implementation="com.jetbrains.edu.coursecreator.CCTaskRenameHandler" order="first"/>
     <renameHandler implementation="com.jetbrains.edu.coursecreator.CCLessonRenameHandler" order="first"/>
   </extensions>
+  <extensions defaultExtensionNs="Edu">
+    <studyActionsProvider implementation="com.jetbrains.edu.coursecreator.CCStudyActionsProvider"/>
+  </extensions>
 
   <application-components>
     <!-- Add your application components here -->
diff --git a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCStudyActionsProvider.java b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCStudyActionsProvider.java
new file mode 100644 (file)
index 0000000..7ccdc07
--- /dev/null
@@ -0,0 +1,12 @@
+package com.jetbrains.edu.coursecreator;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.jetbrains.edu.coursecreator.actions.CCEditTaskTextAction;
+import com.jetbrains.edu.learning.StudyActionsProvider;
+
+public class CCStudyActionsProvider implements StudyActionsProvider{
+  @Override
+  public AnAction[] getActions() {
+    return new AnAction[]{new CCEditTaskTextAction()};
+  }
+}
diff --git a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCEditTaskTextAction.java b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCEditTaskTextAction.java
new file mode 100644 (file)
index 0000000..a528ba6
--- /dev/null
@@ -0,0 +1,81 @@
+package com.jetbrains.edu.coursecreator.actions;
+
+import com.intellij.icons.AllIcons;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.ToggleAction;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.fileEditor.FileDocumentManager;
+import com.intellij.openapi.project.DumbAware;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.jetbrains.edu.coursecreator.CCProjectService;
+import com.jetbrains.edu.learning.StudyState;
+import com.jetbrains.edu.learning.StudyTaskManager;
+import com.jetbrains.edu.learning.StudyUtils;
+import com.jetbrains.edu.learning.core.EduNames;
+import com.jetbrains.edu.learning.editor.StudyEditor;
+import com.jetbrains.edu.learning.ui.StudyToolWindow;
+import org.jetbrains.annotations.NotNull;
+
+public class CCEditTaskTextAction extends ToggleAction implements DumbAware {
+  private static final Logger LOG = Logger.getInstance(CCEditTaskTextAction.class);
+
+  public CCEditTaskTextAction() {
+    super("Editing Mode", "Editing Mode", AllIcons.Modules.Edit);
+  }
+
+  @Override
+  public boolean isSelected(AnActionEvent e) {
+    Project project = e.getProject();
+    if (project == null) {
+      return false;
+    }
+    return StudyTaskManager.getInstance(project).getToolWindowMode() == StudyToolWindow.StudyToolWindowMode.EDITING;
+  }
+
+  @Override
+  public void setSelected(AnActionEvent e, boolean state) {
+    Project project = e.getProject();
+    if (project == null) {
+      return;
+    }
+    StudyToolWindow window = StudyUtils.getStudyToolWindow(project);
+    if (window == null) {
+      return;
+    }
+
+    final StudyEditor selectedEditor = StudyUtils.getSelectedStudyEditor(project);
+    if (selectedEditor == null) {
+      StudyTaskManager.getInstance(project).setTurnEditingMode(true);
+      return;
+    }
+    final StudyState studyState = new StudyState(selectedEditor);
+    VirtualFile taskTextFile = studyState.getTaskDir().findChild(EduNames.TASK_HTML);
+    if (taskTextFile == null) {
+      LOG.info("Failed to find task.html");
+      return;
+    }
+    Document document = FileDocumentManager.getInstance().getDocument(taskTextFile);
+    if (!state) {
+      if (document != null) {
+        FileDocumentManager.getInstance().saveDocument(document);
+      }
+      window.leaveEditingMode(project);
+      return;
+    }
+    window.enterEditingMode(taskTextFile, project);
+  }
+
+  @Override
+  public void update(@NotNull AnActionEvent e) {
+    Project project = e.getProject();
+    if (project == null) {
+      return;
+    }
+
+    if (CCProjectService.getInstance(project).getCourse() == null) {
+      e.getPresentation().setEnabledAndVisible(false);
+    }
+  }
+}
index 9d5142d93775fd71a698e8fe8b12735b68cbc5bb..68aca8e54232447e342b9cf920957c50a13b1f2e 100644 (file)
@@ -36,6 +36,7 @@
       <with attribute="implementationClass" implements="com.jetbrains.edu.learning.StudyLanguageManager"/>
     </extensionPoint>
     <extensionPoint qualifiedName="Edu.studyPluginConfigurator" interface="com.jetbrains.edu.learning.StudyPluginConfigurator"/>
+    <extensionPoint qualifiedName="Edu.studyActionsProvider" interface="com.jetbrains.edu.learning.StudyActionsProvider"/>
   </extensionPoints>
 
   <actions>
diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/StudyActionsProvider.java b/python/educational-core/student/src/com/jetbrains/edu/learning/StudyActionsProvider.java
new file mode 100644 (file)
index 0000000..4aca599
--- /dev/null
@@ -0,0 +1,10 @@
+package com.jetbrains.edu.learning;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.extensions.ExtensionPointName;
+
+public interface StudyActionsProvider {
+  ExtensionPointName<StudyActionsProvider> EP_NAME = ExtensionPointName.create("Edu.studyActionsProvider");
+
+  AnAction[] getActions();
+}
index b269cde639b93330aa53e2f591cebb82002a0a32..cd204d70c63c8c46ac404ba2d4b65adcab0a6124 100644 (file)
@@ -50,9 +50,6 @@ public abstract class StudyBasePluginConfigurator implements StudyPluginConfigur
   public FileEditorManagerListener getFileEditorManagerListener(@NotNull Project project, @NotNull StudyToolWindow toolWindow) {
 
     return new FileEditorManagerListener() {
-
-      private static final String EMPTY_TASK_TEXT = "Please, open any task to see task description";
-
       @Override
       public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
         Task task = getTask(file);
@@ -61,7 +58,7 @@ public abstract class StudyBasePluginConfigurator implements StudyPluginConfigur
 
       @Override
       public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
-        toolWindow.setTaskText(EMPTY_TASK_TEXT);
+        toolWindow.setEmptyText(project);
       }
 
       @Override
@@ -87,10 +84,10 @@ public abstract class StudyBasePluginConfigurator implements StudyPluginConfigur
       private void setTaskText(@Nullable final Task task, @Nullable final VirtualFile taskDirectory) {
         String text = StudyUtils.getTaskTextFromTask(task, taskDirectory);
         if (text == null) {
-          toolWindow.setTaskText(EMPTY_TASK_TEXT);
+          toolWindow.setEmptyText(project);
           return;
         }
-        toolWindow.setTaskText(text);
+        toolWindow.setTaskText(text, taskDirectory, project);
       }
     };
   }
index 9b0d2aea6a8c0ceafca3a42764924525747c6864..81af40c0d894796c6859b966a90a4dd101d3ea38 100644 (file)
@@ -115,10 +115,12 @@ public class StudyProjectComponent implements ProjectComponent {
       List<AnAction> actionsOnToolbar = window.getActions(true);
       if (actionsOnToolbar != null) {
         for (AnAction action : actionsOnToolbar) {
-          if (action instanceof StudyToolbarAction) {
-            String id = ((StudyToolbarAction)action).getActionId();
-            String[] shortcuts = ((StudyToolbarAction)action).getShortcuts();
-            addShortcut(id, shortcuts);
+          if (action instanceof StudyActionWithShortcut) {
+            String id = ((StudyActionWithShortcut)action).getActionId();
+            String[] shortcuts = ((StudyActionWithShortcut)action).getShortcuts();
+            if (shortcuts != null) {
+              addShortcut(id, shortcuts);
+            }
           }
         }
       }
index 6d682f4af732026e68fc77505dea6f972be53754..3a2ffd7d8f6645660856405b50e101e3c5595263 100644 (file)
@@ -14,6 +14,7 @@ import com.intellij.util.xmlb.XmlSerializer;
 import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.courseFormat.*;
 import com.jetbrains.edu.learning.oldCourseFormat.OldCourse;
+import com.jetbrains.edu.learning.ui.StudyToolWindow;
 import org.jdom.Element;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -37,6 +38,9 @@ public class StudyTaskManager implements PersistentStateComponent<Element>, Dumb
   public Map<TaskFile, StudyStatus> myTaskStatusMap = new HashMap<>();
   public Map<Task, List<UserTest>> myUserTests = new HashMap<>();
   public List<String> myInvisibleFiles = new ArrayList<>();
+  private StudyToolWindow.StudyToolWindowMode myToolWindowMode = StudyToolWindow.StudyToolWindowMode.TEXT;
+  private boolean myTurnEditingMode = false;
+
 
   private StudyTaskManager() {
   }
@@ -250,4 +254,20 @@ public class StudyTaskManager implements PersistentStateComponent<Element>, Dumb
   public boolean isInvisibleFile(String path) {
     return myInvisibleFiles.contains(path);
   }
+
+  public StudyToolWindow.StudyToolWindowMode getToolWindowMode() {
+    return myToolWindowMode;
+  }
+
+  public void setToolWindowMode(StudyToolWindow.StudyToolWindowMode toolWindowMode) {
+    myToolWindowMode = toolWindowMode;
+  }
+
+  public boolean isTurnEditingMode() {
+    return myTurnEditingMode;
+  }
+
+  public void setTurnEditingMode(boolean turnEditingMode) {
+    myTurnEditingMode = turnEditingMode;
+  }
 }
index 940d94ce6b539e5bfdd4f415be3374aa82dc5592..c204f012023fe7599c41bf623945db642ac70bef 100644 (file)
@@ -128,7 +128,7 @@ public class StudyUtils {
   }
 
   public static void updateToolWindows(@NotNull final Project project) {
-    update(project);
+    updateStudyToolWindow(project);
 
     final ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
     createProgressToolWindowContent(project, windowManager);
@@ -461,14 +461,7 @@ public class StudyUtils {
   }
 
   public static String getTaskText(@NotNull final Project project) {
-    VirtualFile[] files = FileEditorManager.getInstance(project).getSelectedFiles();
-    TaskFile taskFile = null;
-    for (VirtualFile file : files) {
-      taskFile = getTaskFile(project, file);
-      if (taskFile != null) {
-        break;
-      }
-    }
+    TaskFile taskFile = getSelectedTaskFile(project);
     if (taskFile == null) {
       return EMPTY_TASK_TEXT;
     }
@@ -479,11 +472,24 @@ public class StudyUtils {
     return null;
   }
 
-  public static void update(Project project) {
+  @Nullable
+  public static TaskFile getSelectedTaskFile(@NotNull Project project) {
+    VirtualFile[] files = FileEditorManager.getInstance(project).getSelectedFiles();
+    TaskFile taskFile = null;
+    for (VirtualFile file : files) {
+      taskFile = getTaskFile(project, file);
+      if (taskFile != null) {
+        break;
+      }
+    }
+    return taskFile;
+  }
+
+  public static void updateStudyToolWindow(Project project) {
     final StudyToolWindow studyToolWindow = getStudyToolWindow(project);
     if (studyToolWindow != null) {
       String taskText = getTaskText(project);
-      studyToolWindow.setTaskText(taskText);
+      studyToolWindow.setTaskText(taskText, null, project);
     }
   }
 }
similarity index 58%
rename from python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyToolbarAction.java
rename to python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyActionWithShortcut.java
index a74e547984ef6bb0e86cb7e9491c1cf6767515e8..ae1fa651031c715899a3cd71943677417548b162 100644 (file)
@@ -6,8 +6,9 @@ import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
-public abstract class StudyToolbarAction extends DumbAwareAction {
-  public StudyToolbarAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
+public abstract class StudyActionWithShortcut extends DumbAwareAction {
+
+  public StudyActionWithShortcut(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
     super(text, description, icon);
   }
 
@@ -15,5 +16,5 @@ public abstract class StudyToolbarAction extends DumbAwareAction {
   public abstract String getActionId();
   
   @Nullable
-  public abstract String[] getShortcuts();  
-}
+  public abstract String[] getShortcuts();
+}
\ No newline at end of file
index be3695794db643b5ba3d59b6fe8284baf2518ec8..5c42608382f12aba893c2ef5c9bd5d04f7832e64 100644 (file)
@@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
 
-public abstract class StudyCheckAction extends StudyToolbarAction {
+public abstract class StudyCheckAction extends StudyActionWithShortcut {
   public static final String SHORTCUT = "ctrl alt pressed ENTER";
 
   protected Ref<Boolean> myCheckInProgress = new Ref<>(false);
index 110feeee370f5c124c1c4c1c66a6d12e9058ebb2..2a421abdb13157685310a6d14082484a87178cad 100644 (file)
@@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
-public class StudyRefreshTaskFileAction extends StudyToolbarAction {
+public class StudyRefreshTaskFileAction extends StudyActionWithShortcut {
   public static final String ACTION_ID = "RefreshTaskAction";
   public static final String SHORTCUT = "ctrl shift pressed X";
   private static final Logger LOG = Logger.getInstance(StudyRefreshTaskFileAction.class.getName());
index 25642dc0cf87f187388739f3a06344933622f27c..75a1277c88d990941fe13741f57c13a1f2874fef 100644 (file)
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
-public class StudyShowHintAction extends StudyToolbarAction {
+public class StudyShowHintAction extends StudyActionWithShortcut {
   public static final String ACTION_ID = "ShowHintAction";
   public static final String SHORTCUT = "ctrl pressed 7";
   private static final String ourWarningMessage = "Put the caret in the answer placeholder to get hint";
index 580bc3557d64cd07d3c0b1eab75d2207e5c1831d..308a423d68f6833a4b309cf56afee0d9eeff2e08 100644 (file)
@@ -27,7 +27,7 @@ import javax.swing.tree.TreePath;
 import java.util.Map;
 
 
-abstract public class StudyTaskNavigationAction extends StudyToolbarAction {
+abstract public class StudyTaskNavigationAction extends StudyActionWithShortcut {
   public StudyTaskNavigationAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
     super(text, description, icon);
   }
index 50be6069aa361bed9148259c6c05b7cce03c5c7e..cd0b5ccf1dbe63c6bfd99d136625f6f78798921a 100644 (file)
@@ -16,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
-abstract public class StudyWindowNavigationAction extends StudyToolbarAction implements DumbAware {
+abstract public class StudyWindowNavigationAction extends StudyActionWithShortcut implements DumbAware {
 
   protected StudyWindowNavigationAction(String actionId, String description, Icon icon) {
     super(actionId, description, icon);
index 98bec3d505893bd6633cf15c17f7c46be4e89d4d..058bd633a29b342aca10117dda6e2a7f68c68319 100644 (file)
@@ -29,10 +29,9 @@ public class StudyJavaFxToolWindow extends StudyToolWindow {
   }
 
   @Override
-  public JComponent createTaskInfoPanel(String taskText, Project project) {
+  public JComponent createTaskInfoPanel(Project project) {
     myBrowserWindow = new StudyBrowserWindow(true, false);
     myBrowserWindow.addBackAndOpenButtons();
-    myBrowserWindow.loadContent(taskText, StudyUtils.getConfigurator(project));
     JPanel panel = new JPanel();
     panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
     panel.add(myBrowserWindow.getPanel());
@@ -40,7 +39,7 @@ public class StudyJavaFxToolWindow extends StudyToolWindow {
   }
 
   @Override
-  public void setTaskText(String text) {
+  public void setText(String text) {
     StudyPluginConfigurator configurator = StudyUtils.getConfigurator(ProjectUtil.guessCurrentProject(this));
       myBrowserWindow.loadContent(text, configurator);
   }
index ae4914313f1084f42c2b68dfc1033642d6cd51f7..4e446b083a6c4078f2cf75882629b471a0987d5e 100644 (file)
@@ -35,7 +35,7 @@ public class StudySwingToolWindow extends StudyToolWindow {
   }
 
   @Override
-  public JComponent createTaskInfoPanel(String taskText, Project project) {
+  public JComponent createTaskInfoPanel(Project project) {
     myTaskTextPane = new JTextPane();
     myTaskTextPane.setContentType(new HTMLEditorKit().getContentType());
     final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
@@ -54,12 +54,11 @@ public class StudySwingToolWindow extends StudyToolWindow {
       myTaskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground());
     }
     myTaskTextPane.setBorder(new EmptyBorder(15, 20, 0, 100));
-    myTaskTextPane.setText(taskText);
     myTaskTextPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
     return myTaskTextPane;
   }
 
-  public void setTaskText(String text) {
+  public void setText(String text) {
     myTaskTextPane.setText(text);
   }
 }
index b523ce4af2112d7516bebb9eea60c4f6d8fd4c31..96817aa4a7948b72da3a4040e9718d7e95046204 100644 (file)
  */
 package com.jetbrains.edu.learning.ui;
 
+import com.intellij.ide.browsers.WebBrowserManager;
 import com.intellij.openapi.Disposable;
-import com.intellij.openapi.actionSystem.ActionManager;
-import com.intellij.openapi.actionSystem.ActionToolbar;
-import com.intellij.openapi.actionSystem.DataProvider;
-import com.intellij.openapi.actionSystem.DefaultActionGroup;
+import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.editor.EditorFactory;
+import com.intellij.openapi.editor.ex.EditorEx;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.fileEditor.FileEditorManagerListener;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.SimpleToolWindowPanel;
+import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.ui.JBCardLayout;
 import com.intellij.ui.OnePixelSplitter;
 import com.intellij.util.ui.JBUI;
-import com.jetbrains.edu.learning.StudyBasePluginConfigurator;
-import com.jetbrains.edu.learning.StudyPluginConfigurator;
-import com.jetbrains.edu.learning.StudyTaskManager;
-import com.jetbrains.edu.learning.StudyUtils;
+import com.jetbrains.edu.learning.*;
+import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.courseFormat.Course;
+import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
@@ -41,6 +45,7 @@ import java.util.Map;
 public abstract class StudyToolWindow extends SimpleToolWindowPanel implements DataProvider, Disposable {
   private static final Logger LOG = Logger.getInstance(StudyToolWindow.class);
   private static final String TASK_INFO_ID = "taskInfo";
+  private static final String EMPTY_TASK_TEXT = "Please, open any task to see task description";
   private final JBCardLayout myCardLayout;
   private final JPanel myContentPanel;
   private final OnePixelSplitter mySplitPane;
@@ -49,17 +54,17 @@ public abstract class StudyToolWindow extends SimpleToolWindowPanel implements D
     super(true, true);
     myCardLayout = new JBCardLayout();
     myContentPanel = new JPanel(myCardLayout);
-    mySplitPane = new OnePixelSplitter(myVertical=true);
+    mySplitPane = new OnePixelSplitter(myVertical = true);
   }
 
   public void init(Project project) {
     String taskText = StudyUtils.getTaskText(project);
     if (taskText == null) return;
 
-    JPanel toolbarPanel = createToolbarPanel(project);
+    JPanel toolbarPanel = createToolbarPanel(getActionGroup(project));
     setToolbar(toolbarPanel);
 
-    myContentPanel.add(TASK_INFO_ID, createTaskInfoPanel(taskText, project));
+    myContentPanel.add(TASK_INFO_ID, createTaskInfoPanel(project));
     mySplitPane.setFirstComponent(myContentPanel);
     addAdditionalPanels(project);
     myCardLayout.show(myContentPanel, TASK_INFO_ID);
@@ -71,6 +76,17 @@ public abstract class StudyToolWindow extends SimpleToolWindowPanel implements D
       final FileEditorManagerListener listener = configurator.getFileEditorManagerListener(project, this);
       project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
     }
+
+    if (StudyTaskManager.getInstance(project).isTurnEditingMode() || StudyTaskManager.getInstance(project).getToolWindowMode() == StudyToolWindowMode.EDITING) {
+      TaskFile file = StudyUtils.getSelectedTaskFile(project);
+      if (file != null) {
+        VirtualFile taskDir = file.getTask().getTaskDir(project);
+        setTaskText(taskText, taskDir, project);
+
+      }
+    } else {
+      setTaskText(taskText, null, project);
+    }
   }
 
   private void addAdditionalPanels(Project project) {
@@ -88,7 +104,7 @@ public abstract class StudyToolWindow extends SimpleToolWindowPanel implements D
 
   public void dispose() {
   }
-  
+
   //used in checkiO plugin.
   @SuppressWarnings("unused")
   public void showPanelById(@NotNull final String panelId) {
@@ -120,24 +136,25 @@ public abstract class StudyToolWindow extends SimpleToolWindowPanel implements D
   }
 
 
-  public abstract JComponent createTaskInfoPanel(String taskText, Project project);
-
-  private static JPanel createToolbarPanel(@NotNull final Project project) {
-    final DefaultActionGroup group = getActionGroup(project);
+  public abstract JComponent createTaskInfoPanel(Project project);
 
+  public static JPanel createToolbarPanel(ActionGroup group) {
     final ActionToolbar actionToolBar = ActionManager.getInstance().createActionToolbar("Study", group, true);
     return JBUI.Panels.simplePanel(actionToolBar.getComponent());
   }
 
-  private static DefaultActionGroup getActionGroup(@NotNull final Project project) {
+  public static DefaultActionGroup getActionGroup(@NotNull final Project project) {
+    DefaultActionGroup group = new DefaultActionGroup();
     Course course = StudyTaskManager.getInstance(project).getCourse();
     if (course == null) {
       LOG.warn("Course is null");
-      return new DefaultActionGroup();
+      return group;
     }
     StudyPluginConfigurator configurator = StudyUtils.getConfigurator(project);
     if (configurator != null) {
-      return configurator.getActionGroup(project);
+      group.addAll(configurator.getActionGroup(project));
+      addAdditionalActions(group);
+      return group;
     }
     else {
       LOG.warn("No configurator is provided for plugin");
@@ -145,5 +162,68 @@ public abstract class StudyToolWindow extends SimpleToolWindowPanel implements D
     }
   }
 
-  public abstract void setTaskText(String text) ;
+  private static void addAdditionalActions(DefaultActionGroup group) {
+    StudyActionsProvider[] providers = Extensions.getExtensions(StudyActionsProvider.EP_NAME);
+    for (StudyActionsProvider provider : providers) {
+      group.addAll(provider.getActions());
+    }
+  }
+
+  public void setTaskText(String text, VirtualFile taskDirectory, Project project) {
+    if (StudyTaskManager.getInstance(project).isTurnEditingMode()) {
+      if (taskDirectory == null) {
+        LOG.info("Failed to enter editing mode for StudyToolWindow");
+        return;
+      }
+      VirtualFile taskTextFile = taskDirectory.findChild(EduNames.TASK_HTML);
+      enterEditingMode(taskTextFile, project);
+      StudyTaskManager.getInstance(project).setTurnEditingMode(false);
+    }
+    else {
+      setText(text);
+    }
+  }
+
+  protected abstract void setText(String text);
+
+  public void setEmptyText(@NotNull Project project) {
+    if (StudyTaskManager.getInstance(project).getToolWindowMode() == StudyToolWindowMode.EDITING) {
+      mySplitPane.setFirstComponent(myContentPanel);
+      StudyTaskManager.getInstance(project).setTurnEditingMode(true);
+    }
+    setTaskText(EMPTY_TASK_TEXT, null, project);
+  }
+
+  public enum StudyToolWindowMode {
+    TEXT, EDITING
+  }
+
+
+  public void enterEditingMode(VirtualFile taskFile, Project project) {
+    final EditorFactory factory = EditorFactory.getInstance();
+    Document document = FileDocumentManager.getInstance().getDocument(taskFile);
+    if (document == null) {
+      return;
+    }
+    WebBrowserManager.getInstance().setShowBrowserHover(false);
+    final EditorEx createdEditor = (EditorEx)factory.createEditor(document, project, taskFile, false);
+    Disposer.register(project, new Disposable() {
+      public void dispose() {
+        factory.releaseEditor(createdEditor);
+      }
+    });
+    JComponent editorComponent = createdEditor.getComponent();
+    mySplitPane.setFirstComponent(editorComponent);
+    mySplitPane.repaint();
+
+    StudyTaskManager.getInstance(project).setToolWindowMode(StudyToolWindowMode.EDITING);
+  }
+
+
+  public void leaveEditingMode(Project project) {
+    WebBrowserManager.getInstance().setShowBrowserHover(true);
+    mySplitPane.setFirstComponent(myContentPanel);
+    StudyTaskManager.getInstance(project).setToolWindowMode(StudyToolWindowMode.TEXT);
+    StudyUtils.updateStudyToolWindow(project);
+  }
 }
index afa3ecaa230c8c5d6e1948f937425e398eb96768..348ee0a814c1d1562520717133e1e27ff755c088 100644 (file)
@@ -22,5 +22,6 @@
         <SOURCES />
       </library>
     </orderEntry>
+    <orderEntry type="module" module-name="xml" />
   </component>
 </module>
\ No newline at end of file
index ebffadfea5d2c24427defdf2b5f8ebf42f710a9b..501e73f76e9a02d3d635bb85b453cced4d9a9fde 100644 (file)
@@ -15,6 +15,8 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.platform.DirectoryProjectGenerator;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiManager;
+import com.jetbrains.edu.learning.StudyProjectComponent;
+import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.courseFormat.Course;
 import com.jetbrains.edu.coursecreator.actions.CCCreateLesson;
 import com.jetbrains.edu.coursecreator.actions.CCCreateTask;
@@ -63,6 +65,9 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire
     course.setLanguage("Python");
     service.setCourse(course);
 
+    StudyTaskManager.getInstance(project).setCourse(course);
+    StudyProjectComponent.getInstance(project).registerStudyToolWindow(course);
+
     final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir);
     if (projectDir == null) return;
     new WriteCommandAction.Simple(project) {