use of com.intellij.lang.ContextAwareActionHandler in project intellij-community by JetBrains.
the class BaseRefactoringAction method hasAvailableHandler.
protected boolean hasAvailableHandler(@NotNull DataContext dataContext) {
final RefactoringActionHandler handler = getHandler(dataContext);
if (handler != null) {
if (handler instanceof ContextAwareActionHandler) {
final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
if (editor != null && file != null && !((ContextAwareActionHandler) handler).isAvailableForQuickList(editor, file, dataContext)) {
return false;
}
}
return true;
}
return false;
}
use of com.intellij.lang.ContextAwareActionHandler in project intellij-community by JetBrains.
the class PresentableActionHandlerBasedAction method update.
@Override
protected void update(@NotNull Presentation presentation, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext, @Nullable String actionPlace) {
// avoid evaluating isValidFor several times unnecessary
CodeInsightActionHandler handler = getValidHandler(editor, file);
presentation.setEnabled(handler != null);
if (handler instanceof ContextAwareActionHandler && !ActionPlaces.isMainMenuOrActionSearch(actionPlace)) {
presentation.setVisible(((ContextAwareActionHandler) handler).isAvailableForQuickList(editor, file, dataContext));
}
if (presentation.isVisible() && handler instanceof PresentableCodeInsightActionHandler) {
((PresentableCodeInsightActionHandler) handler).update(editor, file, presentation);
}
}
use of com.intellij.lang.ContextAwareActionHandler in project intellij-community by JetBrains.
the class ChangeSignatureAction method getRefactoringHandler.
@Nullable
@Override
protected RefactoringActionHandler getRefactoringHandler(@NotNull RefactoringSupportProvider provider, final PsiElement element) {
abstract class ContextAwareChangeSignatureHandler implements RefactoringActionHandler, ContextAwareActionHandler {
}
return new ContextAwareChangeSignatureHandler() {
@Override
public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
return findTargetMember(element) != null;
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final PsiElement targetMember = findTargetMember(element);
if (targetMember == null) {
final ChangeSignatureHandler handler = getChangeSignatureHandler(file.getLanguage());
if (handler != null) {
final String notFoundMessage = handler.getTargetNotFoundMessage();
if (notFoundMessage != null) {
CommonRefactoringUtil.showErrorHint(project, editor, notFoundMessage, ChangeSignatureHandler.REFACTORING_NAME, null);
}
}
return;
}
final ChangeSignatureHandler handler = getChangeSignatureHandler(targetMember.getLanguage());
if (handler == null)
return;
handler.invoke(project, new PsiElement[] { targetMember }, dataContext);
}
@Override
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
if (elements.length != 1)
return;
final PsiElement targetMember = findTargetMember(elements[0]);
if (targetMember == null)
return;
final ChangeSignatureHandler handler = getChangeSignatureHandler(targetMember.getLanguage());
if (handler == null)
return;
handler.invoke(project, new PsiElement[] { targetMember }, dataContext);
}
};
}
Aggregations