From 88c8c3103c6e510348bc67eef8d81c8a079620e1 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 3 Feb 2010 15:59:27 +0300 Subject: [PATCH] show hint when refactoring cannot be invoked --- .../actions/CyclicDependenciesAction.java | 6 ++-- .../refactoring/actions/BaseRefactoringAction.java | 32 +++++++++++++--------- .../rename/PsiElementRenameHandler.java | 2 +- .../src/messages/RefactoringBundle.properties | 3 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/java/java-impl/src/com/intellij/cyclicDependencies/actions/CyclicDependenciesAction.java b/java/java-impl/src/com/intellij/cyclicDependencies/actions/CyclicDependenciesAction.java index b1765a431d..615f21a72f 100644 --- a/java/java-impl/src/com/intellij/cyclicDependencies/actions/CyclicDependenciesAction.java +++ b/java/java-impl/src/com/intellij/cyclicDependencies/actions/CyclicDependenciesAction.java @@ -36,12 +36,12 @@ import javax.swing.*; */ public class CyclicDependenciesAction extends AnAction{ private final String myAnalysisVerb; - private final String myAnalysisNoon; + private final String myAnalysisNoun; private final String myTitle; public CyclicDependenciesAction() { myAnalysisVerb = AnalysisScopeBundle.message("action.analyze.verb"); - myAnalysisNoon = AnalysisScopeBundle.message("action.analysis.noun"); + myAnalysisNoun = AnalysisScopeBundle.message("action.analysis.noun"); myTitle = AnalysisScopeBundle.message("action.cyclic.dependency.title"); } @@ -167,7 +167,7 @@ public class CyclicDependenciesAction extends AnAction{ } protected JComponent createCenterPanel() { - myScopePanel.setBorder(IdeBorderFactory.createTitledBorder(AnalysisScopeBundle.message("analysis.scope.title", myAnalysisNoon))); + myScopePanel.setBorder(IdeBorderFactory.createTitledBorder(AnalysisScopeBundle.message("analysis.scope.title", myAnalysisNoun))); myProjectButton.setText(AnalysisScopeBundle.message("cyclic.dependencies.scope.dialog.project.button", myAnalysisVerb)); ButtonGroup group = new ButtonGroup(); group.add(myProjectButton); diff --git a/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java b/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java index 02d8bf753c..54e76c51dc 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java +++ b/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java @@ -26,6 +26,8 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtilBase; import com.intellij.refactoring.RefactoringActionHandler; +import com.intellij.refactoring.RefactoringBundle; +import com.intellij.refactoring.util.CommonRefactoringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,7 +56,11 @@ public abstract class BaseRefactoringAction extends AnAction { final PsiElement[] elements = getPsiElementArray(dataContext); int eventCount = IdeEventQueue.getInstance().getEventCount(); RefactoringActionHandler handler = getHandler(dataContext); - if (handler == null) return; + if (handler == null) { + CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message( + "error.wrong.caret.position.symbol.to.refactor")), RefactoringBundle.getCannotRefactorMessage(null), null); + return; + } IdeEventQueue.getInstance().setEventCount(eventCount); if (editor != null) { final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); @@ -91,7 +97,18 @@ public abstract class BaseRefactoringAction extends AnAction { } } - if (editor != null) { + if (editor == null) { + if (isAvailableInEditorOnly()) { + disableAction(e); + return; + } + final PsiElement[] elements = getPsiElementArray(dataContext); + final boolean isEnabled = isEnabledOnDataContext(dataContext) || elements.length != 0 && isEnabledOnElements(elements); + if (!isEnabled) { + disableAction(e); + } + } + else { PsiElement element = e.getData(LangDataKeys.PSI_ELEMENT); if (element == null || !isAvailableForLanguage(element.getLanguage())) { if (file == null) { @@ -108,17 +125,6 @@ public abstract class BaseRefactoringAction extends AnAction { disableAction(e); } } - else { - if (isAvailableInEditorOnly()) { - disableAction(e); - return; - } - final PsiElement[] elements = getPsiElementArray(dataContext); - final boolean isEnabled = isEnabledOnDataContext(dataContext) || elements.length != 0 && isEnabledOnElements(elements); - if (!isEnabled) { - disableAction(e); - } - } } public static PsiElement getElementAtCaret(final Editor editor, final PsiFile file) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java b/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java index 6782cd66f1..2bc7b26147 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java @@ -89,7 +89,7 @@ public class PsiElementRenameHandler implements RenameHandler { boolean hasWritableMetaData = element instanceof PsiMetaOwner && ((PsiMetaOwner)element).getMetaData() instanceof PsiWritableMetaData; if (!hasRenameProcessor && !hasWritableMetaData && !(element instanceof PsiNamedElement)) { - String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.symbol")); + String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.symbol.to.rename")); if (!ApplicationManager.getApplication().isUnitTestMode()) { showErrorMessage(project, editor, message); } diff --git a/platform/platform-resources-en/src/messages/RefactoringBundle.properties b/platform/platform-resources-en/src/messages/RefactoringBundle.properties index fde181ddd9..64a102a2a8 100644 --- a/platform/platform-resources-en/src/messages/RefactoringBundle.properties +++ b/platform/platform-resources-en/src/messages/RefactoringBundle.properties @@ -21,7 +21,8 @@ error.wrong.caret.position.class=The caret should be positioned inside the class error.wrong.caret.position.method.or.local.name=The caret should be positioned at the name of the element to be refactored. error.wrong.caret.position.local.name=The caret should be positioned at the name of the local variable to be refactored. error.wrong.caret.position.local.or.expression.name=The caret should be positioned at the name of the local variable or expession to be refactored. -error.wrong.caret.position.symbol=The caret should be positioned at the symbol to be renamed. +error.wrong.caret.position.symbol.to.rename=The caret should be positioned at the symbol to be renamed. +error.wrong.caret.position.symbol.to.refactor=The caret should be positioned at the symbol to be refactored. error.out.of.project.element=Selected {0} is not located inside the project. error.in.injected.lang.prefix.suffix=Selected {0} is located in the readonly part of the injected language document. to.refactor=to refactor -- 2.11.4.GIT