Resolve conflicts
[idea/community.git] / python / educational-core / student / src / com / jetbrains / edu / learning / StudyBasePluginConfigurator.java
1 package com.jetbrains.edu.learning;
2
3 import com.intellij.openapi.actionSystem.DefaultActionGroup;
4 import com.intellij.openapi.fileEditor.FileEditorManager;
5 import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
6 import com.intellij.openapi.fileEditor.FileEditorManagerListener;
7 import com.intellij.openapi.project.Project;
8 import com.intellij.openapi.vfs.VirtualFile;
9 import com.jetbrains.edu.learning.actions.*;
10 import com.jetbrains.edu.learning.courseFormat.Task;
11 import com.jetbrains.edu.learning.courseFormat.TaskFile;
12 import com.jetbrains.edu.learning.ui.StudyToolWindow;
13 import org.jetbrains.annotations.NotNull;
14 import org.jetbrains.annotations.Nullable;
15
16 import javax.swing.*;
17 import java.util.Collections;
18 import java.util.Map;
19
20 public abstract class StudyBasePluginConfigurator implements StudyPluginConfigurator {
21   @NotNull
22   @Override
23   public DefaultActionGroup getActionGroup(Project project) {
24     return getDefaultActionGroup();
25   }
26
27   @NotNull
28   public static DefaultActionGroup getDefaultActionGroup() {
29     final DefaultActionGroup group = new DefaultActionGroup();
30     group.add(new StudyPreviousStudyTaskAction());
31     group.add(new StudyNextStudyTaskAction());
32     group.add(new StudyRefreshTaskFileAction());
33     group.add(new StudyShowHintAction());
34
35     group.add(new StudyRunAction());
36     group.add(new StudyEditInputAction());
37     return group;
38   }
39
40   @NotNull
41   @Override
42   public Map<String, JPanel> getAdditionalPanels(Project project) {
43     return Collections.emptyMap();
44   }
45
46   @NotNull
47   @Override
48   public FileEditorManagerListener getFileEditorManagerListener(@NotNull Project project, @NotNull StudyToolWindow toolWindow) {
49
50     return new FileEditorManagerListener() {
51       @Override
52       public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
53         Task task = getTask(file);
54         setTaskText(task, file.getParent());
55       }
56
57       @Override
58       public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
59         toolWindow.setEmptyText(project);
60       }
61
62       @Override
63       public void selectionChanged(@NotNull FileEditorManagerEvent event) {
64         VirtualFile file = event.getNewFile();
65         if (file != null) {
66           Task task = getTask(file);
67           setTaskText(task, file.getParent());
68         }
69         toolWindow.setBottomComponent(null);
70       }
71
72       @Nullable
73       private Task getTask(@NotNull VirtualFile file) {
74         TaskFile taskFile = StudyUtils.getTaskFile(project, file);
75         if (taskFile != null) {
76           return taskFile.getTask();
77         }
78         else {
79           return null;
80         }
81       }
82
83       private void setTaskText(@Nullable final Task task, @Nullable final VirtualFile taskDirectory) {
84         String text = StudyUtils.getTaskTextFromTask(task, taskDirectory);
85         if (text == null) {
86           toolWindow.setEmptyText(project);
87           return;
88         }
89         toolWindow.setTaskText(text, taskDirectory, project);
90       }
91     };
92   }
93
94   @Nullable
95   @Override
96   public StudyAfterCheckAction[] getAfterCheckActions() {
97     return null;
98   }
99 }