List of usage examples for com.intellij.openapi.actionSystem ActionPlaces FAVORITES_VIEW_POPUP
String FAVORITES_VIEW_POPUP
To view the source code for com.intellij.openapi.actionSystem ActionPlaces FAVORITES_VIEW_POPUP.
Click Source Link
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;// w w w . j a v a 2 s . co m 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; }/*ww w . ja va 2s . co m*/ 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; }/* w w w.jav a2 s .com*/ 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.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 ww.j av a2 s . 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; }
From source file:com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel.java
License:Apache License
public FavoritesTreeViewPanel(Project project) { super(new BorderLayout()); myProject = project;//from w w w .ja v a 2 s .c o m myFavoritesManager = FavoritesManager.getInstance(myProject); myFavoritesTreeStructure = new FavoritesTreeStructure(project); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); root.setUserObject(myFavoritesTreeStructure.getRootElement()); final DefaultTreeModel treeModel = new DefaultTreeModel(root); myTree = new DnDAwareTree(treeModel); myBuilder = new FavoritesViewTreeBuilder(myProject, myTree, treeModel, myFavoritesTreeStructure); DockManager.getInstance(project).register(this); TreeUtil.installActions(myTree); UIUtil.setLineStyleAngled(myTree); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); myTree.setLargeModel(true); new TreeSpeedSearch(myTree); ToolTipManager.sharedInstance().registerComponent(myTree); final FavoritesComparator favoritesComparator = new FavoritesComparator(ProjectView.getInstance(project), FavoritesProjectViewPane.ID); myBuilder.setNodeDescriptorComparator(new Comparator<NodeDescriptor>() { @Override public int compare(NodeDescriptor o1, NodeDescriptor o2) { if (o1 instanceof FavoritesTreeNodeDescriptor && o2 instanceof FavoritesTreeNodeDescriptor) { final FavoritesListNode listNode1 = FavoritesTreeUtil .extractParentList((FavoritesTreeNodeDescriptor) o1); final FavoritesListNode listNode2 = FavoritesTreeUtil .extractParentList((FavoritesTreeNodeDescriptor) o2); if (listNode1.equals(listNode2)) { final Comparator<FavoritesTreeNodeDescriptor> comparator = myFavoritesManager .getCustomComparator(listNode1.getName()); if (comparator != null) { return comparator.compare((FavoritesTreeNodeDescriptor) o1, (FavoritesTreeNodeDescriptor) o2); } else { return favoritesComparator.compare(o1, o2); } } } return o1.getIndex() - o2.getIndex(); } }); myTree.setCellRenderer(new NodeRenderer() { @Override public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus); if (value instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; //only favorites roots to explain final Object userObject = node.getUserObject(); if (userObject instanceof FavoritesTreeNodeDescriptor) { final FavoritesTreeNodeDescriptor favoritesTreeNodeDescriptor = (FavoritesTreeNodeDescriptor) userObject; AbstractTreeNode treeNode = favoritesTreeNodeDescriptor.getElement(); FavoritesListProvider provider = FavoritesTreeUtil.getProvider(myFavoritesManager, favoritesTreeNodeDescriptor); if (provider != null) { Object o = myBuilder.getUi().getElementFor(value); if (o instanceof AbstractTreeNode) { o = ((AbstractTreeNode) o).getValue(); } provider.customizeRenderer(this, tree, o, selected, expanded, leaf, row, hasFocus); return; } final ItemPresentation presentation = treeNode.getPresentation(); String locationString = presentation.getLocationString(); if (locationString == null && node.getParent() != null && node.getParent().getParent() != null && node.getParent().getParent().getParent() == null) { final String location = favoritesTreeNodeDescriptor.getLocation(); if (location != null && location.length() > 0) { append(" (" + location + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); } } } } } }); myTreePopupHandler = CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_FAVORITES_VIEW_POPUP, ActionPlaces.FAVORITES_VIEW_POPUP); EditSourceOnDoubleClickHandler.install(myTree); EditSourceOnEnterKeyHandler.install(myTree); myCopyPasteDelegator = new CopyPasteDelegator(myProject, this) { @Override @NotNull protected PsiElement[] getSelectedElements() { return getSelectedPsiElements(); } }; AnActionButton addActionButton = AnActionButton .fromAction(ActionManager.getInstance().getAction("AddNewFavoritesList")); addActionButton.getTemplatePresentation().setIcon(CommonActionsPanel.Buttons.ADD.getIcon()); addActionButton.setShortcut(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD)); AnActionButton editActionButton = AnActionButton.fromAction(new EditFavoritesAction()); editActionButton.setShortcut(CommonShortcuts.CTRL_ENTER); AnActionButton deleteActionButton = new DeleteFromFavoritesAction(); deleteActionButton.setShortcut(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.REMOVE)); //final AnAction exportToTextFileAction = CommonActionsManager.getInstance().createExportToTextFileAction(createTextExporter()); //AnActionButton exportActionButton = AnActionButton.fromAction(exportToTextFileAction); //exportActionButton.setShortcut(exportToTextFileAction.getShortcutSet()); final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree).initPosition() .disableAddAction().disableRemoveAction().disableDownAction().disableUpAction() .addExtraAction(addActionButton).addExtraAction(editActionButton) .addExtraAction(deleteActionButton); //.addExtraAction(exportActionButton); final AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_NEW_ELEMENT); action.registerCustomShortcutSet(action.getShortcutSet(), myTree); final JPanel panel = decorator.createPanel(); panel.setBorder(IdeBorderFactory.createEmptyBorder()); add(panel, BorderLayout.CENTER); setBorder(IdeBorderFactory.createEmptyBorder()); myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() { @Override protected boolean isAutoScrollMode() { return myFavoritesManager.getViewSettings().isAutoScrollToSource(); } @Override protected void setAutoScrollMode(boolean state) { myFavoritesManager.getViewSettings().setAutoScrollToSource(state); } }; myAutoScrollToSourceHandler.install(myTree); myFavoritesManager.addFavoritesListener(new FavoritesListener() { @Override public void rootsChanged() { myBuilder.updateFromRoot(); myTree.repaint(); } @Override public void listAdded(String listName) { myBuilder.updateFromRoot(); myTree.repaint(); } @Override public void listRemoved(String listName) { myBuilder.updateFromRoot(); myTree.repaint(); } }); }
From source file:com.intellij.tools.BaseExternalToolsGroup.java
License:Apache License
private boolean isToolVisible(T tool, String context) { if (!tool.isEnabled()) return false; if (ActionPlaces.EDITOR_POPUP.equals(context) || ActionPlaces.EDITOR_TAB_POPUP.equals(context)) { return tool.isShownInEditor(); } else if (ActionPlaces.PROJECT_VIEW_POPUP.equals(context) || ActionPlaces.COMMANDER_POPUP.equals(context) || ActionPlaces.J2EE_VIEW_POPUP.equals(context) || ActionPlaces.TYPE_HIERARCHY_VIEW_POPUP.equals(context) || ActionPlaces.CALL_HIERARCHY_VIEW_POPUP.equals(context) || ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP.equals(context) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(context) || ActionPlaces.SCOPE_VIEW_POPUP.equals(context) || ActionPlaces.NAVIGATION_BAR.equals(context)) { return tool.isShownInProjectViews(); } else if (ActionPlaces.MAIN_MENU.equals(context)) { return tool.isShownInMainMenu(); } else if (ActionPlaces.USAGE_VIEW_POPUP.equals(context)) { return tool.isShownInSearchResultsPopup(); }/*from www . j av a 2 s. c om*/ return false; }