show warning dialog when rename was invoked from non-project file (IDEA-72328)

This commit is contained in:
anna
2011-08-02 19:01:05 +04:00
parent 183f6cdcc0
commit bb8f9dfc50
2 changed files with 13 additions and 1 deletions
@@ -18,6 +18,7 @@ package com.intellij.refactoring;
import com.intellij.CommonBundle;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.PropertyKey;
import java.lang.ref.Reference;
@@ -67,7 +68,7 @@ public class RefactoringBundle {
return message("visibility.escalate");
}
public static String getCannotRefactorMessage(final String message) {
public static String getCannotRefactorMessage(@Nullable final String message) {
return message("cannot.perform.refactoring") + (message == null ? "" : "\n" + message);
}
@@ -29,6 +29,7 @@ import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
@@ -80,6 +81,16 @@ public class PsiElementRenameHandler implements RenameHandler {
if (element != null && !canRename(project, editor, element)) {
return;
}
if (nameSuggestionContext != null && !PsiManager.getInstance(project).isInProject(nameSuggestionContext)) {
final String message = "Selected element is used from non-project files. These usages won't be renamed. Proceed anyway?";
if (ApplicationManager.getApplication().isUnitTestMode()) throw new CommonRefactoringUtil.RefactoringErrorHintException(message);
if (Messages.showYesNoDialog(project, message,
RefactoringBundle.getCannotRefactorMessage(null), Messages.getWarningIcon()) != DialogWrapper.OK_EXIT_CODE) {
return;
}
}
FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.rename");
rename(element, project, nameSuggestionContext, editor);