diff --git a/python/edu/course-creator/resources/META-INF/plugin.xml b/python/edu/course-creator/resources/META-INF/plugin.xml
index 0e984b2fcb65..1b6dfc9c61af 100644
--- a/python/edu/course-creator/resources/META-INF/plugin.xml
+++ b/python/edu/course-creator/resources/META-INF/plugin.xml
@@ -58,6 +58,12 @@
+
+
+
+
+
+
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectComponent.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectComponent.java
index d5e3085f0f07..20e7753e0247 100644
--- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectComponent.java
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectComponent.java
@@ -151,7 +151,7 @@ public class CCProjectComponent implements ProjectComponent {
if (task == null) {
return;
}
- lesson.getTasklist().remove(task);
+ lesson.getTaskList().remove(task);
lesson.getTasksMap().remove(removedFile.getName());
}
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java
index 17bb8013e2a7..c06925e9a453 100644
--- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java
@@ -71,6 +71,9 @@ public class CCProjectService implements PersistentStateComponent {
@Override
public void loadState(Element el) {
myCourse = XmlSerializer.deserialize(el.getChild(COURSE_ELEMENT), Course.class);
+ if (myCourse != null) {
+ myCourse.init();
+ }
}
public static CCProjectService getInstance(@NotNull Project project) {
@@ -155,7 +158,7 @@ public class CCProjectService implements PersistentStateComponent {
}
Lesson lesson = lessons.get(lessonIndex);
int taskIndex = getIndex(taskDirName, "task");
- List tasks = lesson.getTasklist();
+ List tasks = lesson.getTaskList();
if (!indexIsValid(taskIndex, tasks)) {
return false;
}
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCRunTests.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCRunTests.java
index a0e2efa36c55..d078972e3f56 100644
--- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCRunTests.java
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCRunTests.java
@@ -228,8 +228,8 @@ public class CCRunTests extends AnAction {
.createChildDirectory(project, taskDir.getName());
if (CCProjectService.indexIsValid(lessonIndex, course.getLessons())) {
Lesson lesson = course.getLessons().get(lessonIndex);
- if (CCProjectService.indexIsValid(index, lesson.getTasklist())) {
- Task task = lesson.getTasklist().get(index);
+ if (CCProjectService.indexIsValid(index, lesson.getTaskList())) {
+ Task task = lesson.getTaskList().get(index);
HashMap taskFilesCopy = new HashMap();
for (Map.Entry entry : task.getTaskFiles().entrySet()) {
CreateCourseArchive.createUserFile(project, taskFilesCopy, taskResourceDir, taskDir, entry);
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRename.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRename.java
new file mode 100644
index 000000000000..ae6c3906f186
--- /dev/null
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRename.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.coursecreator.actions;
+
+import com.intellij.ide.IdeView;
+import com.intellij.ide.projectView.ProjectView;
+import com.intellij.ide.util.DirectoryChooserUtil;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.CommonDataKeys;
+import com.intellij.openapi.actionSystem.LangDataKeys;
+import com.intellij.openapi.actionSystem.Presentation;
+import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiDirectory;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.coursecreator.CCProjectService;
+import org.jetbrains.plugins.coursecreator.format.Course;
+
+import javax.swing.*;
+
+public abstract class CCRename extends DumbAwareAction {
+ public CCRename(String text, String description, Icon icon) {
+ super(text, description, icon);
+ }
+
+ @Override
+ public void update(@NotNull AnActionEvent event) {
+ final Presentation presentation = event.getPresentation();
+ final Project project = event.getData(CommonDataKeys.PROJECT);
+ if (project == null) {
+ presentation.setVisible(false);
+ presentation.setEnabled(false);
+ return;
+ }
+
+ final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
+ if (view == null) {
+ presentation.setVisible(false);
+ presentation.setEnabled(false);
+ return;
+ }
+
+ final PsiDirectory[] directories = view.getDirectories();
+ if (directories.length == 0) {
+ presentation.setVisible(false);
+ presentation.setEnabled(false);
+ return;
+ }
+ final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
+ if (directory == null || !directory.getName().contains(getFolderName())) {
+ presentation.setEnabled(false);
+ presentation.setVisible(false);
+ return;
+ }
+ presentation.setVisible(true);
+ presentation.setEnabled(true);
+ }
+
+ public abstract String getFolderName();
+
+ @Override
+ public void actionPerformed(@NotNull AnActionEvent e) {
+ final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
+ final Project project = e.getData(CommonDataKeys.PROJECT);
+
+ if (view == null || project == null) {
+ return;
+ }
+ final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
+ if (directory == null || !directory.getName().contains("lesson")) {
+ return;
+ }
+ Course course = CCProjectService.getInstance(project).getCourse();
+ if (course == null) {
+ return;
+ }
+ if (!processRename(project, directory, course)) return;
+ ProjectView.getInstance(project).refresh();
+ }
+
+ public abstract boolean processRename(Project project, PsiDirectory directory, Course course);
+}
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRenameLesson.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRenameLesson.java
new file mode 100644
index 000000000000..3f580454ed6e
--- /dev/null
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRenameLesson.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.coursecreator.actions;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.Messages;
+import com.intellij.psi.PsiDirectory;
+import org.jetbrains.plugins.coursecreator.format.Course;
+import org.jetbrains.plugins.coursecreator.format.Lesson;
+
+public class CCRenameLesson extends CCRename {
+
+ public CCRenameLesson() {
+ super("Rename Lesson", "Rename Lesson", null);
+ }
+
+ @Override
+ public String getFolderName() {
+ return "lesson";
+ }
+
+ @Override
+ public boolean processRename(Project project, PsiDirectory directory, Course course) {
+ Lesson lesson = course.getLesson(directory.getName());
+ if (lesson == null) {
+ return false;
+ }
+ String newName = Messages.showInputDialog(project, "Enter new name", "Rename " + getFolderName(), null);
+ if (newName == null) {
+ return false;
+ }
+ lesson.setName(newName);
+ return true;
+ }
+}
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRenameTask.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRenameTask.java
new file mode 100644
index 000000000000..342621bf0d47
--- /dev/null
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRenameTask.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.coursecreator.actions;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.Messages;
+import com.intellij.psi.PsiDirectory;
+import org.jetbrains.plugins.coursecreator.format.Course;
+import org.jetbrains.plugins.coursecreator.format.Lesson;
+import org.jetbrains.plugins.coursecreator.format.Task;
+
+public class CCRenameTask extends CCRename {
+ public CCRenameTask() {
+ super("Rename Task", "Rename Task", null);
+ }
+
+ @Override
+ public String getFolderName() {
+ return "task";
+ }
+
+ @Override
+ public boolean processRename(Project project, PsiDirectory directory, Course course) {
+ PsiDirectory lessonDir = directory.getParent();
+ if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
+ return false;
+ }
+ Lesson lesson = course.getLesson(lessonDir.getName());
+ if (lesson == null) {
+ return false;
+ }
+ Task task = lesson.getTask(directory.getName());
+ if (task == null) {
+ return false;
+ }
+ String newName = Messages.showInputDialog(project, "Enter new name", "Rename " + getFolderName(), null);
+ if (newName == null) {
+ return false;
+ }
+ task.setName(newName);
+ return true;
+
+ }
+}
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CreateTask.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CreateTask.java
index aa33ccc23a9b..57a37b3f4194 100644
--- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CreateTask.java
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CreateTask.java
@@ -18,6 +18,7 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.util.PlatformIcons;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.coursecreator.CCProjectService;
import org.jetbrains.plugins.coursecreator.format.Course;
import org.jetbrains.plugins.coursecreator.format.Lesson;
@@ -42,7 +43,7 @@ public class CreateTask extends DumbAwareAction {
final CCProjectService service = CCProjectService.getInstance(project);
final Course course = service.getCourse();
final Lesson lesson = course.getLesson(directory.getName());
- final int size = lesson.getTasklist().size();
+ final int size = lesson.getTaskList().size();
final String taskName = Messages.showInputDialog("Name:", "Task Name", null, "task" + (size + 1), null);
if (taskName == null) return;
@@ -83,7 +84,7 @@ public class CreateTask extends DumbAwareAction {
}
@Override
- public void update(AnActionEvent event) {
+ public void update(@NotNull AnActionEvent event) {
final Presentation presentation = event.getPresentation();
final Project project = event.getData(CommonDataKeys.PROJECT);
if (project == null) {
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Course.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Course.java
index eb62d59cd9b1..e124a6eb305d 100644
--- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Course.java
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Course.java
@@ -4,10 +4,7 @@ import com.google.gson.annotations.Expose;
import com.intellij.psi.PsiDirectory;
import org.jetbrains.annotations.NotNull;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class Course {
@Expose public List lessons = new ArrayList();
@@ -52,4 +49,13 @@ public class Course {
public String getDescription() {
return description;
}
+
+ public void init() {
+ lessons.clear();
+ for (Lesson lesson: myLessonsMap.values()) {
+ lessons.add(lesson);
+ lesson.init();
+ }
+ Collections.sort(lessons);
+ }
}
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Lesson.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Lesson.java
index 69aa748bf873..bd91e8ec30af 100644
--- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Lesson.java
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Lesson.java
@@ -4,12 +4,9 @@ import com.google.gson.annotations.Expose;
import com.intellij.psi.PsiDirectory;
import org.jetbrains.annotations.NotNull;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
-public class Lesson {
+public class Lesson implements Comparable{
@Expose public String name;
@Expose public List task_list = new ArrayList();
@@ -27,11 +24,15 @@ public class Lesson {
task_list.add(task);
}
+ public void setName(String name) {
+ this.name = name;
+ }
+
public Task getTask(@NotNull final String name) {
return myTasksMap.get(name);
}
- public List getTasklist() {
+ public List getTaskList() {
return task_list;
}
@@ -46,4 +47,18 @@ public class Lesson {
public Map getTasksMap() {
return myTasksMap;
}
+
+ public void init() {
+ task_list.clear();
+ for (Task task : myTasksMap.values()) {
+ task_list.add(task);
+ }
+ Collections.sort(task_list);
+ }
+
+ @Override
+ public int compareTo(@NotNull Object o) {
+ Lesson lesson = (Lesson) o;
+ return myIndex - lesson.getIndex();
+ }
}
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Task.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Task.java
index e1e9923653f7..886add86ceb4 100644
--- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Task.java
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Task.java
@@ -7,7 +7,7 @@ import org.jetbrains.plugins.coursecreator.CCProjectService;
import java.util.HashMap;
import java.util.Map;
-public class Task {
+public class Task implements Comparable{
@Expose public String name;
@Expose public Map task_files = new HashMap();
public int myIndex;
@@ -44,4 +44,14 @@ public class Task {
public boolean isTaskFile(String name) {
return task_files.get(name) != null;
}
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int compareTo(@NotNull Object o) {
+ Task task = (Task) o;
+ return myIndex - task.getIndex();
+ }
}