Search in sources :

Example 56 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class CCRenameHandler method isAvailableOnDataContext.

@Override
public boolean isAvailableOnDataContext(DataContext dataContext) {
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (element == null || !(element instanceof PsiDirectory)) {
        return false;
    }
    if (!CCUtils.isCourseCreator(element.getProject())) {
        return false;
    }
    VirtualFile directory = ((PsiDirectory) element).getVirtualFile();
    return isAvailable(directory);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiElement(com.intellij.psi.PsiElement)

Example 57 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class CCTaskMoveHandlerDelegate method canMove.

@Override
public boolean canMove(DataContext dataContext) {
    if (CommonDataKeys.PSI_FILE.getData(dataContext) != null) {
        return false;
    }
    IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return false;
    }
    PsiDirectory sourceDirectory = DirectoryChooserUtil.getOrChooseDirectory(view);
    return isTaskDir(sourceDirectory);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView)

Example 58 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class CCTaskRenameHandler method rename.

@Override
protected void rename(@NotNull Project project, @NotNull Course course, @NotNull PsiDirectory directory) {
    if (directory.getName().equals(EduNames.SRC)) {
        directory = directory.getParent();
        if (directory == null) {
            return;
        }
    }
    PsiDirectory lessonDir = directory.getParent();
    if (lessonDir == null || !lessonDir.getName().contains(EduNames.LESSON)) {
        return;
    }
    Lesson lesson = course.getLesson(lessonDir.getName());
    if (lesson == null) {
        return;
    }
    String directoryName = directory.getName();
    Task task = lesson.getTask(directoryName);
    if (task != null) {
        processRename(task, EduNames.TASK, project);
    }
}
Also used : Task(com.jetbrains.edu.learning.courseFormat.Task) PsiDirectory(com.intellij.psi.PsiDirectory) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson)

Example 59 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class CCPushLesson method update.

@Override
public void update(@NotNull AnActionEvent e) {
    e.getPresentation().setEnabledAndVisible(false);
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (view == null || project == null) {
        return;
    }
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    if (!course.getCourseMode().equals(CCUtils.COURSE_MODE))
        return;
    PsiDirectory lessonDir = DirectoryChooserUtil.getOrChooseDirectory(view);
    if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
        return;
    }
    final Lesson lesson = course.getLesson(lessonDir.getName());
    if (lesson != null && course.getId() > 0) {
        e.getPresentation().setEnabledAndVisible(true);
        if (lesson.getId() <= 0) {
            e.getPresentation().setText("Upload Lesson to Stepik");
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) Course(com.jetbrains.edu.learning.courseFormat.Course) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson)

Example 60 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class CCPushTask method update.

@Override
public void update(@NotNull AnActionEvent e) {
    e.getPresentation().setEnabledAndVisible(false);
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (view == null || project == null) {
        return;
    }
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    if (!course.getCourseMode().equals(CCUtils.COURSE_MODE))
        return;
    PsiDirectory taskDir = DirectoryChooserUtil.getOrChooseDirectory(view);
    if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
        return;
    }
    final PsiDirectory lessonDir = taskDir.getParentDirectory();
    if (lessonDir == null)
        return;
    final Lesson lesson = course.getLesson(lessonDir.getName());
    if (lesson != null && lesson.getId() > 0 && course.getId() > 0) {
        e.getPresentation().setEnabledAndVisible(true);
        final com.jetbrains.edu.learning.courseFormat.Task task = lesson.getTask(taskDir.getName());
        if (task.getStepId() <= 0) {
            e.getPresentation().setText("Upload Task to Stepik");
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) Course(com.jetbrains.edu.learning.courseFormat.Course) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson)

Aggregations

PsiDirectory (com.intellij.psi.PsiDirectory)321 VirtualFile (com.intellij.openapi.vfs.VirtualFile)122 PsiFile (com.intellij.psi.PsiFile)111 PsiElement (com.intellij.psi.PsiElement)79 Project (com.intellij.openapi.project.Project)73 Module (com.intellij.openapi.module.Module)68 Nullable (org.jetbrains.annotations.Nullable)62 NotNull (org.jetbrains.annotations.NotNull)50 IdeView (com.intellij.ide.IdeView)31 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)24 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)24 PsiManager (com.intellij.psi.PsiManager)24 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 ArrayList (java.util.ArrayList)20 PsiPackage (com.intellij.psi.PsiPackage)17 File (java.io.File)15 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)11 IncorrectOperationException (com.intellij.util.IncorrectOperationException)11 Course (com.jetbrains.edu.learning.courseFormat.Course)11 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)10