Search in sources :

Example 1 with CustomComponentAction

use of com.intellij.openapi.actionSystem.ex.CustomComponentAction in project intellij-community by JetBrains.

the class PerFileConfigurableBase method createActionPanel.

@NotNull
private JPanel createActionPanel(@Nullable Object target, @NotNull Value<T> value, boolean editor) {
    AnAction changeAction = createValueAction(target, value);
    JComponent comboComponent = ((CustomComponentAction) changeAction).createCustomComponent(changeAction.getTemplatePresentation());
    JPanel panel = new JPanel(new BorderLayout()) {

        @Override
        public Color getBackground() {
            // track "Table.selectionInactiveBackground" switch
            Container parent = getParent();
            return parent instanceof JTable ? ((JTable) parent).getSelectionBackground() : super.getBackground();
        }
    };
    panel.add(comboComponent, BorderLayout.CENTER);
    comboComponent.setOpaque(false);
    DataContext dataContext = SimpleDataContext.getProjectContext(myProject);
    AnActionEvent event = AnActionEvent.createFromAnAction(changeAction, null, ActionPlaces.UNKNOWN, dataContext);
    changeAction.update(event);
    panel.revalidate();
    if (!editor)
        myResetRunnables.add(() -> changeAction.update(null));
    return panel;
}
Also used : CustomComponentAction(com.intellij.openapi.actionSystem.ex.CustomComponentAction) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CustomComponentAction

use of com.intellij.openapi.actionSystem.ex.CustomComponentAction in project intellij-community by JetBrains.

the class ActionToolbarImpl method fillToolBar.

private void fillToolBar(final List<AnAction> actions, boolean layoutSecondaries) {
    final List<AnAction> rightAligned = new ArrayList<>();
    if (myAddSeparatorFirst) {
        add(new MySeparator());
    }
    for (int i = 0; i < actions.size(); i++) {
        final AnAction action = actions.get(i);
        if (action instanceof RightAlignedToolbarAction) {
            rightAligned.add(action);
            continue;
        }
        if (layoutSecondaries) {
            if (!myActionGroup.isPrimary(action)) {
                mySecondaryActions.add(action);
                continue;
            }
        }
        if (action instanceof Separator) {
            if (i > 0 && i < actions.size() - 1) {
                add(new MySeparator());
            }
        } else if (action instanceof CustomComponentAction) {
            add(getCustomComponent(action));
        } else {
            add(createToolbarButton(action));
        }
    }
    if (mySecondaryActions.getChildrenCount() > 0) {
        mySecondaryActionsButton = new ActionButton(mySecondaryActions, myPresentationFactory.getPresentation(mySecondaryActions), myPlace, getMinimumButtonSize()) {

            @Override
            @ButtonState
            public int getPopState() {
                return mySecondaryButtonPopupStateModifier != null && mySecondaryButtonPopupStateModifier.willModify() ? mySecondaryButtonPopupStateModifier.getModifiedPopupState() : super.getPopState();
            }
        };
        mySecondaryActionsButton.setNoIconsInPopup(true);
        add(mySecondaryActionsButton);
    }
    for (AnAction action : rightAligned) {
        JComponent button = action instanceof CustomComponentAction ? getCustomComponent(action) : createToolbarButton(action);
        button.putClientProperty(RIGHT_ALIGN_KEY, Boolean.TRUE);
        add(button);
    }
//if ((ActionPlaces.MAIN_TOOLBAR.equals(myPlace) || ActionPlaces.NAVIGATION_BAR_TOOLBAR.equals(myPlace))) {
//  final AnAction searchEverywhereAction = ActionManager.getInstance().getAction("SearchEverywhere");
//  if (searchEverywhereAction != null) {
//    try {
//      final CustomComponentAction searchEveryWhereAction = (CustomComponentAction)searchEverywhereAction;
//      final JComponent searchEverywhere = searchEveryWhereAction.createCustomComponent(searchEverywhereAction.getTemplatePresentation());
//      searchEverywhere.putClientProperty("SEARCH_EVERYWHERE", Boolean.TRUE);
//      add(searchEverywhere);
//    }
//    catch (Exception ignore) {}
//  }
//}
}
Also used : CustomComponentAction(com.intellij.openapi.actionSystem.ex.CustomComponentAction) ArrayList(java.util.ArrayList) RelativePoint(com.intellij.ui.awt.RelativePoint)

Aggregations

CustomComponentAction (com.intellij.openapi.actionSystem.ex.CustomComponentAction)2 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1