@NotNull @Override public RelativePoint guessBestPopupLocation(@NotNull DataContext dataContext) { Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); JComponent focusOwner = component instanceof JComponent ? (JComponent) component : null; if (focusOwner == null) { Project project = PlatformDataKeys.PROJECT.getData(dataContext); IdeFrameImpl frame = project == null ? null : ((WindowManagerEx) WindowManager.getInstance()).getFrame(project); focusOwner = frame == null ? null : frame.getRootPane(); if (focusOwner == null) { throw new IllegalArgumentException("focusOwner cannot be null"); } } final Point point = PlatformDataKeys.CONTEXT_MENU_POINT.getData(dataContext); if (point != null) { return new RelativePoint(focusOwner, point); } Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); if (editor != null && focusOwner == editor.getContentComponent()) { return guessBestPopupLocation(editor); } else { return guessBestPopupLocation(focusOwner); } }
public void playBack(DataContext context) { Editor editor = PlatformDataKeys.EDITOR.getData(context); final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction(); char chars[] = myText.toCharArray(); for (int i = 0; i < chars.length; i++) { typedAction.actionPerformed(editor, chars[i], context); } }
public void update(AnActionEvent e) { DataContext dataContext = e.getDataContext(); Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); boolean enabled = (editor != null && FileDocumentManager.getInstance().getFile(editor.getDocument()) != null) || getElementToCopy(editor, dataContext) != null; e.getPresentation().setEnabled(enabled); if (ActionPlaces.isPopupPlace(e.getPlace())) { e.getPresentation().setVisible(enabled); } else { e.getPresentation().setVisible(true); } }
public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); Project project = PlatformDataKeys.PROJECT.getData(dataContext); presentation.setEnabled(false); if (project == null) { return; } Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); if (editor != null) { updateForEditor(dataContext, presentation); } else { String id = ToolWindowManager.getInstance(project).getActiveToolWindowId(); updateForToolWindow(id, dataContext, presentation); } }
@Override public void actionPerformed(AnActionEvent e) { DataContext context = e.getDataContext(); Editor editor = PlatformDataKeys.EDITOR.getData(context); PsiFile psiFile = LangDataKeys.PSI_FILE.getData(context); if (psiFile == null) return; List<GotoRelatedItem> items = getItems(psiFile, editor, context); if (items.isEmpty()) return; if (items.size() == 1 && items.get(0).getElement() != null) { items.get(0).navigate(); return; } if (ApplicationManager.getApplication().isUnitTestMode()) { System.out.println(items); } createPopup(items, "Go to Related Files").showInBestPositionFor(context); }
public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); Project project = PlatformDataKeys.PROJECT.getData(dataContext); PsiElement element = getElementToCopy(editor, dataContext); if (!doCopy(element, project, editor) && editor != null) { Document document = editor.getDocument(); PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document); if (file != null) { String toCopy = getFileFqn(file) + ":" + (editor.getCaretModel().getLogicalPosition().line + 1); CopyPasteManager.getInstance().setContents(new StringSelection(toCopy)); setStatusBarText(project, toCopy + " has been copied"); } return; } HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager manager = EditorColorsManager.getInstance(); TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); if (element != null && editor != null) { PsiElement nameIdentifier = HighlightUsagesHandler.getNameIdentifier(element); if (nameIdentifier != null) { highlightManager.addOccurrenceHighlights( editor, new PsiElement[] {nameIdentifier}, attributes, true, null); } else { PsiReference reference = TargetElementUtilBase.findReference(editor, editor.getCaretModel().getOffset()); if (reference != null) { highlightManager.addOccurrenceHighlights( editor, new PsiReference[] {reference}, attributes, true, null); } else { highlightManager.addOccurrenceHighlights( editor, new PsiElement[] {element}, attributes, true, null); } } } }
protected void updateForEditor(DataContext dataContext, Presentation presentation) { Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); if (editor == null) { presentation.setVisible(false); return; } Project project = PlatformDataKeys.PROJECT.getData(dataContext); if (project == null) { return; } PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); PsiElement element = getTargetElement(editor, project); boolean result = element != null && CopyHandler.canCopy(new PsiElement[] {element}); if (!result && file != null) { result = CopyHandler.canCopy(new PsiElement[] {file}); } presentation.setEnabled(result); presentation.setVisible(true); }
public void actionPerformed(AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Project project = PlatformDataKeys.PROJECT.getData(dataContext); if (project == null) { return; } CommandProcessor.getInstance() .executeCommand( project, new Runnable() { public void run() { PsiDocumentManager.getInstance(project).commitAllDocuments(); } }, "", null); final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); PsiElement[] elements; PsiDirectory defaultTargetDirectory; if (editor != null) { PsiElement aElement = getTargetElement(editor, project); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) return; elements = new PsiElement[] {aElement}; if (aElement == null || !CopyHandler.canCopy(elements)) { elements = new PsiElement[] {file}; } defaultTargetDirectory = file.getContainingDirectory(); } else { PsiElement element = LangDataKeys.TARGET_PSI_ELEMENT.getData(dataContext); defaultTargetDirectory = element instanceof PsiDirectory ? (PsiDirectory) element : null; elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext); } doCopy(elements, defaultTargetDirectory); }
private static Editor getEditor(final AnActionEvent e) { return PlatformDataKeys.EDITOR.getData(e.getDataContext()); }