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>
\ No newline at end of file
--- /dev/null
+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;
+ }
+}
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;
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
@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
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;
}
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;
+ }
}