use of com.intellij.openapi.actionSystem.ActionGroup in project intellij-community by JetBrains.
the class ActionUrl method readExternal.
@Override
public void readExternal(Element element) throws InvalidDataException {
myGroupPath = new ArrayList<>();
for (Object o : element.getChildren(PATH)) {
myGroupPath.add(((Element) o).getAttributeValue(VALUE));
}
final String attributeValue = element.getAttributeValue(VALUE);
if (element.getAttributeValue(IS_ACTION) != null) {
myComponent = attributeValue;
} else if (element.getAttributeValue(SEPARATOR) != null) {
myComponent = Separator.getInstance();
} else if (element.getAttributeValue(IS_GROUP) != null) {
final AnAction action = ActionManager.getInstance().getAction(attributeValue);
myComponent = action instanceof ActionGroup ? ActionsTreeUtil.createGroup((ActionGroup) action, true, null) : new Group(attributeValue, attributeValue, null);
}
myActionType = Integer.parseInt(element.getAttributeValue(ACTION_TYPE));
myAbsolutePosition = Integer.parseInt(element.getAttributeValue(POSITION));
DefaultJDOMExternalizer.readExternal(this, element);
}
use of com.intellij.openapi.actionSystem.ActionGroup in project intellij-community by JetBrains.
the class NewRecentProjectPanel method createList.
@Override
protected JBList createList(AnAction[] recentProjectActions, Dimension size) {
final JBList list = super.createList(recentProjectActions, size);
list.setBackground(FlatWelcomeFrame.getProjectsBackground());
list.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
Object selected = list.getSelectedValue();
final ProjectGroup group;
if (selected instanceof ProjectGroupActionGroup) {
group = ((ProjectGroupActionGroup) selected).getGroup();
} else {
group = null;
}
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_RIGHT) {
if (group != null) {
if (!group.isExpanded()) {
group.setExpanded(true);
ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
int index = list.getSelectedIndex();
RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
list.setSelectedIndex(group.getProjects().isEmpty() ? index : index + 1);
}
} else {
FlatWelcomeFrame frame = UIUtil.getParentOfType(FlatWelcomeFrame.class, list);
if (frame != null) {
FocusTraversalPolicy policy = frame.getFocusTraversalPolicy();
if (policy != null) {
Component next = policy.getComponentAfter(frame, list);
if (next != null) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(next, true);
});
}
}
}
}
} else if (keyCode == KeyEvent.VK_LEFT) {
if (group != null && group.isExpanded()) {
group.setExpanded(false);
int index = list.getSelectedIndex();
ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
list.setSelectedIndex(index);
}
}
}
});
list.addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
final int index = list.locationToIndex(new Point(x, y));
if (index != -1 && Arrays.binarySearch(list.getSelectedIndices(), index) < 0) {
list.setSelectedIndex(index);
}
final ActionGroup group = (ActionGroup) ActionManager.getInstance().getAction("WelcomeScreenRecentProjectActionGroup");
if (group != null) {
ActionManager.getInstance().createActionPopupMenu(ActionPlaces.WELCOME_SCREEN, group).getComponent().show(comp, x, y);
}
}
});
return list;
}
use of com.intellij.openapi.actionSystem.ActionGroup in project intellij-community by JetBrains.
the class GitBranchPopupActions method createActions.
ActionGroup createActions(@Nullable DefaultActionGroup toInsert, @NotNull String repoInfo, boolean firstLevelGroup) {
DefaultActionGroup popupGroup = new DefaultActionGroup(null, false);
List<GitRepository> repositoryList = Collections.singletonList(myRepository);
popupGroup.addAction(new GitNewBranchAction(myProject, repositoryList));
popupGroup.addAction(new CheckoutRevisionActions(myProject, repositoryList));
if (toInsert != null) {
popupGroup.addAll(toInsert);
}
popupGroup.addSeparator("Local Branches" + repoInfo);
List<BranchActionGroup> localBranchActions = myRepository.getBranches().getLocalBranches().stream().sorted().filter(branch -> !branch.equals(myRepository.getCurrentBranch())).map(branch -> new LocalBranchActions(myProject, repositoryList, branch.getName(), myRepository)).collect(toList());
// if there are only a few local favorites -> show all; for remotes it's better to show only favorites;
wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(localBranchActions, FAVORITE_BRANCH_COMPARATOR), getNumOfTopShownBranches(localBranchActions), firstLevelGroup ? GitBranchPopup.SHOW_ALL_LOCALS_KEY : null, firstLevelGroup);
popupGroup.addSeparator("Remote Branches" + repoInfo);
List<BranchActionGroup> remoteBranchActions = myRepository.getBranches().getRemoteBranches().stream().sorted().map(remoteBranch -> new RemoteBranchActions(myProject, repositoryList, remoteBranch.getName(), myRepository)).collect(toList());
wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(remoteBranchActions, FAVORITE_BRANCH_COMPARATOR), getNumOfTopShownBranches(remoteBranchActions), firstLevelGroup ? GitBranchPopup.SHOW_ALL_REMOTES_KEY : null);
return popupGroup;
}
use of com.intellij.openapi.actionSystem.ActionGroup in project intellij-community by JetBrains.
the class GradleToolWindowPanel method initContent.
public void initContent() {
final ActionManager actionManager = ActionManager.getInstance();
final ActionGroup actionGroup = (ActionGroup) actionManager.getAction(TOOL_WINDOW_TOOLBAR_ID);
ActionToolbar actionToolbar = actionManager.createActionToolbar(myPlace, actionGroup, true);
JPanel toolbarControl = new JPanel(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.weightx = 1;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.anchor = GridBagConstraints.WEST;
toolbarControl.add(actionToolbar.getComponent(), constraints);
for (JComponent component : getToolbarControls()) {
component.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
toolbarControl.add(component, constraints);
}
setToolbar(toolbarControl);
final JComponent payloadControl = buildContent();
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(payloadControl);
JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
myContent.add(scrollPane, CONTENT_CARD_NAME);
RichTextControlBuilder builder = new RichTextControlBuilder();
builder.setBackgroundColor(payloadControl.getBackground());
builder.setForegroundColor(UIUtil.getInactiveTextColor());
builder.setFont(payloadControl.getFont());
builder.setText(GradleBundle.message("gradle.toolwindow.text.no.linked.project"));
final JComponent noLinkedProjectControl = builder.build();
myContent.add(noLinkedProjectControl, NON_LINKED_CARD_NAME);
update();
}
use of com.intellij.openapi.actionSystem.ActionGroup in project intellij-community by JetBrains.
the class RunLineMarkerProvider method getLineMarkerInfo.
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
List<RunLineMarkerContributor> contributors = RunLineMarkerContributor.EXTENSION.allForLanguage(element.getLanguage());
Icon icon = null;
List<Info> infos = null;
for (RunLineMarkerContributor contributor : contributors) {
Info info = contributor.getInfo(element);
if (info == null) {
continue;
}
if (icon == null) {
icon = info.icon;
}
if (infos == null) {
infos = new SmartList<>();
}
infos.add(info);
}
if (icon == null)
return null;
if (infos.size() > 1) {
Collections.sort(infos, COMPARATOR);
final Info first = infos.get(0);
for (Iterator<Info> it = infos.iterator(); it.hasNext(); ) {
Info info = it.next();
if (info != first && first.shouldReplace(info)) {
it.remove();
}
}
}
final DefaultActionGroup actionGroup = new DefaultActionGroup();
for (Info info : infos) {
for (AnAction action : info.actions) {
actionGroup.add(new LineMarkerActionWrapper(element, action));
}
if (info != infos.get(infos.size() - 1)) {
actionGroup.add(new Separator());
}
}
List<Info> finalInfos = infos;
Function<PsiElement, String> tooltipProvider = element1 -> {
final StringBuilder tooltip = new StringBuilder();
for (Info info : finalInfos) {
if (info.tooltipProvider != null) {
String string = info.tooltipProvider.apply(element1);
if (string == null)
continue;
if (tooltip.length() != 0) {
tooltip.append("\n");
}
tooltip.append(string);
}
}
return tooltip.length() == 0 ? null : tooltip.toString();
};
return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, tooltipProvider, null, GutterIconRenderer.Alignment.CENTER) {
@Nullable
@Override
public GutterIconRenderer createGutterRenderer() {
return new LineMarkerGutterIconRenderer<PsiElement>(this) {
@Override
public AnAction getClickAction() {
return null;
}
@Override
public boolean isNavigateAction() {
return true;
}
@Nullable
@Override
public ActionGroup getPopupMenuActions() {
return actionGroup;
}
};
}
};
}
Aggregations