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);
}
}
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();
}
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);
}
}
}
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());
}
}
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);
}
}
});
}
Aggregations