use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class ShowAddPackagingElementPopupAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DefaultActionGroup group = new DefaultActionGroup();
for (PackagingElementType type : PackagingElementFactory.getInstance().getAllElementTypes()) {
group.add(new AddNewPackagingElementAction((PackagingElementType<?>) type, myArtifactEditor));
}
final DataContext dataContext = e.getDataContext();
final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup("Add", group, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
popup.showInBestPositionFor(dataContext);
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class LeaveCodeBlockEnterProcessor method doEnter.
@Override
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
PsiElement parent = psiElement.getParent();
if (!(parent instanceof PsiCodeBlock)) {
return false;
}
final ASTNode node = psiElement.getNode();
if (node != null && CONTROL_FLOW_ELEMENT_TYPES.contains(node.getElementType())) {
return false;
}
boolean leaveCodeBlock = isControlFlowBreak(psiElement);
if (!leaveCodeBlock) {
return false;
}
final int offset = parent.getTextRange().getEndOffset();
// Check if there is empty line after the code block. Just move caret there in the case of the positive answer.
final CharSequence text = editor.getDocument().getCharsSequence();
if (offset < text.length() - 1) {
final int i = CharArrayUtil.shiftForward(text, offset + 1, " \t");
if (i < text.length() && text.charAt(i) == '\n') {
editor.getCaretModel().moveToOffset(offset + 1);
EditorActionManager actionManager = EditorActionManager.getInstance();
EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_LINE_END);
final DataContext dataContext = DataManager.getInstance().getDataContext(editor.getComponent());
if (dataContext != null) {
actionHandler.execute(editor, dataContext);
return true;
}
}
}
editor.getCaretModel().moveToOffset(offset);
return false;
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method typeInAlienEditor.
private static void typeInAlienEditor(Editor alienEditor, char c) {
TypedAction action = EditorActionManager.getInstance().getTypedAction();
DataContext dataContext = ((EditorEx) alienEditor).getDataContext();
action.actionPerformed(alienEditor, c, dataContext);
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class DeleteFromFavoritesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
Project project = e.getProject();
FavoritesViewTreeBuilder builder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(dataContext);
if (project == null || builder == null) {
return;
}
Set<Object> selection = builder.getSelectedElements();
if (selection.isEmpty()) {
return;
}
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
FavoritesListProvider provider = favoritesManager.getListProvider(listName);
if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.REMOVE, project, selection)) {
provider.handle(CommonActionsPanel.Buttons.REMOVE, project, selection, builder.getTree());
return;
}
FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
final DnDAwareTree tree = FavoritesTreeViewPanel.FAVORITES_TREE_KEY.getData(dataContext);
assert roots != null && tree != null;
Map<String, List<AbstractTreeNode>> toRemove = new HashMap<>();
for (FavoritesTreeNodeDescriptor root : roots) {
final AbstractTreeNode node = root.getElement();
if (node instanceof FavoritesListNode) {
favoritesManager.removeFavoritesList((String) node.getValue());
} else {
final FavoritesListNode listNode = FavoritesTreeUtil.extractParentList(root);
LOG.assertTrue(listNode != null);
final String name = listNode.getName();
if (!toRemove.containsKey(name)) {
toRemove.put(name, new ArrayList<>());
}
toRemove.get(name).add(node);
}
}
for (String name : toRemove.keySet()) {
favoritesManager.removeRoot(name, toRemove.get(name));
}
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class SendToFavoritesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
Project project = e.getProject();
final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
if (roots == null)
return;
for (FavoritesTreeNodeDescriptor root : roots) {
FavoritesTreeNodeDescriptor listNode = root.getFavoritesRoot();
if (listNode != null && listNode != root && listNode.getElement() instanceof FavoritesListNode) {
doSend(favoritesManager, new FavoritesTreeNodeDescriptor[] { root }, listNode.getElement().getName());
}
}
}
Aggregations