part of EDU-331(improving lesson and task management)
[idea/community.git] / python / educational / course-creator / src / com / jetbrains / edu / coursecreator / CCUtils.java
index 130952e8ebaa6343cb53bd56ba82873a48824ac6..1e82811a6d8d034fe56abd30cc82e04e02ff30ca 100644 (file)
@@ -1,6 +1,8 @@
 package com.jetbrains.edu.coursecreator;
 
 import com.intellij.ide.projectView.actions.MarkRootActionBase;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.Module;
@@ -36,4 +38,22 @@ public class CCUtils {
       }
     });
   }
+
+  public static void enableAction(@NotNull final AnActionEvent event, boolean isEnable) {
+    final Presentation presentation = event.getPresentation();
+    presentation.setVisible(isEnable);
+    presentation.setEnabled(isEnable);
+  }
+
+  public static int getIndex(@NotNull final String fullName, @NotNull final String logicalName) {
+    if (!fullName.startsWith(logicalName)) {
+      throw new IllegalArgumentException();
+    }
+    try {
+      return Integer.parseInt(fullName.substring(logicalName.length()));
+    }
+    catch (NumberFormatException e) {
+      return -1;
+    }
+  }
 }