Search in sources :

Example 86 with DataContext

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);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) ListPopup(com.intellij.openapi.ui.popup.ListPopup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) PackagingElementType(com.intellij.packaging.elements.PackagingElementType)

Example 87 with 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;
}
Also used : EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) PsiCodeBlock(com.intellij.psi.PsiCodeBlock) DataContext(com.intellij.openapi.actionSystem.DataContext) ASTNode(com.intellij.lang.ASTNode) EditorActionHandler(com.intellij.openapi.editor.actionSystem.EditorActionHandler) PsiElement(com.intellij.psi.PsiElement)

Example 88 with DataContext

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);
}
Also used : SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) DataContext(com.intellij.openapi.actionSystem.DataContext) EditorEx(com.intellij.openapi.editor.ex.EditorEx) TypedAction(com.intellij.openapi.editor.actionSystem.TypedAction)

Example 89 with 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));
    }
}
Also used : HashMap(com.intellij.util.containers.hash.HashMap) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ArrayList(java.util.ArrayList) List(java.util.List) DnDAwareTree(com.intellij.ide.dnd.aware.DnDAwareTree)

Example 90 with DataContext

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());
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) FavoritesListNode(com.intellij.ide.favoritesTreeView.FavoritesListNode) FavoritesTreeNodeDescriptor(com.intellij.ide.favoritesTreeView.FavoritesTreeNodeDescriptor) FavoritesManager(com.intellij.ide.favoritesTreeView.FavoritesManager)

Aggregations

DataContext (com.intellij.openapi.actionSystem.DataContext)204 Project (com.intellij.openapi.project.Project)73 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 NotNull (org.jetbrains.annotations.NotNull)23 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)23 Editor (com.intellij.openapi.editor.Editor)22 Nullable (org.jetbrains.annotations.Nullable)21 FileEditor (com.intellij.openapi.fileEditor.FileEditor)20 PsiFile (com.intellij.psi.PsiFile)17 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)16 Module (com.intellij.openapi.module.Module)13 PsiElement (com.intellij.psi.PsiElement)13 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 DataManager (com.intellij.ide.DataManager)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)9 List (java.util.List)9 Consumer (com.intellij.util.Consumer)7 AnAction (com.intellij.openapi.actionSystem.AnAction)6 Transferable (java.awt.datatransfer.Transferable)6