mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not allow to invoke move refactoring (part of EDU-441)
This commit is contained in:
@@ -85,5 +85,6 @@
|
||||
serviceImplementation="com.jetbrains.edu.learning.StudyTaskManager"/>
|
||||
<extendWordSelectionHandler implementation="com.jetbrains.edu.learning.StudyAnswerPlaceholderExtendWordHandler"/>
|
||||
<renameHandler implementation="com.jetbrains.edu.learning.StudyRenameHandler"/>
|
||||
<refactoring.moveHandler implementation="com.jetbrains.edu.learning.StudyMoveDelegate" order="first"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.jetbrains.edu.learning;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.refactoring.move.MoveCallback;
|
||||
import com.intellij.refactoring.move.MoveHandlerDelegate;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class StudyMoveDelegate extends MoveHandlerDelegate{
|
||||
@Override
|
||||
public boolean canMove(DataContext dataContext) {
|
||||
return StudyUtils.canRenameOrMove(dataContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMove(PsiElement[] elements, @Nullable PsiElement targetContainer) {
|
||||
if (elements.length == 1) {
|
||||
Project project = elements[0].getProject();
|
||||
Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
if (course == null) {
|
||||
return false;
|
||||
}
|
||||
return !StudyUtils.isRenameableOrMoveable(project, course, elements[0]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidTarget(PsiElement psiElement, PsiElement[] sources) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doMove(final Project project,
|
||||
PsiElement[] elements,
|
||||
@Nullable PsiElement targetContainer,
|
||||
@Nullable MoveCallback callback) {
|
||||
Messages.showInfoMessage("This move operation can break the course", "Invalid Move Operation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryToMove(PsiElement element,
|
||||
Project project,
|
||||
DataContext dataContext,
|
||||
@Nullable PsiReference reference,
|
||||
Editor editor) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+2
-16
@@ -1,6 +1,5 @@
|
||||
package com.jetbrains.edu.learning;
|
||||
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -8,25 +7,12 @@ import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.refactoring.rename.RenameHandler;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class StudyRenameHandler implements RenameHandler {
|
||||
@Override
|
||||
public boolean isAvailableOnDataContext(DataContext dataContext) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
|
||||
if (element == null || project == null) {
|
||||
return false;
|
||||
}
|
||||
Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
if (course == null) {
|
||||
return false;
|
||||
}
|
||||
if (!StudyUtils.isRenameableOrMoveable(project, course, element)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return StudyUtils.canRenameOrMove(dataContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,7 +22,7 @@ public class StudyRenameHandler implements RenameHandler {
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
|
||||
Messages.showWarningDialog("This rename operation can break the course", "Invalid Rename Operation");
|
||||
Messages.showInfoMessage("This rename operation can break the course", "Invalid Rename Operation");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+18
@@ -5,6 +5,8 @@ import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -370,4 +372,20 @@ public class StudyUtils {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canRenameOrMove(DataContext dataContext) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
|
||||
if (element == null || project == null) {
|
||||
return false;
|
||||
}
|
||||
Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
if (course == null) {
|
||||
return false;
|
||||
}
|
||||
if (!isRenameableOrMoveable(project, course, element)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user