Search in sources :

Example 51 with PsiDirectory

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

the class AbstractCreateFormAction method update.

public void update(final AnActionEvent e) {
    super.update(e);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final Presentation presentation = e.getPresentation();
    if (presentation.isEnabled()) {
        final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
        if (view != null) {
            final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
            final PsiDirectory[] dirs = view.getDirectories();
            for (final PsiDirectory dir : dirs) {
                if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
                    return;
                }
            }
        }
        presentation.setEnabled(false);
        presentation.setVisible(false);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Presentation(com.intellij.openapi.actionSystem.Presentation) IdeView(com.intellij.ide.IdeView)

Example 52 with PsiDirectory

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

the class CCCreateTask method createItemDir.

@Override
@Nullable
protected PsiDirectory createItemDir(@NotNull final Project project, @NotNull final StudyItem item, @Nullable final IdeView view, @NotNull final PsiDirectory parentDirectory, @NotNull final Course course) {
    CCTaskCreator creator = CCTaskCreator.INSTANCE.forLanguage(course.getLanguageById());
    if (creator != null) {
        return creator.createTask(project, item, view, parentDirectory, course);
    }
    final Ref<PsiDirectory> taskDirectory = new Ref<>();
    ApplicationManager.getApplication().runWriteAction(() -> {
        String taskDirName = EduNames.TASK + item.getIndex();
        taskDirectory.set(DirectoryUtil.createSubdirectories(taskDirName, parentDirectory, "\\/"));
        if (taskDirectory.get() != null) {
            CCUtils.createTaskContent(project, view, course, taskDirectory.get());
        }
    });
    return taskDirectory.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) PsiDirectory(com.intellij.psi.PsiDirectory) CCTaskCreator(com.jetbrains.edu.coursecreator.creation.CCTaskCreator) Nullable(org.jetbrains.annotations.Nullable)

Example 53 with PsiDirectory

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

the class CCNewSubtaskAction method createTaskDescriptionFile.

private static void createTaskDescriptionFile(Project project, VirtualFile taskDir, int index) {
    String taskDescriptionFileName = StudyUtils.getTaskDescriptionFileName(CCSettings.getInstance().useHtmlAsDefaultTaskFormat());
    FileTemplate taskTextTemplate = FileTemplateManager.getInstance(project).getInternalTemplate(taskDescriptionFileName);
    PsiDirectory taskPsiDir = PsiManager.getInstance(project).findDirectory(taskDir);
    if (taskTextTemplate != null && taskPsiDir != null) {
        String nextTaskTextName = FileUtil.getNameWithoutExtension(taskDescriptionFileName) + EduNames.SUBTASK_MARKER + index + "." + FileUtilRt.getExtension(taskDescriptionFileName);
        try {
            FileTemplateUtil.createFromTemplate(taskTextTemplate, nextTaskTextName, null, taskPsiDir);
        } catch (Exception e) {
            LOG.error(e);
        }
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 54 with PsiDirectory

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

the class CCEditAnswerPlaceholder method performAnswerPlaceholderAction.

@Override
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
    final Project project = state.getProject();
    PsiFile file = state.getFile();
    final PsiDirectory taskDir = file.getContainingDirectory();
    final PsiDirectory lessonDir = taskDir.getParent();
    if (lessonDir == null)
        return;
    AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
    if (answerPlaceholder == null) {
        return;
    }
    CCCreateAnswerPlaceholderDialog dlg = new CCCreateAnswerPlaceholderDialog(project, answerPlaceholder.getTaskText(), answerPlaceholder.getHints());
    dlg.setTitle("Edit Answer Placeholder");
    if (dlg.showAndGet()) {
        final String answerPlaceholderText = dlg.getTaskText();
        answerPlaceholder.setTaskText(answerPlaceholderText);
        answerPlaceholder.setLength(answerPlaceholder.getActiveSubtaskInfo().isNeedInsertText() ? 0 : StringUtil.notNullize(answerPlaceholderText).length());
        answerPlaceholder.setHints(dlg.getHints());
    }
}
Also used : Project(com.intellij.openapi.project.Project) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile)

Example 55 with PsiDirectory

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

the class CCLessonMoveHandlerDelegate method doMove.

@Override
public void doMove(final Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
    if (targetContainer == null || !(targetContainer instanceof PsiDirectory)) {
        return;
    }
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    final PsiDirectory sourceDirectory = (PsiDirectory) elements[0];
    final Lesson sourceLesson = course.getLesson(sourceDirectory.getName());
    final Lesson targetLesson = course.getLesson(((PsiDirectory) targetContainer).getName());
    if (targetLesson == null) {
        Messages.showInfoMessage("Lessons can be moved only to other lessons", "Incorrect Target For Move");
        return;
    }
    final CCMoveStudyItemDialog dialog = new CCMoveStudyItemDialog(project, EduNames.LESSON, targetLesson.getName());
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return;
    }
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            try {
                sourceDirectory.getVirtualFile().rename(this, "tmp");
            } catch (IOException e) {
                LOG.error(e);
            }
        }
    });
    final VirtualFile[] lessonDirs = project.getBaseDir().getChildren();
    final Function<VirtualFile, StudyItem> getStudyItem = file -> course.getLesson(file.getName());
    int sourceLessonIndex = sourceLesson.getIndex();
    sourceLesson.setIndex(-1);
    CCUtils.updateHigherElements(lessonDirs, getStudyItem, sourceLessonIndex, EduNames.LESSON, -1);
    final int newItemIndex = targetLesson.getIndex() + dialog.getIndexDelta();
    CCUtils.updateHigherElements(lessonDirs, getStudyItem, newItemIndex - 1, EduNames.LESSON, 1);
    sourceLesson.setIndex(newItemIndex);
    Collections.sort(course.getLessons(), EduUtils.INDEX_COMPARATOR);
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            try {
                sourceDirectory.getVirtualFile().rename(this, EduNames.LESSON + newItemIndex);
            } catch (IOException e) {
                LOG.error(e);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MoveHandlerDelegate(com.intellij.refactoring.move.MoveHandlerDelegate) DataContext(com.intellij.openapi.actionSystem.DataContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeView(com.intellij.ide.IdeView) EduUtils(com.jetbrains.edu.learning.core.EduUtils) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) MoveCallback(com.intellij.refactoring.move.MoveCallback) CCMoveStudyItemDialog(com.jetbrains.edu.coursecreator.ui.CCMoveStudyItemDialog) PsiReference(com.intellij.psi.PsiReference) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) IOException(java.io.IOException) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) Editor(com.intellij.openapi.editor.Editor) DirectoryChooserUtil(com.intellij.ide.util.DirectoryChooserUtil) Nullable(org.jetbrains.annotations.Nullable) Function(com.intellij.util.Function) EduNames(com.jetbrains.edu.learning.core.EduNames) StudyItem(com.jetbrains.edu.learning.courseFormat.StudyItem) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiDirectory(com.intellij.psi.PsiDirectory) LangDataKeys(com.intellij.openapi.actionSystem.LangDataKeys) Collections(java.util.Collections) CCUtils(com.jetbrains.edu.coursecreator.CCUtils) Course(com.jetbrains.edu.learning.courseFormat.Course) IOException(java.io.IOException) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) PsiDirectory(com.intellij.psi.PsiDirectory) Course(com.jetbrains.edu.learning.courseFormat.Course) CCMoveStudyItemDialog(com.jetbrains.edu.coursecreator.ui.CCMoveStudyItemDialog) StudyItem(com.jetbrains.edu.learning.courseFormat.StudyItem)

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