@Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); Project project = e.getProject(); if (project == null) { presentation.setEnabled(false); return; } final DataContext dataContext = e.getDataContext(); Editor editor = getEditor(dataContext, project, true); if (editor == null) { presentation.setEnabled(false); return; } final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); if (file == null) { presentation.setEnabled(false); return; } update(presentation, project, editor, file, dataContext, e.getPlace()); }
@Override public void actionPerformed(AnActionEvent event) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); Project project = CommonDataKeys.PROJECT.getData(dataContext); Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (project == null || editor == null) { presentation.setEnabled(false); return; } PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null || file.getVirtualFile() == null) { presentation.setEnabled(false); return; } boolean hasSelection = editor.getSelectionModel().hasSelection(); LayoutCodeDialog dialog = new LayoutCodeDialog(project, file, hasSelection, HELP_ID); dialog.show(); if (dialog.isOK()) { new FileInEditorProcessor(file, editor, dialog.getRunOptions()).processCode(); } }
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 final void update(final AnActionEvent event) { final Presentation presentation = event.getPresentation(); final DataContext dataContext = event.getDataContext(); final HierarchyBrowserBaseEx browser = (HierarchyBrowserBaseEx) dataContext.getData(myBrowserDataKey); if (browser == null) { presentation.setVisible(false); presentation.setEnabled(false); return; } presentation.setVisible(true); final PsiElement selectedElement = browser.getSelectedElement(); if (selectedElement == null || !browser.isApplicableElement(selectedElement)) { presentation.setEnabled(false); presentation.setVisible(false); return; } presentation.setEnabled(isEnabled(browser, selectedElement)); String nonDefaultText = getNonDefaultText(browser, selectedElement); if (nonDefaultText != null) { presentation.setText(nonDefaultText); } }
@Override public void update(@NotNull final AnActionEvent e) { super.update(e); final Presentation presentation = e.getPresentation(); DebugProcessImpl process = getCurrentDebugProcess(e.getProject()); if (process == null || process.canGetMethodReturnValue()) { presentation.setEnabled(true); presentation.setText(myText); } else { presentation.setEnabled(false); presentation.setText(myTextUnavailable); } }
@Override public void update(AnActionEvent event) { super.update(event); Presentation presentation = event.getPresentation(); FileTemplate[] allTemplates = FileTemplateManager.getInstance().getAllTemplates(); for (FileTemplate template : allTemplates) { if (canCreateFromTemplate(event, template)) { presentation.setEnabled(true); return; } } presentation.setEnabled(false); }
public void update(final AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setEnabled(false); final PackageDependenciesNode leftNode = myLeftTree.getSelectedNode(); final PackageDependenciesNode rightNode = myRightTree.getSelectedNode(); if (leftNode != null && rightNode != null) { final PatternDialectProvider provider = PatternDialectProvider.getInstance(mySettings.SCOPE_TYPE); presentation.setEnabled( (provider.createPackageSet(leftNode, true) != null || provider.createPackageSet(leftNode, false) != null) && (provider.createPackageSet(rightNode, true) != null || provider.createPackageSet(rightNode, false) != null)); } }
protected void update( @NotNull Presentation presentation, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { presentation.setEnabled(isValidForFile(project, editor, file)); }
public static void updateFindUsagesAction(AnActionEvent event) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); boolean enabled = isEnabled(dataContext); presentation.setVisible(enabled || !ActionPlaces.isPopupPlace(event.getPlace())); presentation.setEnabled(enabled); }
// Async update @Override public final void update(AnActionEvent e) { final T data = prepareDataFromContext(e); final Presentation originalPresentation = e.getPresentation(); if (!forceSyncUpdate(e) && isDumbAware()) { final Presentation realPresentation = (Presentation) originalPresentation.clone(); ourUpdaterService.submit( new Runnable() { @Override public void run() { performUpdate(realPresentation, data); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (originalPresentation.isVisible() != realPresentation.isVisible()) { LOG.error( "Async update is not supported for actions that change their visibility." + "Either stop extending AsyncUpdateAction or override forceSyncUpdate() to return true." + "Action class is: " + AsyncUpdateAction.this.getClass().getName()); } originalPresentation.copyFrom(realPresentation); } }); } }); originalPresentation.setVisible(true); originalPresentation.setEnabled(false); } else { performUpdate(originalPresentation, data); } }
@Override public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setEnabled(false); if (getSelectedProfile() == null) return; final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) return; final InspectionConfigTreeNode[] selectedNodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); if (selectedNodes == null) return; final List<Descriptor> descriptors = new ArrayList<Descriptor>(); for (InspectionConfigTreeNode node : selectedNodes) { collect(descriptors, new ArrayList<InspectionConfigTreeNode>(), node); } presentation.setEnabled(!getAvailableScopes(project, descriptors).isEmpty()); }
@Override public void update(AnActionEvent event) { final Presentation presentation = event.getPresentation(); final Project project = event.getData(CommonDataKeys.PROJECT); presentation.setEnabled(project != null); presentation.setVisible( ActionPlaces.isMainMenuOrActionSearch(event.getPlace()) && !PlatformUtils.isCidr()); }
@Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); if (ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace()) || ActionPlaces.COMMANDER_POPUP.equals(e.getPlace())) { presentation.setText(IdeBundle.message("action.delete.ellipsis")); } else { presentation.setText(IdeBundle.message("action.delete")); } if (e.getProject() == null) { presentation.setEnabled(false); return; } DataContext dataContext = e.getDataContext(); DeleteProvider provider = getDeleteProvider(dataContext); if (e.getInputEvent() instanceof KeyEvent) { KeyEvent keyEvent = (KeyEvent) e.getInputEvent(); Object component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); if (component instanceof JTextComponent) provider = null; // Do not override text deletion if (keyEvent.getKeyCode() == KeyEvent.VK_BACK_SPACE) { // Do not override text deletion in speed search if (component instanceof JComponent) { SpeedSearchSupply searchSupply = SpeedSearchSupply.getSupply((JComponent) component); if (searchSupply != null) provider = null; } String activeSpeedSearchFilter = SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY.getData(dataContext); if (!StringUtil.isEmpty(activeSpeedSearchFilter)) { provider = null; } } } if (provider instanceof TitledHandler) { presentation.setText(((TitledHandler) provider).getActionTitle()); } boolean canDelete = provider != null && provider.canDeleteElement(dataContext); if (ActionPlaces.isPopupPlace(e.getPlace())) { presentation.setVisible(canDelete); } else { presentation.setEnabled(canDelete); } }
@Override public final void update(final AnActionEvent e) { final Presentation presentation = e.getPresentation(); final Project project = e.getProject(); if (project == null) return; presentation.setEnabled(isEnabled()); presentation.setText(getCurrentScopeType()); }
@Override public void update(AnActionEvent e) { final DataContext dc = e.getDataContext(); final Presentation presentation = e.getPresentation(); // presentation.setVisible(isVisible(dc)); presentation.setEnabled(isVisible(dc) && isEnabled(dc)); }
public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setEnabled(false); final TreePath[] selectionPath = myTree.getSelectionPaths(); if (selectionPath != null) { Object[] nodes = ContainerUtil.map2Array( selectionPath, new Function<TreePath, Object>() { @Override public Object fun(TreePath treePath) { return treePath.getLastPathComponent(); } }); if (!myCondition.value(nodes)) return; presentation.setEnabled(true); } }
public void update(final AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Presentation presentation = e.getPresentation(); final boolean enabled = isAvailable(dataContext); presentation.setVisible(enabled); presentation.setEnabled(enabled); }
public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setEnabled(false); if (myElement != null) { final PsiElement element = myElement.getElement(); final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element); final PsiElement originalElement = DocumentationManager.getOriginalElement(element); if (provider instanceof ExternalDocumentationProvider) { presentation.setEnabled( element != null && ((ExternalDocumentationProvider) provider) .hasDocumentationFor(element, originalElement)); } else { final List<String> urls = provider.getUrlFor(element, originalElement); presentation.setEnabled(element != null && urls != null && !urls.isEmpty()); } } }
@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); if (editor == null) { presentation.setEnabled(false); return; } boolean groupEmpty = ActionGroupUtil.isGroupEmpty(getGroup(), event); presentation.setEnabled(!groupEmpty); }
@Override public void update(final AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Project project = PlatformDataKeys.PROJECT.getData(dataContext); final Change[] changes = e.getData(getChangesKey()); final Presentation presentation = e.getPresentation(); presentation.setVisible(VcsDataKeys.CHANGES.getData(dataContext) != null); presentation.setEnabled(enabled(project, changes)); }
@Override public void update(AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Presentation presentation = e.getPresentation(); final boolean enabled = LangDataKeys.PSI_FILE.getData(dataContext) instanceof DartFile; presentation.setVisible(enabled); presentation.setEnabled(enabled); }
@Override public void update(final AnActionEvent event) { final Presentation presentation = event.getPresentation(); String name = myEnvironment.getRunProfile().getName(); ProcessHandler processHandler = myDescriptor.getProcessHandler(); final boolean isRunning = processHandler != null && !processHandler.isProcessTerminated(); presentation.setText(ExecutionBundle.message("rerun.configuration.action.name", name)); presentation.setIcon(isRunning ? AllIcons.Actions.Restart : myExecutor.getIcon()); presentation.setEnabled(isEnabled()); }
@Override public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); Project project = CommonDataKeys.PROJECT.getData(dataContext); Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (project == null || editor == null) { presentation.setEnabled(false); return; } PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null || file.getVirtualFile() == null) { presentation.setEnabled(false); return; } if (LanguageFormatting.INSTANCE.forContext(file) != null) { presentation.setEnabled(true); } }
@Override public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); final Project project = e.getData(CommonDataKeys.PROJECT); presentation.setEnabled(true); if (project == null || project.isDisposed()) { presentation.setEnabled(false); presentation.setVisible(false); return; } if (null == getDefaultExecutor()) { presentation.setEnabled(false); presentation.setVisible(false); return; } presentation.setEnabled(true); presentation.setVisible(true); }
@Override public void update(final AnActionEvent e) { if (!e.getPresentation().isVisible()) { return; } final DataContext dataContext = e.getDataContext(); final Presentation presentation = e.getPresentation(); final boolean enabled = isAvailable(dataContext); presentation.setVisible(enabled); presentation.setEnabled(enabled); }
@Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); Project project = e.getData(CommonDataKeys.PROJECT); if (ActionPlaces.isMainMenuOrActionSearch(e.getPlace())) { presentation.setDescription( ExecutionBundle.message("choose.run.configuration.action.description")); } try { if (project == null || project.isDisposed() || !project.isInitialized()) { updatePresentation(null, null, null, presentation); presentation.setEnabled(false); } else { updatePresentation( ExecutionTargetManager.getActiveTarget(project), RunManagerEx.getInstanceEx(project).getSelectedConfiguration(), project, presentation); presentation.setEnabled(true); } } catch (IndexNotReadyException e1) { presentation.setEnabled(false); } }
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 update(final AnActionEvent e) { final Presentation presentation = e.getPresentation(); final Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) { disable(presentation); return; } RunnerAndConfigurationSettings settings = chooseTempSettings(project); if (settings == null) { disable(presentation); } else { presentation.setText( ExecutionBundle.message( "save.temporary.run.configuration.action.name", settings.getName())); presentation.setDescription(presentation.getText()); presentation.setVisible(true); presentation.setEnabled(true); } }
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); }
@Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); presentation.setEnabled(!myForwardStack.isEmpty()); }