List of usage examples for com.intellij.openapi.actionSystem ActionPlaces PROJECT_VIEW_POPUP
String PROJECT_VIEW_POPUP
To view the source code for com.intellij.openapi.actionSystem ActionPlaces PROJECT_VIEW_POPUP.
Click Source Link
From source file:com.android.tools.idea.actions.AndroidBuildModuleAction.java
License:Apache License
protected void updatePresentation(@NotNull AnActionEvent e) { DataContext dataContext = e.getDataContext(); Module[] modules = getSelectedModules(dataContext); int moduleCount = modules == null ? 0 : modules.length; boolean hasModules = moduleCount > 0; Presentation presentation = e.getPresentation(); presentation.setEnabled(hasModules); String presentationText;/*from w w w. j av a 2 s . c o m*/ if (hasModules) { String text = myActionName + (moduleCount == 1 ? " Module" : " Modules"); for (int i = 0; i < moduleCount; i++) { if (text.length() > 30) { text = myActionName + " Selected Modules"; break; } Module toMake = modules[i]; if (i != 0) { text += ","; } text += " '" + toMake.getName() + "'"; } presentationText = text; } else { presentationText = myActionName; } presentation.setText(presentationText); presentation.setVisible(hasModules || !ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace())); }
From source file:com.github.beansoftapp.reatnative.idea.actions.UpdageModuleAARAction.java
License:Apache License
public void update(AnActionEvent event) { super.update(event); Presentation presentation = event.getPresentation(); if (!presentation.isEnabled()) { return;//from w w w.ja va2 s. c om } final DataContext dataContext = event.getDataContext(); final Module module = LangDataKeys.MODULE.getData(dataContext); Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext); final boolean isEnabled = module != null || modules != null; presentation.setEnabled(isEnabled); // final String actionName = getTemplatePresentation().getTextWithMnemonic(); String presentationText; // if (modules != null) { // String text = actionName; // for (int i = 0; i < modules.length; i++) { // if (text.length() > 30) { // text = CompilerBundle.message("action.make.selected.modules.text"); // break; // } // Module toMake = modules[i]; // if (i!=0) { // text += ","; // } // text += " '" + toMake.getName() + "'"; // } // presentationText = text; // } // else if (module != null) { presentationText = "Update AAR of '" + module.getName() + "'"; } else { presentationText = "Select a module first"; } presentation.setText(presentationText); presentation.setVisible(isEnabled || !ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace())); }
From source file:com.igormaznitsa.ideamindmap.view.KnowledgeViewPane.java
License:Apache License
private void initTree() { myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); UIUtil.setLineStyleAngled(myTree);//from www . ja va2s . co m myTree.setRootVisible(false); myTree.setShowsRootHandles(true); myTree.expandPath(new TreePath(myTree.getModel().getRoot())); myTree.setSelectionPath(new TreePath(myTree.getModel().getRoot())); EditSourceOnDoubleClickHandler.install(myTree); ToolTipManager.sharedInstance().registerComponent(myTree); TreeUtil.installActions(myTree); myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { fireTreeChangeListener(); } }); myTree.getModel().addTreeModelListener(new TreeModelListener() { @Override public void treeNodesChanged(TreeModelEvent e) { fireTreeChangeListener(); } @Override public void treeNodesInserted(TreeModelEvent e) { fireTreeChangeListener(); } @Override public void treeNodesRemoved(TreeModelEvent e) { fireTreeChangeListener(); } @Override public void treeStructureChanged(TreeModelEvent e) { fireTreeChangeListener(); } }); new SpeedSearch(myTree); myTree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { final DefaultMutableTreeNode selectedNode = ((ProjectViewTree) myTree).getSelectedNode(); if (selectedNode != null && !selectedNode.isLeaf()) { return; } DataContext dataContext = DataManager.getInstance().getDataContext(myTree); OpenSourceUtil.openSourcesFrom(dataContext, false); } else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) { if (e.isConsumed()) return; PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance(); boolean[] isCopied = new boolean[1]; if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) { copyPasteManager.clear(); e.consume(); } } } }); CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP); }
From source file:com.intellij.compiler.actions.MakeModuleAction.java
License:Apache License
public void update(AnActionEvent event) { super.update(event); Presentation presentation = event.getPresentation(); if (!presentation.isEnabled()) { return;/* ww w .j a v a 2 s. c o m*/ } final DataContext dataContext = event.getDataContext(); final Module module = LangDataKeys.MODULE.getData(dataContext); Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext); final boolean isEnabled = module != null || modules != null; presentation.setEnabled(isEnabled); final String actionName = getTemplatePresentation().getTextWithMnemonic(); String presentationText; if (modules != null) { String text = actionName; for (int i = 0; i < modules.length; i++) { if (text.length() > 30) { text = CompilerBundle.message("action.make.selected.modules.text"); break; } Module toMake = modules[i]; if (i != 0) { text += ","; } text += " '" + toMake.getName() + "'"; } presentationText = text; } else if (module != null) { presentationText = actionName + " '" + module.getName() + "'"; } else { presentationText = actionName; } presentation.setText(presentationText); presentation.setVisible(isEnabled || !ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace())); }
From source file:com.intellij.debugger.actions.ToggleFieldBreakpointAction.java
License:Apache License
@Override public void update(AnActionEvent event) { SourcePosition place = getPlace(event); boolean toEnable = place != null; Presentation presentation = event.getPresentation(); if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) { presentation.setVisible(toEnable); } else if (DebuggerAction.isContextView(event)) { presentation.setText(DebuggerBundle.message("action.add.field.watchpoint.text")); Project project = event.getData(CommonDataKeys.PROJECT); if (project != null && place != null) { Document document = PsiDocumentManager.getInstance(project).getDocument(place.getFile()); if (document != null) { final int offset = place.getOffset(); final BreakpointManager breakpointManager = (DebuggerManagerEx.getInstanceEx(project)) .getBreakpointManager(); final Breakpoint fieldBreakpoint = offset >= 0 ? breakpointManager.findBreakpoint(document, offset, FieldBreakpoint.CATEGORY) : null;/*from w w w. j a v a 2 s . c om*/ if (fieldBreakpoint != null) { presentation.setEnabled(false); return; } } } } presentation.setVisible(toEnable); }
From source file:com.intellij.debugger.actions.ToggleFieldBreakpointAction.java
License:Apache License
@Nullable public static SourcePosition getPlace(AnActionEvent event) { final DataContext dataContext = event.getDataContext(); final Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { return null; }//from ww w . j a v a 2 s .com if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) { final PsiElement psiElement = event.getData(CommonDataKeys.PSI_ELEMENT); if (psiElement instanceof PsiField) { return SourcePosition.createFromElement(psiElement); } return null; } final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext); if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) { final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext); final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); if (debugProcess != null) { // if there is an active debugsession final Ref<SourcePosition> positionRef = new Ref<SourcePosition>(null); debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) { public Priority getPriority() { return Priority.HIGH; } public void threadAction() { ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { final FieldDescriptorImpl descriptor = (FieldDescriptorImpl) selectedNode .getDescriptor(); positionRef.set(descriptor.getSourcePosition(project, debuggerContext)); } }); } }); final SourcePosition sourcePosition = positionRef.get(); if (sourcePosition != null) { return sourcePosition; } } } if (DebuggerAction.isContextView(event)) { DebuggerTree tree = DebuggerTree.DATA_KEY.getData(dataContext); if (tree != null && tree.getSelectionPath() != null) { DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent()); if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl) { Field field = ((FieldDescriptorImpl) node.getDescriptor()).getField(); DebuggerSession session = tree.getDebuggerContext().getDebuggerSession(); PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project, (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project)); if (psiClass != null) { psiClass = (PsiClass) psiClass.getNavigationElement(); final PsiField psiField = psiClass.findFieldByName(field.name(), true); if (psiField != null) { return SourcePosition.createFromElement(psiField); } } } } return null; } Editor editor = event.getData(CommonDataKeys.EDITOR); if (editor == null) { editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); } if (editor != null) { final Document document = editor.getDocument(); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); if (file != null) { final VirtualFile virtualFile = file.getVirtualFile(); FileType fileType = virtualFile != null ? virtualFile.getFileType() : null; if (fileType == JavaFileType.INSTANCE || fileType == JavaClassFileType.INSTANCE) { final PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset()); if (field != null) { return SourcePosition.createFromElement(field); } } } } return null; }
From source file:com.intellij.debugger.actions.ToggleMethodBreakpointAction.java
License:Apache License
@Nullable private static PlaceInDocument getPlace(AnActionEvent event) { final Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { return null; }/*from w ww . j av a2 s .co m*/ PsiElement method = null; Document document = null; if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.NAVIGATION_BAR.equals(event.getPlace())) { final PsiElement psiElement = event.getData(LangDataKeys.PSI_ELEMENT); if (psiElement instanceof PsiMethod) { final PsiFile containingFile = psiElement.getContainingFile(); if (containingFile != null) { method = psiElement; document = PsiDocumentManager.getInstance(project).getDocument(containingFile); } } } else { Editor editor = event.getData(PlatformDataKeys.EDITOR); if (editor == null) { editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); } if (editor != null) { document = editor.getDocument(); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); if (file != null) { final VirtualFile virtualFile = file.getVirtualFile(); FileType fileType = virtualFile != null ? virtualFile.getFileType() : null; if (fileType == JavaFileType.INSTANCE || fileType == JavaClassFileType.INSTANCE) { method = findMethod(project, editor); } } } } if (method != null) { final PsiElement method1 = method; final Document document1 = document; return new PlaceInDocument() { public Document getDocument() { return document1; } public int getOffset() { return method1.getTextOffset(); } }; } return null; }
From source file:com.intellij.ide.actions.DeleteAction.java
License:Apache License
public void update(AnActionEvent event) { String place = event.getPlace(); Presentation presentation = event.getPresentation(); if (ActionPlaces.PROJECT_VIEW_POPUP.equals(place) || ActionPlaces.COMMANDER_POPUP.equals(place)) presentation.setText(IdeBundle.message("action.delete.ellipsis")); else//from w w w . java2s . c o m presentation.setText(IdeBundle.message("action.delete")); DataContext dataContext = event.getDataContext(); Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { presentation.setEnabled(false); return; } DeleteProvider provider = getDeleteProvider(dataContext); if (event.getInputEvent() instanceof KeyEvent) { KeyEvent keyEvent = (KeyEvent) event.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()); } final boolean canDelete = provider != null && provider.canDeleteElement(dataContext); if (ActionPlaces.isPopupPlace(event.getPlace())) { presentation.setVisible(canDelete); } else { presentation.setEnabled(canDelete); } }
From source file:com.intellij.ide.actions.OpenModuleSettingsAction.java
License:Apache License
protected static boolean isModuleInProjectViewPopup(AnActionEvent e) { if (ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace())) { final Project project = getEventProject(e); final Module module = LangDataKeys.MODULE.getData(e.getDataContext()); if (project != null && module != null) { final VirtualFile moduleFolder = PlatformDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); if (moduleFolder == null) { return false; }/*from w w w . j a va 2 s . c o m*/ if (ProjectRootsUtil.isModuleContentRoot(moduleFolder, project) || ProjectRootsUtil.isSourceOrTestRoot(moduleFolder, project)) { return true; } } } return false; }
From source file:com.intellij.ide.favoritesTreeView.actions.AddToFavoritesAction.java
License:Apache License
public static boolean canCreateNodes(AnActionEvent e) { DataContext dataContext = e.getDataContext(); if (e.getProject() == null) { return false; }/*from w w w . j a va 2s.c o m*/ if (e.getPlace().equals(ActionPlaces.FAVORITES_VIEW_POPUP) && FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext) == null) { return false; } final boolean inProjectView = e.getPlace().equals(ActionPlaces.J2EE_VIEW_POPUP) || e.getPlace().equals(ActionPlaces.STRUCTURE_VIEW_POPUP) || e.getPlace().equals(ActionPlaces.PROJECT_VIEW_POPUP); //com.intellij.openapi.actionSystem.ActionPlaces.USAGE_VIEW_TOOLBAR return getNodesToAdd(dataContext, inProjectView) != null; }