@Override public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) { if (!myHandler.isEnabled(project)) { return false; } Editor editor = event.getData(CommonDataKeys.EDITOR); if (editor == null) { return false; } if (EditorGutter.KEY.getData(event.getDataContext()) != null) { return false; } return true; }
@Override public boolean isEnabled(@Nonnull final Project project, final AnActionEvent event) { if (!myHandler.isEnabled(project)) { return false; } Editor editor = event.getData(CommonDataKeys.EDITOR); if (editor == null) { return false; } if (event.getData(EditorGutter.KEY) != null) { return false; } return true; }
public DevMotiveAnnotationGutter(Project project, FileAnnotation annotation, List<VcsFileRevision> revisions, EditorGutter editorGutter) { this.annotation = annotation; devMotivePanel = AliContentFactory.addDevMotiveContent(project, annotation.getFile(), revisions, annotation.getVcsKey().getName(), this, true); devMotivePanel.addChangeListener(this); if (editorGutter instanceof EditorGutterComponentEx) { editorGutterComponentEx = (EditorGutterComponentEx) editorGutter; unknownLine = "???"; } else { // unable to resize, make sure to reserve enough room unknownLine = "??????????"; } }
@Override public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { presentation.setEnabled(false); return; } Editor editor = CommonDataKeys.EDITOR.getData(dataContext); PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext); if (editor == null && element == null) { presentation.setEnabled(false); return; } if (LookupManager.getInstance(project).getActiveLookup() != null) { if (!isValidForLookup()) { presentation.setEnabled(false); } else { presentation.setEnabled(true); } } else { if (editor != null) { if (EditorGutter.KEY.getData(event.getDataContext()) != null) { presentation.setEnabled(false); return; } PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) { presentation.setEnabled(false); } if (element == null && file != null) { try { final PsiReference ref = file.findReferenceAt(editor.getCaretModel().getOffset()); if (ref instanceof PsiPolyVariantReference) { element = ref.getElement(); } } catch (IndexNotReadyException e) { element = null; } } } if (element != null) { presentation.setEnabled(true); } } }
@RequiredDispatchThread @Override public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { presentation.setEnabled(false); return; } Editor editor = event.getData(CommonDataKeys.EDITOR); PsiElement element = event.getData(CommonDataKeys.PSI_ELEMENT); if (editor == null && element == null) { presentation.setEnabled(false); return; } if (LookupManager.getInstance(project).getActiveLookup() != null) { if (!isValidForLookup()) { presentation.setEnabled(false); } else { presentation.setEnabled(true); } } else { if (editor != null) { if (event.getData(EditorGutter.KEY) != null) { presentation.setEnabled(false); return; } PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) { presentation.setEnabled(false); } if (element == null && file != null) { try { final PsiReference ref = file.findReferenceAt(editor.getCaretModel().getOffset()); if (ref instanceof PsiPolyVariantReference) { element = ref.getElement(); } } catch (IndexNotReadyException e) { element = null; } } } if (element != null) { presentation.setEnabled(true); } } }