mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
show warning dialog when rename was invoked from non-project file (IDEA-72328)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user