Fix according to review IDEA-CR-11224: 1) Update Course creator options panel 2)...
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 6 Jun 2016 08:33:53 +0000 (11:33 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 6 Jun 2016 11:40:36 +0000 (14:40 +0300)
12 files changed:
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCVirtualFileListener.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateTask.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCEditTaskTextAction.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/projectView/CCTreeStructureProvider.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/settings/CCOptions.form
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/settings/CCOptions.java
python/educational-core/student/src/com/jetbrains/edu/learning/StudyProjectComponent.java
python/educational-core/student/src/com/jetbrains/edu/learning/StudyUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Task.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseGeneration/StudyGenerator.java
python/educational-core/student/src/com/jetbrains/edu/learning/projectView/StudyTreeStructureProvider.java
python/educational-core/student/src/com/jetbrains/edu/learning/ui/StudyToolWindow.java

index d05530f84a6e7b83437f48fe4e706b83ae601b47..5f5922edf027cb24b704e8c0c43d008a7c49f853 100644 (file)
@@ -6,11 +6,13 @@ import com.intellij.openapi.project.ProjectUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileAdapter;
 import com.intellij.openapi.vfs.VirtualFileEvent;
-import com.intellij.util.Function;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.core.EduNames;
-import com.jetbrains.edu.learning.courseFormat.*;
+import com.jetbrains.edu.learning.courseFormat.Course;
+import com.jetbrains.edu.learning.courseFormat.Lesson;
+import com.jetbrains.edu.learning.courseFormat.Task;
+import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import org.jetbrains.annotations.NotNull;
 
 public class CCVirtualFileListener extends VirtualFileAdapter {
@@ -35,8 +37,7 @@ public class CCVirtualFileListener extends VirtualFileAdapter {
 
     String name = createdFile.getName();
     if (CCUtils.isTestsFile(project, createdFile)
-        || EduNames.TASK_HTML.equals(name)
-        || EduNames.TASK_MD.equals(name)
+        || StudyUtils.isTaskDescriptionFile(name)
         || name.contains(EduNames.WINDOW_POSTFIX)
         || name.contains(EduNames.WINDOWS_POSTFIX)
         || name.contains(EduNames.ANSWERS_POSTFIX)) {
index 2596d8cacd52080f05d4f2abbb3dd2a5368048cc..fbbe0d95fc67dc980058cd1d80db91c5341df17f 100644 (file)
@@ -17,6 +17,7 @@ import com.intellij.util.Function;
 import com.jetbrains.edu.coursecreator.CCLanguageManager;
 import com.jetbrains.edu.coursecreator.CCUtils;
 import com.jetbrains.edu.coursecreator.settings.CCSettings;
+import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.courseFormat.Course;
@@ -100,7 +101,8 @@ public class CCCreateTask extends CCCreateStudyItemActionBase {
           return;
         }
         createFromTemplate(taskDirectory.get(), manager.getTestsTemplate(project), view, false);
-        createFromTemplate(taskDirectory.get(), FileTemplateManager.getInstance(project).getInternalTemplate(CCSettings.getInstance().useHtmlAsDefaultTaskFormat() ? EduNames.TASK_HTML : EduNames.TASK_MD), view, false);
+        createFromTemplate(taskDirectory.get(), FileTemplateManager.getInstance(project)
+          .getInternalTemplate(StudyUtils.getTaskDescriptionFileName(CCSettings.getInstance().useHtmlAsDefaultTaskFormat())), view, false);
         String defaultExtension = manager.getDefaultTaskFileExtension();
         if (defaultExtension != null) {
           FileTemplate taskFileTemplate = manager.getTaskFileTemplateForExtension(project, defaultExtension);
index 89024abb24c434f405ca73425626412f64e66e50..5786ebe51199b1fc333052c591f9c1bfbf6405a8 100644 (file)
@@ -10,11 +10,9 @@ import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.jetbrains.edu.coursecreator.CCUtils;
-import com.jetbrains.edu.coursecreator.settings.CCSettings;
 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;
@@ -52,8 +50,7 @@ public class CCEditTaskTextAction extends ToggleAction implements DumbAware {
       return;
     }
     final StudyState studyState = new StudyState(selectedEditor);
-    VirtualFile taskTextFile = studyState.getTaskDir().findChild(CCSettings.getInstance().useHtmlAsDefaultTaskFormat() ? 
-                                                                 EduNames.TASK_HTML : EduNames.TASK_MD);
+    VirtualFile taskTextFile = StudyUtils.findTaskDescriptionVirtualFile(studyState.getTaskDir());
     if (taskTextFile == null) {
       LOG.info("Failed to find task.html");
       return;
index d73ca3e90678cfb409f8bec41356b174ed0227a6..3ba35d688992c81d419903747437429df44b0e3f 100644 (file)
@@ -9,7 +9,6 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDirectory;
 import com.jetbrains.edu.coursecreator.CCUtils;
 import com.jetbrains.edu.learning.StudyUtils;
-import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.projectView.StudyTreeStructureProvider;
 import org.jetbrains.annotations.NotNull;
 
@@ -42,8 +41,7 @@ public class CCTreeStructureProvider extends StudyTreeStructureProvider {
           if (virtualFile == null) {
             continue;
           }
-          if (StudyUtils.getTaskFile(project, virtualFile) == null && !EduNames.TASK_HTML.equals(virtualFile.getName()) 
-              && !EduNames.TASK_MD.equals(virtualFile.getName())) {
+          if (StudyUtils.getTaskFile(project, virtualFile) == null && !StudyUtils.isTaskDescriptionFile(virtualFile.getName())) {
             modifiedChildren.add(new CCStudentInvisibleFileNode(project, ((PsiFileNode)node).getValue(), settings));
           }
         }
index 19705399b4399d435e03886c14b4b2c18bbab469..d6603108b5909f632814e00047576484fcb7a7ab 100644 (file)
@@ -6,16 +6,23 @@
       <xy x="20" y="20" width="500" height="400"/>
     </constraints>
     <properties/>
+    <clientProperties>
+      <BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
+    </clientProperties>
     <border type="etched" title="Course creator">
       <font/>
+      <title-color color="-4473925"/>
     </border>
     <children>
-      <grid id="2f67b" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+      <grid id="2f67b" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
         <margin top="0" left="0" bottom="0" right="0"/>
         <constraints>
           <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties/>
+        <clientProperties>
+          <BorderFactoryClass class="java.lang.String" value=""/>
+        </clientProperties>
         <border type="none"/>
         <children>
           <component id="8c915" class="com.intellij.ui.components.JBLabel">
@@ -23,7 +30,7 @@
               <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
-              <text value="Default task text format"/>
+              <text value="Default task description format:"/>
             </properties>
           </component>
           <component id="3a318" class="javax.swing.JRadioButton" binding="myHtmlRadioButton" default-binding="true">
@@ -37,7 +44,7 @@
           </component>
           <component id="bf5e2" class="javax.swing.JRadioButton" binding="myMarkdownRadioButton" default-binding="true">
             <constraints>
-              <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+              <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <selected value="false"/>
index 34d15f23f18293ecfbc65e25f86a79fc6a8d8e71..4ebd48652970f25bf3e246680a3d4a8914b11c4e 100644 (file)
@@ -36,11 +36,11 @@ public class CCOptions implements StudyOptionsProvider {
   public JComponent createComponent() {
     if (CCSettings.getInstance().useHtmlAsDefaultTaskFormat()) {
       myHtmlRadioButton.setSelected(true);
-      myMarkdownRadioButton.setSelected(false);
+      myHtmlRadioButton.requestFocus();
     }
     else {
-      myHtmlRadioButton.setSelected(false);
       myMarkdownRadioButton.setSelected(true);
+      myMarkdownRadioButton.requestFocus();
     }
     return myPanel;
   }
@@ -52,16 +52,12 @@ public class CCOptions implements StudyOptionsProvider {
 
   @Override
   public void apply() throws ConfigurationException {
-    if (myHtmlRadioButton.isSelected()) {
-      CCSettings.getInstance().setUseHtmlAsDefaultTaskFormat(true);
-    }
-    else if (myMarkdownRadioButton.isSelected()) {
-      CCSettings.getInstance().setUseHtmlAsDefaultTaskFormat(false);
-    }
+    CCSettings.getInstance().setUseHtmlAsDefaultTaskFormat(myHtmlRadioButton.isSelected());
   }
 
   @Override
   public void reset() {
+    createComponent();    
   }
 
   @Override
index ac816c7ebde5d6b1dd3b91f4ab95317f0f0c16f6..44cf72f11f58e5a02f642de26c0b47582c47c26d 100644 (file)
@@ -161,12 +161,18 @@ public class StudyProjectComponent implements ProjectComponent {
         final File[] tasks = file.listFiles();
         if (tasks == null) continue;
         for (File task : tasks) {
-          final File taskDescr = new File(task, EduNames.TASK_HTML);
-          String testFileName = manager.getTestFileName();
-          final File taskTests = new File(task, testFileName);
-          copyFile(taskDescr, new File(new File(new File(myProject.getBasePath(), file.getName()), task.getName()), EduNames.TASK_HTML));
-          copyFile(taskTests, new File(new File(new File(myProject.getBasePath(), file.getName()), task.getName()),
-                                       testFileName));
+          final File taskDescrFrom = StudyUtils.createTaskDescriptionFile(task);
+          if (taskDescrFrom != null) {
+            String testFileName = manager.getTestFileName();
+            final File taskTests = new File(task, testFileName);
+            final File taskDescrTo =
+              StudyUtils.createTaskDescriptionFile(new File(new File(myProject.getBasePath(), file.getName()), task.getName()));
+            if (taskDescrTo != null) {
+              copyFile(taskDescrFrom, taskDescrTo);
+              copyFile(taskTests, new File(new File(new File(myProject.getBasePath(), file.getName()), task.getName()),
+                                           testFileName));
+            }
+          }
         }
       }
     }
index cfafd03603e831c1e13846328427391a650d5510..937c6d8d22ff16531e9ea6ad29e2b6e1357ca4de 100644 (file)
@@ -36,6 +36,7 @@ import com.intellij.psi.PsiFile;
 import com.intellij.ui.JBColor;
 import com.intellij.ui.awt.RelativePoint;
 import com.intellij.ui.content.Content;
+import com.intellij.util.ObjectUtils;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.text.MarkdownUtil;
 import com.intellij.util.ui.UIUtil;
@@ -277,7 +278,7 @@ public class StudyUtils {
       return null;
     }
     //need this because of multi-module generation
-    if ("src".equals(taskDir.getName())) {
+    if (EduNames.SRC.equals(taskDir.getName())) {
       taskDir = taskDir.getParent();
       if (taskDir == null) {
         return null;
@@ -394,7 +395,7 @@ public class StudyUtils {
         return false;
       }
       String name = virtualFile.getName();
-      return !isTestsFile(project, name) && !EduNames.TASK_HTML.equals(name) && !EduNames.TASK_MD.equals(name);
+      return !isTestsFile(project, name) && !isTaskDescriptionFile(name);
     }
     if (element instanceof PsiDirectory) {
       VirtualFile virtualFile = ((PsiDirectory)element).getVirtualFile();
@@ -581,4 +582,28 @@ public class StudyUtils {
     
     return new MarkdownProcessor().markdown(StringUtil.join(lines, "\n"));
   }
+  
+  public static boolean isTaskDescriptionFile(@NotNull final String fileName) {
+    return EduNames.TASK_HTML.equals(fileName) || EduNames.TASK_MD.equals(fileName);
+  }
+  
+  @Nullable
+  public static VirtualFile findTaskDescriptionVirtualFile(@NotNull final VirtualFile parent) {
+    return ObjectUtils.chooseNotNull(parent.findChild(EduNames.TASK_HTML), parent.findChild(EduNames.TASK_MD));
+  }
+  
+  @NotNull
+  public static String getTaskDescriptionFileName(final boolean useHtml) {
+    return useHtml ? EduNames.TASK_HTML : EduNames.TASK_MD;    
+  }
+  
+  @Nullable
+  public static File createTaskDescriptionFile(@NotNull final File parent) {
+    if(new File(parent, EduNames.TASK_HTML).exists()) {
+      return new File(parent, EduNames.TASK_HTML);
+    }
+    else {
+      return new File(parent, EduNames.TASK_MD);
+    }
+  }
 }
index 3491f386dc6593cb5fe6ae8d146a3e2aaedd6bc7..71ca327a45be9b2d3d1aafa42a987d4f895c4aef 100644 (file)
@@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.xmlb.annotations.Transient;
+import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.core.EduNames;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -147,7 +148,7 @@ public class Task implements StudyItem {
     if (!StringUtil.isEmptyOrSpaces(text)) return text;
     final VirtualFile taskDir = getTaskDir(project);
     if (taskDir != null) {
-      final VirtualFile file = taskDir.findChild(EduNames.TASK_HTML);
+      final VirtualFile file = StudyUtils.findTaskDescriptionVirtualFile(taskDir);
       if (file == null) return "";
       final Document document = FileDocumentManager.getInstance().getDocument(file);
       if (document != null) {
index eca6e59322e10551821b30a3f74fce76bbd0d0ed..57b84b9f6df1de65db6f85ebb209bcfccbddb32f 100644 (file)
@@ -14,7 +14,6 @@ import com.jetbrains.edu.learning.StudyUtils;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
-import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
@@ -70,7 +69,7 @@ public class StudyGenerator {
           File resourceFile = new File(newResourceRoot, fileName);
           File fileInProject = new File(taskDir.getCanonicalPath(), fileName);
           FileUtil.copy(resourceFile, fileInProject);
-          if (!StudyUtils.isTestsFile(project, fileName) && !EduNames.TASK_HTML.equals(fileName) && !EduNames.TASK_MD.equals(fileName)) {
+          if (!StudyUtils.isTestsFile(project, fileName) && !StudyUtils.isTaskDescriptionFile(fileName)) {
             StudyTaskManager.getInstance(project).addInvisibleFiles(FileUtil.toSystemIndependentName(fileInProject.getPath()));
           }
         }
index 443c7ac523fc9b2c95730f59fe20cb5143270637..4b1e88f8dd65c658abcc38528435adc8c12a5c30 100644 (file)
@@ -79,7 +79,7 @@ public class StudyTreeStructureProvider implements TreeStructureProvider, DumbAw
     if (!StudyTaskManager.getInstance(project).isInvisibleFile(virtualFile.getPath())) {
       String fileName = virtualFile.getName();
       if (!fileName.contains(EduNames.WINDOW_POSTFIX) && !fileName.contains(EduNames.WINDOWS_POSTFIX)
-          && !StudyUtils.isTestsFile(project, fileName) && !EduNames.TASK_HTML.equals(fileName) && !EduNames.TASK_MD.equals(fileName)) {
+          && !StudyUtils.isTestsFile(project, fileName) && !StudyUtils.isTaskDescriptionFile(fileName)) {
         nodes.add(node);
       }
     }
index feb06b72159a898193fa3b6b1f490c96e8eb4027..846b93633f8749ab5fd84e061b0350d261b3cb17 100644 (file)
@@ -33,7 +33,6 @@ import com.intellij.ui.JBCardLayout;
 import com.intellij.ui.OnePixelSplitter;
 import com.intellij.util.ui.JBUI;
 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;
@@ -172,7 +171,7 @@ public abstract class StudyToolWindow extends SimpleToolWindowPanel implements D
         LOG.info("Failed to enter editing mode for StudyToolWindow");
         return;
       }
-      VirtualFile taskTextFile = taskDirectory.findChild(EduNames.TASK_HTML);
+      VirtualFile taskTextFile = StudyUtils.findTaskDescriptionVirtualFile(taskDirectory);
       enterEditingMode(taskTextFile, project);
       StudyTaskManager.getInstance(project).setTurnEditingMode(false);
     }