@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()); }
public void actionPerformed(final AnActionEvent e) { final PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE); final Project project = e.getData(CommonDataKeys.PROJECT); final Editor editor = e.getData(LangDataKeys.EDITOR); if (psiFile != null && project != null && editor != null) { ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { CommandProcessor.getInstance() .executeCommand( project, new Runnable() { public void run() { try { intention.invoke(project, editor, psiFile); } catch (IncorrectOperationException ex) { LOGGER.error(ex); } } }, e.getPresentation().getText(), e.getActionManager().getId(SpellCheckerIntentionAction.this)); } }); } }
@Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { SNode node = event.getData(MPSCommonDataKeys.NODE); if (node == null) { return false; } } { EditorContext p = event.getData(MPSEditorDataKeys.EDITOR_CONTEXT); if (p == null) { return false; } } { MPSProject p = event.getData(MPSCommonDataKeys.MPS_PROJECT); if (p == null) { return false; } } return true; }
@Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { SNode node = event.getData(MPSCommonDataKeys.NODE); if (node != null && !(SNodeOperations.isInstanceOf( node, MetaAdapterFactory.getConcept( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca68L, "jetbrains.mps.baseLanguage.structure.FieldDeclaration")))) { node = null; } MapSequence.fromMap(_params).put("target", node); if (node == null) { return false; } } { MPSProject p = event.getData(MPSCommonDataKeys.MPS_PROJECT); MapSequence.fromMap(_params).put("project", p); if (p == null) { return false; } } return true; }
public void actionPerformed(final AnActionEvent e) { final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) return; final PsiFile file = LangDataKeys.PSI_FILE.getData(e.getDataContext()); FileAssociationsConfigurable.editAssociations(project, file); }
@Override public void update(AnActionEvent e) { Tool tool = findTool(myActionId, e.getDataContext()); if (tool != null) { e.getPresentation().setText(ToolRunProfile.expandMacrosInName(tool, e.getDataContext())); } }
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 protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { Project p = event.getData(CommonDataKeys.PROJECT); if (p == null) { return false; } } { FileEditor p = event.getData(PlatformDataKeys.FILE_EDITOR); if (p == null) { return false; } } { VirtualFile p = event.getData(CommonDataKeys.VIRTUAL_FILE); if (p == null) { return false; } } return true; }
public void actionPerformed(final AnActionEvent e) { DebuggerTreeNodeImpl[] selectedNode = getSelectedNodes(e.getDataContext()); final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); if (debugProcess == null) return; //noinspection ConstantConditions for (final DebuggerTreeNodeImpl debuggerTreeNode : selectedNode) { final ThreadDescriptorImpl threadDescriptor = ((ThreadDescriptorImpl) debuggerTreeNode.getDescriptor()); if (threadDescriptor.isSuspended()) { final ThreadReferenceProxyImpl thread = threadDescriptor.getThreadReference(); debugProcess .getManagerThread() .schedule( new DebuggerCommandImpl() { @Override protected void action() throws Exception { Set<SuspendContextImpl> contexts = SuspendManagerUtil.getSuspendingContexts( debugProcess.getSuspendManager(), thread); if (!contexts.isEmpty()) { debugProcess .createResumeThreadCommand(contexts.iterator().next(), thread) .run(); } debuggerTreeNode.calcValue(); } }); } } }
@Override public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setVisible(false); final DataContext dataContext = e.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project != null) { final RunConfiguration configuration = RunConfiguration.DATA_KEY.getData(dataContext); if (isPatternBasedConfiguration(configuration)) { final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(dataContext); if (testProxy != null) { final Location location = testProxy.getLocation( project, ((T) configuration).getConfigurationModule().getSearchScope()); if (location != null) { final PsiElement psiElement = location.getPsiElement(); if (psiElement instanceof PsiClass && getPattern((T) configuration) .contains(((PsiClass) psiElement).getQualifiedName())) { presentation.setVisible(true); } } } } } }
public void actionPerformed(@NotNull AnActionEvent event) { if (logger.isDebugEnabled()) { logger.debug("actionPerformed=" + event); } if (!VimPlugin.isEnabled()) { return; } if (event.getInputEvent() instanceof KeyEvent) { KeyEvent ke = (KeyEvent) event.getInputEvent(); Editor editor = event.getData(PlatformDataKeys.EDITOR); if (editor != null) { KeyStroke key = KeyStroke.getKeyStrokeForEvent(ke); KeyHandler.getInstance().handleKey(editor, key, event.getDataContext()); } else { if (ExEntryPanel.getInstance().isActive()) { KeyEvent e = new KeyEvent( ke.getComponent(), ke.getID(), ke.getWhen(), ke.getModifiers(), ke.getKeyCode(), ke.getKeyChar(), ke.getKeyLocation()); ExEntryPanel.getInstance().processKey(e); } } } }
protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { List<SNode> nodes = event.getData(MPSCommonDataKeys.NODES); boolean error = false; if (nodes != null) { for (SNode node : ListSequence.fromList(nodes)) { if (!(SNodeOperations.isInstanceOf( node, "jetbrains.mps.lang.core.structure.BaseConcept"))) { error = true; break; } } } if (error || nodes == null) { MapSequence.fromMap(_params).put("nodes", null); } else { MapSequence.fromMap(_params) .put("nodes", ListSequence.fromListWithValues(new ArrayList<SNode>(), nodes)); } } if (MapSequence.fromMap(_params).get("nodes") == null) { return false; } MapSequence.fromMap(_params).put("project", event.getData(MPSCommonDataKeys.MPS_PROJECT)); if (MapSequence.fromMap(_params).get("project") == null) { return false; } return true; }
@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 final void actionPerformed(final AnActionEvent event) { final DataContext dataContext = event.getDataContext(); final HierarchyBrowserBaseEx browser = (HierarchyBrowserBaseEx) dataContext.getData(myBrowserDataKey); if (browser == null) return; final PsiElement selectedElement = browser.getSelectedElement(); if (selectedElement == null || !browser.isApplicableElement(selectedElement)) return; final String currentViewType = browser.myCurrentViewType; Disposer.dispose(browser); final HierarchyProvider provider = BrowseHierarchyActionBase.findProvider( myProviderLanguageExtension, selectedElement, selectedElement.getContainingFile(), event.getDataContext()); final HierarchyBrowser newBrowser = BrowseHierarchyActionBase.createAndAddToPanel( selectedElement.getProject(), provider, selectedElement); ApplicationManager.getApplication() .invokeLater( () -> ((HierarchyBrowserBaseEx) newBrowser) .changeView(correctViewType(browser, currentViewType))); }
@Override public void update(@NotNull AnActionEvent event) { final Presentation presentation = event.getPresentation(); final Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { presentation.setVisible(false); presentation.setEnabled(false); return; } final IdeView view = event.getData(LangDataKeys.IDE_VIEW); if (view == null) { presentation.setVisible(false); presentation.setEnabled(false); return; } final PsiDirectory[] directories = view.getDirectories(); if (directories.length == 0) { presentation.setVisible(false); presentation.setEnabled(false); return; } final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view); final CCProjectService service = CCProjectService.getInstance(project); final Course course = service.getCourse(); if (course != null && directory != null && course.getLesson(directory.getName()) == null) { presentation.setVisible(false); presentation.setEnabled(false); return; } presentation.setVisible(true); presentation.setEnabled(true); }
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getData(PlatformDataKeys.PROJECT); Editor editor = e.getData(PlatformDataKeys.EDITOR); if (editor == null) { return; } if (!editor.getDocument().isWritable()) { return; } Document document = editor.getDocument(); SelectionModel selection = editor.getSelectionModel(); String selectedText = selection.getSelectedText(); String autoAlignedText; int startOffset; int endOffset; if (selectedText != null) { // just align the selected text autoAlignedText = aligner.align(selectedText); startOffset = selection.getSelectionStart(); endOffset = selection.getSelectionEnd(); } else { // auto-align the whole document autoAlignedText = aligner.align(document.getText()); startOffset = 0; endOffset = document.getTextLength(); } replaceString(project, document, autoAlignedText, startOffset, endOffset); }
@Override public void update(AnActionEvent e) { final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); final boolean isPng = isPngFile(file); e.getPresentation().setEnabled(isPng); e.getPresentation().setVisible(isPng); }
@Override public void update(@NotNull AnActionEvent e) { Presentation presentation = e.getPresentation(); OpenInBrowserRequest result = BaseOpenInBrowserAction.doUpdate(e); if (result == null) { return; } String description = getTemplatePresentation().getDescription(); if (HtmlUtil.isHtmlFile(result.getFile())) { description += " (hold Shift to open URL of local file)"; } presentation.setText(getTemplatePresentation().getText()); presentation.setDescription(description); WebBrowser browser = findUsingBrowser(); if (browser != null) { presentation.setIcon(browser.getIcon()); } if (ActionPlaces.isPopupPlace(e.getPlace())) { presentation.setVisible(presentation.isEnabled()); } }
@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(); } }
@Override public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) { IBreakpoint breakpoint = BreakpointsUtil.MPS_BREAKPOINT.getData(event.getDataContext()); event .getPresentation() .setEnabled(breakpoint != null && breakpoint instanceof ILocationBreakpoint); }
public void update(AnActionEvent e) { super.update(e); final Project project = e.getData(DataKeys.PROJECT); final VirtualFile file = e.getData(DataKeys.VIRTUAL_FILE); boolean visible = project != null && file != null && !file.isDirectory() && file.getFileType() == CppSupportLoader.CPP_FILETYPE && !Communicator.isHeaderFile(file); boolean enabled = visible; if (!visible) { visible = ActionPlaces.MAIN_MENU.equals(e.getPlace()); } e.getPresentation().setEnabled(enabled); e.getPresentation().setVisible(visible); if (visible) { final String s = "Do c&ompile for " + (file != null ? file.getName() : "selected c/c++ fileToCompile"); e.getPresentation().setText(s); e.getPresentation().setDescription(s); } }
public boolean isEnabled(AnActionEvent e) { PsiElement psiElement = e.getData(LangDataKeys.PSI_ELEMENT); if (psiElement == null || !(psiElement instanceof PsiDirectory)) { // Can be used only on package return false; } VirtualFile targetDir = ((PsiDirectory) psiElement).getVirtualFile(); boolean isUnderSourceRoot = false; if (psiElement instanceof MPSPsiModel) { isUnderSourceRoot = true; } else { Module m = e.getData(LangDataKeys.MODULE); VirtualFile[] sourceRoots = ModuleRootManager.getInstance(m).getSourceRoots(true); for (VirtualFile root : sourceRoots) { if (targetDir.getPath().equals(root.getPath())) { // Can't be source or test folder return false; } isUnderSourceRoot = isUnderSourceRoot || FileUtil.isSubPath(root.getPath(), targetDir.getPath()); } } return isUnderSourceRoot && myOperationContext != null && (myModelDescriptor != null || myNewModel) && myProject != null; }
@Override protected void actionPerformed( @NotNull AnActionEvent e, @NotNull Project project, @NotNull ChangeRequestChain chain, @NotNull DiffViewer diffViewer) { List<DiffRequestPresentable> requests = chain.getAllRequests(); List<Change> changes = getChangesFromRequests(requests); ChangesBrowser cb = new MyChangesBrowser(project, changes, requests, chain, diffViewer); myPopup = JBPopupFactory.getInstance() .createComponentPopupBuilder(cb, cb.getPreferredFocusedComponent()) .setResizable(true) .setModalContext(false) .setFocusable(true) .setRequestFocus(true) .setCancelOnWindowDeactivation(true) .setCancelOnOtherWindowOpen(true) .setMovable(true) .setCancelKeyEnabled(true) .setCancelOnClickOutside(true) .createPopup(); InputEvent event = e.getInputEvent(); if (event instanceof MouseEvent) { myPopup.show(new RelativePoint((MouseEvent) event)); } else { myPopup.showInBestPositionFor(e.getDataContext()); } }
public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); final DataContext dataContext = e.getDataContext(); Project project = PlatformDataKeys.PROJECT.getData(dataContext); if ((project == null) || (ProjectLevelVcsManager.getInstance(project).isBackgroundVcsOperationRunning())) { presentation.setEnabled(false); presentation.setVisible(false); return; } VirtualFile[] files = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); if (files == null || files.length == 0) { presentation.setEnabled(false); presentation.setVisible(false); return; } boolean enabled = false; boolean visible = false; if (files.length == 1 && files[0].isDirectory()) { visible = true; if (!SvnStatusUtil.isUnderControl(project, files[0])) { enabled = true; } } presentation.setEnabled(enabled); presentation.setVisible(visible); }
protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } MapSequence.fromMap(_params).put("context", event.getData(MPSCommonDataKeys.OPERATION_CONTEXT)); if (MapSequence.fromMap(_params).get("context") == null) { return false; } MapSequence.fromMap(_params).put("langModule", event.getData(MPSCommonDataKeys.MODULE)); if (MapSequence.fromMap(_params).get("langModule") == null) { return false; } { SNode node = event.getData(MPSCommonDataKeys.NODE); if (node != null) { if (!(SNodeOperations.isInstanceOf( node, "jetbrains.mps.lang.structure.structure.AbstractConceptDeclaration"))) { node = null; } } MapSequence.fromMap(_params).put("node", node); } if (MapSequence.fromMap(_params).get("node") == null) { return false; } return true; }
protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { SNode node = event.getData(MPSCommonDataKeys.NODE); if (node != null) { if (!(SNodeOperations.isInstanceOf( node, "jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration"))) { node = null; } } MapSequence.fromMap(_params).put("methodNode", node); } if (MapSequence.fromMap(_params).get("methodNode") == null) { return false; } MapSequence.fromMap(_params).put("selectedCell", event.getData(MPSEditorDataKeys.EDITOR_CELL)); if (MapSequence.fromMap(_params).get("selectedCell") == null) { return false; } MapSequence.fromMap(_params).put("project", event.getData(PlatformDataKeys.PROJECT)); if (MapSequence.fromMap(_params).get("project") == null) { return false; } return true; }
@NotNull private static AnAction[] findActions(@NotNull AnActionEvent e) { PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE); Project project = e.getData(CommonDataKeys.PROJECT); Editor editor = e.getData(LangDataKeys.EDITOR); if (psiFile != null && project != null && editor != null) { List<HighlightInfo.IntentionActionDescriptor> quickFixes = ShowIntentionsPass.getAvailableActions(editor, psiFile, -1); Map<Anchor, List<AnAction>> children = new HashMap<Anchor, List<AnAction>>(); ArrayList<AnAction> first = new ArrayList<AnAction>(); children.put(Anchor.FIRST, first); ArrayList<AnAction> last = new ArrayList<AnAction>(); children.put(Anchor.LAST, last); extractActions(quickFixes, children); if (first.size() > 0 && last.size() > 0) { first.add(new AnSeparator()); } first.addAll(last); if (first.size() > 0) { return first.toArray(new AnAction[first.size()]); } } return AnAction.EMPTY_ARRAY; }
protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } MapSequence.fromMap(_params) .put("editorComponent", event.getData(MPSEditorDataKeys.EDITOR_COMPONENT)); if (MapSequence.fromMap(_params).get("editorComponent") == null) { return false; } MapSequence.fromMap(_params).put("editorCell", event.getData(MPSEditorDataKeys.EDITOR_CELL)); if (MapSequence.fromMap(_params).get("editorCell") == null) { return false; } MapSequence.fromMap(_params).put("model", event.getData(MPSCommonDataKeys.CONTEXT_MODEL)); if (MapSequence.fromMap(_params).get("model") == null) { return false; } { SNode node = event.getData(MPSCommonDataKeys.NODE); if (node != null) {} MapSequence.fromMap(_params).put("node", node); } if (MapSequence.fromMap(_params).get("node") == null) { return false; } return true; }
@Override public void update(AnActionEvent anActionEvent) { final Project project = anActionEvent.getData(CommonDataKeys.PROJECT); if (project != null) return; Object navigatable = anActionEvent.getData(CommonDataKeys.NAVIGATABLE); anActionEvent.getPresentation().setVisible(navigatable != null); }
@Override public void update(final AnActionEvent e) { e.getPresentation().setIcon(myTabs.isEditorTabs() ? myNewIcon : myIcon); e.getPresentation().setHoveredIcon(myTabs.isEditorTabs() ? myNewHoveredIcon : myHoveredIcon); e.getPresentation().setVisible(UISettings.getInstance().SHOW_CLOSE_BUTTON); e.getPresentation().setText("Close. Alt-click to close others."); }