EDU-425 Show actual lesson name dbe/163.2174
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 2 Aug 2016 16:35:23 +0000 (19:35 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 2 Aug 2016 16:35:23 +0000 (19:35 +0300)
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/handlers/CCRenameHandler.java
python/educational-core/student/resources/META-INF/plugin.xml
python/educational-core/student/src/com/jetbrains/edu/learning/StudyTabTitleProvider.java [new file with mode: 0644]

index e98ba1ab133f27b4b989880324fba8666271b6c5..9814a6631fe23c4d5ed1397ac4145defc18734b8 100644 (file)
@@ -4,6 +4,7 @@ import com.intellij.ide.projectView.ProjectView;
 import com.intellij.openapi.actionSystem.CommonDataKeys;
 import com.intellij.openapi.actionSystem.DataContext;
 import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.text.StringUtil;
@@ -50,6 +51,10 @@ public abstract class CCRenameHandler implements RenameHandler {
     }
     rename(project, course, directory);
     ProjectView.getInstance(project).refresh();
+    FileEditorManagerEx managerEx = FileEditorManagerEx.getInstanceEx(project);
+    for (VirtualFile virtualFile : managerEx.getOpenFiles()) {
+      managerEx.updateFilePresentation(virtualFile);
+    }
   }
 
   protected abstract void rename(@NotNull Project project, @NotNull Course course, @NotNull PsiDirectory directory);
index a5ac8e742d05e3e831e842398bc58061841cbafb..c0ad88e0a78843e002f2cd7a9bad21b415c0a554 100644 (file)
     <statistics.usagesCollector implementation="com.jetbrains.edu.learning.statistics.EduUsagesCollector"/>
     <applicationService serviceImplementation="com.jetbrains.edu.learning.statistics.EduUsagesCollector"/>
     <applicationService serviceImplementation="com.jetbrains.edu.learning.stepic.StepicUpdateSettings"/>
+    <editorTabTitleProvider implementation="com.jetbrains.edu.learning.StudyTabTitleProvider"/>
   </extensions>
 
   <extensions defaultExtensionNs="Edu">
diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/StudyTabTitleProvider.java b/python/educational-core/student/src/com/jetbrains/edu/learning/StudyTabTitleProvider.java
new file mode 100644 (file)
index 0000000..e2a96a1
--- /dev/null
@@ -0,0 +1,45 @@
+package com.jetbrains.edu.learning;
+
+import com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider;
+import com.intellij.openapi.fileEditor.impl.UniqueNameEditorTabTitleProvider;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.jetbrains.edu.learning.core.EduNames;
+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.Nullable;
+
+import java.io.File;
+
+public class StudyTabTitleProvider implements EditorTabTitleProvider {
+  @Nullable
+  @Override
+  public String getEditorTabTitle(Project project, VirtualFile file) {
+    TaskFile taskFile = StudyUtils.getTaskFile(project, file);
+    if (taskFile == null) {
+      return null;
+    }
+    String title = new UniqueNameEditorTabTitleProvider().getEditorTabTitle(project, file);
+    if (title == null) {
+      return null;
+    }
+    String[] split = title.split(File.separator);
+    for (int i = 0; i < split.length; i++) {
+      String part = split[i];
+      Task task = taskFile.getTask();
+      VirtualFile taskDir = task.getTaskDir(project);
+      if (taskDir != null && part.equals(taskDir.getName())) {
+        split[i] = task.getName();
+        continue;
+      }
+      Lesson lesson = task.getLesson();
+      int lessonIndex = lesson.getIndex();
+      if (part.equals(EduNames.LESSON + lessonIndex)) {
+        split[i] = lesson.getName();
+      }
+    }
+    return StringUtil.join(split, File.separator);
+  }
+}