compute initial state of placeholder correctly phpstorm/163.586
authorliana.bakradze <liana.bakradze@jetbrains.com>
Sun, 26 Jun 2016 10:50:58 +0000 (13:50 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Sun, 26 Jun 2016 10:50:58 +0000 (13:50 +0300)
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCRefactoringElementListenerProvider.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCAddAnswerPlaceholder.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCHideFromStudent.java
python/educational-core/student/src/com/jetbrains/edu/learning/StudyUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshAnswerPlaceholder.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshTaskFileAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/TaskFile.java

index 75634c0a9026fd21468fae82742f580d9ffc0082..86121ab4340f3639f0efe51ccb23049c6ab270fd 100644 (file)
@@ -95,7 +95,7 @@ public class CCRefactoringElementListenerProvider implements RefactoringElementL
         return;
       }
       ApplicationManager.getApplication().runWriteAction(() -> {
         return;
       }
       ApplicationManager.getApplication().runWriteAction(() -> {
-        VirtualFile patternFile = StudyUtils.getPatternFile(project, taskFile, oldName);
+        VirtualFile patternFile = StudyUtils.getPatternFile(taskFile, oldName);
         if (patternFile != null) {
           try {
             patternFile.delete(CCRefactoringElementListenerProvider.class);
         if (patternFile != null) {
           try {
             patternFile.delete(CCRefactoringElementListenerProvider.class);
index edd3a7f240ac260c66e97129a1ab2debd8053860..66e036be3f03a11a71608d015710eb77112642e2 100644 (file)
@@ -221,7 +221,7 @@ public class CCUtils {
       if (child == null) {
         continue;
       }
       if (child == null) {
         continue;
       }
-      Document patternDocument = StudyUtils.getPatternDocument(project, entry.getValue(), name);
+      Document patternDocument = StudyUtils.getPatternDocument(entry.getValue(), name);
       Document document = FileDocumentManager.getInstance().getDocument(child);
       if (document == null || patternDocument == null) {
         return;
       Document document = FileDocumentManager.getInstance().getDocument(child);
       if (document == null || patternDocument == null) {
         return;
index 0643eaa8cf0cb66d6dd1bf5d7ddf9455968ce22f..2ad1d79faf1fb5776b10d5163992b878dbf8a6ee 100644 (file)
@@ -84,7 +84,7 @@ public class CCAddAnswerPlaceholder extends CCAnswerPlaceholderAction {
   }
 
   private static void computeInitialState(Project project, PsiFile file, TaskFile taskFile, Document document) {
   }
 
   private static void computeInitialState(Project project, PsiFile file, TaskFile taskFile, Document document) {
-    Document patternDocument = StudyUtils.getPatternDocument(project, taskFile, file.getName());
+    Document patternDocument = StudyUtils.getPatternDocument(taskFile, file.getName());
     if (patternDocument == null) {
       return;
     }
     if (patternDocument == null) {
       return;
     }
@@ -102,8 +102,7 @@ public class CCAddAnswerPlaceholder extends CCAnswerPlaceholderAction {
 
     for (int i = 0; i < placeholders.size(); i++) {
       AnswerPlaceholder fromPlaceholder = placeholders.get(i);
 
     for (int i = 0; i < placeholders.size(); i++) {
       AnswerPlaceholder fromPlaceholder = placeholders.get(i);
-      AnswerPlaceholder.MyInitialState state = fromPlaceholder.getInitialState();
-      taskFile.getAnswerPlaceholders().get(i).setInitialState(new AnswerPlaceholder.MyInitialState(state.getOffset(), state.getLength()));
+      taskFile.getAnswerPlaceholders().get(i).setInitialState(new AnswerPlaceholder.MyInitialState(fromPlaceholder.getOffset(), fromPlaceholder.getLength()));
     }
   }
 
     }
   }
 
index 9ac18ba159a3ab9bd21e565bf9fe0287e76d53ec..07cd46cfdf200e8249564d2b0518d2c4007b9ee6 100644 (file)
@@ -24,7 +24,7 @@ public class CCHideFromStudent extends CCTaskFileActionBase {
       return;
     }
     String name = file.getName();
       return;
     }
     String name = file.getName();
-    VirtualFile patternFile = StudyUtils.getPatternFile(project, taskFile, name);
+    VirtualFile patternFile = StudyUtils.getPatternFile(taskFile, name);
     ApplicationManager.getApplication().runWriteAction(() -> {
       if (patternFile != null) {
         try {
     ApplicationManager.getApplication().runWriteAction(() -> {
       if (patternFile != null) {
         try {
index 020dbc27f58e4842b925beeeb10385ecfd272a7c..0be991e4c931466c98c9192342958b530bc6255d 100644 (file)
@@ -393,12 +393,12 @@ public class StudyUtils {
 
 
   @Nullable
 
 
   @Nullable
-  public static VirtualFile getPatternFile(@NotNull Project project, @NotNull TaskFile taskFile, String name) {
+  public static VirtualFile getPatternFile(@NotNull TaskFile taskFile, String name) {
     Task task = taskFile.getTask();
     String lessonDir = EduNames.LESSON + String.valueOf(task.getLesson().getIndex());
     String taskDir = EduNames.TASK + String.valueOf(task.getIndex());
     Course course = task.getLesson().getCourse();
     Task task = taskFile.getTask();
     String lessonDir = EduNames.LESSON + String.valueOf(task.getLesson().getIndex());
     String taskDir = EduNames.TASK + String.valueOf(task.getIndex());
     Course course = task.getLesson().getCourse();
-    File resourceFile = getCourseDirectory(project, course);
+    File resourceFile = new File(course.getCourseDirectory());
     if (!resourceFile.exists()) {
       return null;
     }
     if (!resourceFile.exists()) {
       return null;
     }
@@ -411,8 +411,8 @@ public class StudyUtils {
   }
 
   @Nullable
   }
 
   @Nullable
-  public static Document getPatternDocument(@NotNull Project project, @NotNull final TaskFile taskFile, String name) {
-    VirtualFile patternFile = getPatternFile(project, taskFile, name);
+  public static Document getPatternDocument(@NotNull final TaskFile taskFile, String name) {
+    VirtualFile patternFile = getPatternFile(taskFile, name);
     if (patternFile == null) {
       return null;
     }
     if (patternFile == null) {
       return null;
     }
index 987819c83ffe6b320216e1e465b75acdac16e504..de68d1cfc95170be39cfea48846570a8761dafb1 100644 (file)
@@ -45,7 +45,7 @@ public class StudyRefreshAnswerPlaceholder extends DumbAwareAction {
     }
     StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
     final StudyState studyState = new StudyState(studyEditor);
     }
     StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
     final StudyState studyState = new StudyState(studyEditor);
-    Document patternDocument = StudyUtils.getPatternDocument(project, answerPlaceholder.getTaskFile(), studyState.getVirtualFile().getName());
+    Document patternDocument = StudyUtils.getPatternDocument(answerPlaceholder.getTaskFile(), studyState.getVirtualFile().getName());
     if (patternDocument == null) {
       return;
     }
     if (patternDocument == null) {
       return;
     }
index 83ba428b17adf8f31a6d8df091bfeb7a45c96e10..c4046496b736954c61d3189eb67ebd817d7de3b4 100644 (file)
@@ -82,7 +82,7 @@ public class StudyRefreshTaskFileAction extends StudyActionWithShortcut {
                                        @NotNull final Project project,
                                        TaskFile taskFile,
                                        String name) {
                                        @NotNull final Project project,
                                        TaskFile taskFile,
                                        String name) {
-    if (!resetDocument(project, document, taskFile, name)) {
+    if (!resetDocument(document, taskFile, name)) {
       return false;
     }
     taskFile.getTask().setStatus(StudyStatus.Unchecked);
       return false;
     }
     taskFile.getTask().setStatus(StudyStatus.Unchecked);
@@ -111,11 +111,10 @@ public class StudyRefreshTaskFileAction extends StudyActionWithShortcut {
   }
 
 
   }
 
 
-  private static boolean resetDocument(@NotNull final Project project, 
-                                       @NotNull final Document document, 
+  private static boolean resetDocument(@NotNull final Document document,
                                        @NotNull final TaskFile taskFile,
                                        String fileName) {
                                        @NotNull final TaskFile taskFile,
                                        String fileName) {
-    final Document patternDocument = StudyUtils.getPatternDocument(project, taskFile, fileName);
+    final Document patternDocument = StudyUtils.getPatternDocument(taskFile, fileName);
     if (patternDocument == null) {
       return false;
     }
     if (patternDocument == null) {
       return false;
     }
index 1223f43f3d10bb17cadfde3953b55c2692ca054a..31eb6f19a7435548496718ad889b5d33eccfacbc 100644 (file)
@@ -99,7 +99,9 @@ public class TaskFile {
       answerPlaceholderCopy.setIndex(answerPlaceholder.getIndex());
       answerPlaceholderCopy.setHint(answerPlaceholder.getHint());
       final AnswerPlaceholder.MyInitialState state = answerPlaceholder.getInitialState();
       answerPlaceholderCopy.setIndex(answerPlaceholder.getIndex());
       answerPlaceholderCopy.setHint(answerPlaceholder.getHint());
       final AnswerPlaceholder.MyInitialState state = answerPlaceholder.getInitialState();
-      answerPlaceholderCopy.setInitialState(new AnswerPlaceholder.MyInitialState(state.getOffset(), state.getLength()));
+      if (state != null) {
+        answerPlaceholderCopy.setInitialState(new AnswerPlaceholder.MyInitialState(state.getOffset(), state.getLength()));
+      }
       answerPlaceholdersCopy.add(answerPlaceholderCopy);
     }
     target.name = source.name;
       answerPlaceholdersCopy.add(answerPlaceholderCopy);
     }
     target.name = source.name;