use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.
the class FindUIHelper method registerAction.
private void registerAction(String actionName, boolean replace, FindDialog findDialog) {
AnAction action = ActionManager.getInstance().getAction(actionName);
JRootPane findDialogRootComponent = ((JDialog) (findDialog.getWindow())).getRootPane();
new AnAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
myModel.setReplaceState(replace);
findDialog.updateReplaceVisibility();
}
}.registerCustomShortcutSet(action.getShortcutSet(), findDialogRootComponent);
}
use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.
the class ProjectSdksModel method createAddActions.
public void createAddActions(@NotNull DefaultActionGroup group, @NotNull final JComponent parent, @Nullable final Sdk selectedSdk, @NotNull final Consumer<Sdk> updateTree, @Nullable Condition<SdkTypeId> filter) {
final SdkType[] types = SdkType.getAllTypes();
for (final SdkType type : types) {
if (filter != null && !filter.value(type))
continue;
final AnAction addAction = new DumbAwareAction(type.getPresentableName(), null, type.getIconForAddAction()) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
doAdd(parent, selectedSdk, type, updateTree);
}
};
group.add(addAction);
}
}
use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.
the class ProjectWindowActionGroup method findWindowActionsWithProjectName.
private List<ProjectWindowAction> findWindowActionsWithProjectName(String projectName) {
List<ProjectWindowAction> result = null;
final AnAction[] children = getChildren(null);
for (AnAction child : children) {
if (!(child instanceof ProjectWindowAction)) {
continue;
}
final ProjectWindowAction windowAction = (ProjectWindowAction) child;
if (projectName.equals(windowAction.getProjectName())) {
if (result == null) {
result = new ArrayList<>();
}
result.add(windowAction);
}
}
if (result == null) {
return Collections.emptyList();
}
return result;
}
use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.
the class UnwrapHandler method showPopup.
private static void showPopup(final List<AnAction> options, Editor editor) {
final ScopeHighlighter highlighter = new ScopeHighlighter(editor);
DefaultListModel<String> m = new DefaultListModel<>();
for (AnAction a : options) {
m.addElement(((MyUnwrapAction) a).getName());
}
final JList list = new JBList(m);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(options.size());
list.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int index = list.getSelectedIndex();
if (index < 0)
return;
MyUnwrapAction a = (MyUnwrapAction) options.get(index);
List<PsiElement> toExtract = new ArrayList<>();
PsiElement wholeRange = a.collectAffectedElements(toExtract);
highlighter.highlight(wholeRange, toExtract);
}
});
PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
builder.setTitle(CodeInsightBundle.message("unwrap.popup.title")).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
MyUnwrapAction a = (MyUnwrapAction) options.get(list.getSelectedIndex());
a.actionPerformed(null);
}).addListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
highlighter.dropHighlight();
}
});
JBPopup popup = builder.createPopup();
popup.showInBestPositionFor(editor);
}
use of com.intellij.openapi.actionSystem.AnAction 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