private void popupInvoked(Component component, int x, int y) { final TreePath path = myTree.getLeadSelectionPath(); if (path == null) return; final DefaultActionGroup actions = new DefaultActionGroup(); final ActionManager actionManager = ActionManager.getInstance(); actions.add(actionManager.getAction(IdeActions.ACTION_EDIT_SOURCE)); actions.add(actionManager.getAction(IdeActions.ACTION_FIND_USAGES)); actions.add(myIncludeAction); actions.add(myExcludeAction); actions.addSeparator(); final InspectionToolWrapper toolWrapper = myTree.getSelectedToolWrapper(); if (toolWrapper != null) { final QuickFixAction[] quickFixes = myProvider.getQuickFixes(toolWrapper, myTree); if (quickFixes != null) { for (QuickFixAction quickFixe : quickFixes) { actions.add(quickFixe); } } final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName()); if (key == null) return; // e.g. DummyEntryPointsTool // options actions.addSeparator(); actions.add(new EditSettingsAction()); final List<AnAction> options = new InspectionsOptionsToolbarAction(this).createActions(); for (AnAction action : options) { actions.add(action); } } actions.addSeparator(); actions.add(actionManager.getAction(IdeActions.GROUP_VERSION_CONTROLS)); final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.CODE_INSPECTION, actions); menu.getComponent().show(component, x, y); }
protected void initTree() { ((DefaultTreeModel) myTree.getModel()).setRoot(myRoot); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); UIUtil.setLineStyleAngled(myTree); TreeUtil.installActions(myTree); myTree.setCellRenderer( new ColoredTreeCellRenderer() { public void customizeCellRenderer( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof MyNode) { final MyNode node = ((MyNode) value); setIcon(node.getIcon(expanded)); final Font font = UIUtil.getTreeFont(); if (node.isDisplayInBold()) { setFont(font.deriveFont(Font.BOLD)); } else { setFont(font.deriveFont(Font.PLAIN)); } append( node.getDisplayName(), node.isDisplayInBold() ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES); } } }); initToolbar(); ArrayList<AnAction> actions = createActions(true); if (actions != null) { final DefaultActionGroup group = new DefaultActionGroup(); for (AnAction action : actions) { group.add(action); } actions = getAdditionalActions(); if (actions != null) { group.addSeparator(); for (AnAction action : actions) { group.add(action); } } PopupHandler.installPopupHandler( myTree, group, ActionPlaces.UNKNOWN, ActionManager.getInstance()); // popup should follow the selection } }
@Override protected JComponent createCenterPanel() { JPanel panel = new JPanel(new BorderLayout()); // Toolbar DefaultActionGroup group = new DefaultActionGroup(); fillToolbarActions(group); group.addSeparator(); ExpandAllAction expandAllAction = new ExpandAllAction(); expandAllAction.registerCustomShortcutSet( new CustomShortcutSet( KeymapManager.getInstance() .getActiveKeymap() .getShortcuts(IdeActions.ACTION_EXPAND_ALL)), myTree); group.add(expandAllAction); CollapseAllAction collapseAllAction = new CollapseAllAction(); collapseAllAction.registerCustomShortcutSet( new CustomShortcutSet( KeymapManager.getInstance() .getActiveKeymap() .getShortcuts(IdeActions.ACTION_COLLAPSE_ALL)), myTree); group.add(collapseAllAction); panel.add( ActionManager.getInstance() .createActionToolbar(ActionPlaces.UNKNOWN, group, true) .getComponent(), BorderLayout.NORTH); // Tree expandFirst(); defaultExpandTree(); installSpeedSearch(); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); scrollPane.setPreferredSize(new Dimension(350, 450)); panel.add(scrollPane, BorderLayout.CENTER); return panel; }
private void initSearchToolbars() { DefaultActionGroup actionGroup1 = new DefaultActionGroup("search bar 1", false); mySearchActionsToolbar1 = (ActionToolbarImpl) ActionManager.getInstance() .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup1, true); mySearchActionsToolbar1.setForceMinimumSize(true); mySearchActionsToolbar1.setReservePlaceAutoPopupIcon(false); mySearchActionsToolbar1.setSecondaryButtonPopupStateModifier( new ActionToolbarImpl.PopupStateModifier() { @Override public int getModifiedPopupState() { return ActionButtonComponent.PUSHED; } @Override public boolean willModify() { return myFindModel.getSearchContext() != FindModel.SearchContext.ANY; } }); mySearchActionsToolbar1.setSecondaryActionsTooltip( "More Options(" + ShowMoreOptions.SHORT_CUT + ")"); actionGroup1.add(new PrevOccurrenceAction(this, mySearchFieldWrapper)); actionGroup1.add(new NextOccurrenceAction(this, mySearchFieldWrapper)); actionGroup1.add(new FindAllAction(this)); actionGroup1.addSeparator(); actionGroup1.add(new AddOccurrenceAction(this)); actionGroup1.add(new RemoveOccurrenceAction(this)); actionGroup1.add(new SelectAllAction(this)); // actionGroup1.addSeparator(); // actionGroup1.add(new ToggleMultiline(this));//todo get rid of it! actionGroup1.addSeparator(); actionGroup1.addAction(new ToggleInCommentsAction(this)).setAsSecondary(true); actionGroup1.addAction(new ToggleInLiteralsOnlyAction(this)).setAsSecondary(true); actionGroup1.addAction(new ToggleExceptCommentsAction(this)).setAsSecondary(true); actionGroup1.addAction(new ToggleExceptLiteralsAction(this)).setAsSecondary(true); actionGroup1.addAction(new ToggleExceptCommentsAndLiteralsAction(this)).setAsSecondary(true); DefaultActionGroup actionGroup2 = new DefaultActionGroup("search bar 2", false); mySearchActionsToolbar2 = (ActionToolbarImpl) ActionManager.getInstance() .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true); actionGroup2.add(new ToggleMatchCase(this)); actionGroup2.add(new ToggleRegex(this)); actionGroup2.add(new ToggleWholeWordsOnlyAction(this)); myMatchInfoLabel = new JLabel() { @Override public Font getFont() { Font font = super.getFont(); return font != null ? font.deriveFont(Font.BOLD) : null; } }; myMatchInfoLabel.setBorder(JBUI.Borders.empty(2, 20, 0, 20)); myClickToHighlightLabel = new LinkLabel<Object>( "Click to highlight", null, new LinkListener<Object>() { @Override public void linkSelected(LinkLabel aSource, Object aLinkData) { setMatchesLimit(Integer.MAX_VALUE); updateResults(true); } }); myClickToHighlightLabel.setVisible(false); mySearchActionsToolbar2 = (ActionToolbarImpl) ActionManager.getInstance() .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true); actionGroup2.add(new DefaultCustomComponentAction(myMatchInfoLabel)); actionGroup2.add(new DefaultCustomComponentAction(myClickToHighlightLabel)); mySearchActionsToolbar1.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY); mySearchActionsToolbar2.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY); mySearchActionsToolbar1.setBorder(null); mySearchActionsToolbar2.setBorder(null); mySearchActionsToolbar1.setOpaque(false); mySearchActionsToolbar2.setOpaque(false); new ShowMoreOptions(mySearchActionsToolbar1, mySearchFieldWrapper); Utils.setSmallerFontForChildren(mySearchActionsToolbar1); Utils.setSmallerFontForChildren(mySearchActionsToolbar2); }