use of com.intellij.refactoring.move.MoveCallback in project intellij-plugins by StepicOrg.
the class AbstractMoveHandlerDelegate method doMove.
@Override
public void doMove(Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
List<PsiFileSystemItem> sources = Arrays.stream(elements).filter(psiElement -> isNotMovableOrRenameElement(psiElement, acceptableClasses)).map(ProjectPsiFilesUtils::getFile).filter(Objects::nonNull).collect(Collectors.toList());
StringBuilder message = new StringBuilder();
if (sources.size() > 1) {
message.append("You can not move the following elements:");
} else {
PsiFileSystemItem source = sources.get(0);
message.append("You can not move the ").append(source.isDirectory() ? "directory" : "file").append(":");
}
for (PsiFileSystemItem file : sources) {
message.append("\n").append(file.getVirtualFile().getPath());
}
MessagesEx.error(project, message.toString(), "Move").showNow();
}
use of com.intellij.refactoring.move.MoveCallback 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