public void update(final AnActionEvent event) { super.update(event); final Presentation presentation = event.getPresentation(); final DataContext context = event.getDataContext(); Module module = (Module) context.getData(LangDataKeys.MODULE.getName()); PsiFile currentFile = (PsiFile) context.getData(LangDataKeys.PSI_FILE.getName()); Editor editor = (Editor) context.getData(PlatformDataKeys.EDITOR.getName()); // VirtualFile currentFile = (VirtualFile) // context.getData(PlatformDataKeys.VIRTUAL_FILE.getName()); if (currentFile != null && editor != null) { boolean isSSFile = currentFile .getFileType() .getDefaultExtension() .equals(SilverStripeFileType.DEFAULT_EXTENSION); SelectionModel selectionModel = editor.getSelectionModel(); String selectedText = selectionModel.getSelectedText(); this.selectedText = selectedText; this.selectonModel = selectionModel; this.editor = editor; this.currentFile = currentFile; if (selectedText == null) { presentation.setEnabled(false); } if (!isSSFile) { presentation.setEnabled(false); presentation.setVisible(false); } } else { presentation.setEnabled(false); presentation.setVisible(false); } }
@Override public void execute(Editor editor, DataContext dataContext) { Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return; } PsiFile psiFile = LangDataKeys.PSI_FILE.getData(dataContext); if (psiFile == null) { return; } process(psiFile, editor, project, editor.getCaretModel().getOffset()); }