mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
show hint when refactoring cannot be invoked
This commit is contained in:
+3
-3
@@ -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);
|
||||
|
||||
+19
-13
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user