Example usage for com.intellij.openapi.actionSystem IdeActions ACTION_COPY

List of usage examples for com.intellij.openapi.actionSystem IdeActions ACTION_COPY

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem IdeActions ACTION_COPY.

Prototype

String ACTION_COPY

To view the source code for com.intellij.openapi.actionSystem IdeActions ACTION_COPY.

Click Source Link

Usage

From source file:com.android.tools.idea.uibuilder.editor.NlActionManager.java

License:Apache License

@NotNull
private DefaultActionGroup createPopupMenu(@NotNull ActionManager actionManager,
        @Nullable ScreenView screenView, @Nullable NlComponent leafComponent) {
    DefaultActionGroup group = new DefaultActionGroup();

    if (screenView != null) {
        if (leafComponent != null) {
            addViewHandlerActions(group, leafComponent, screenView.getSelectionModel().getSelection());
        }//  w w  w  . j a  va2 s.  com

        group.add(createSelectActionGroup(screenView.getSelectionModel()));
        group.addSeparator();
    }

    group.add(new MockupEditAction(mySurface));
    if (leafComponent != null && Mockup.hasMockupAttribute(leafComponent)) {
        group.add(new MockupDeleteAction(leafComponent));
    }
    group.addSeparator();

    group.add(actionManager.getAction(IdeActions.ACTION_CUT));
    group.add(actionManager.getAction(IdeActions.ACTION_COPY));
    group.add(actionManager.getAction(IdeActions.ACTION_PASTE));
    group.addSeparator();
    group.add(actionManager.getAction(IdeActions.ACTION_DELETE));
    group.addSeparator();
    group.add(myGotoComponentAction);
    group.add(createRefactoringMenu());
    group.add(new SaveScreenshotAction(mySurface));

    if (ConvertToConstraintLayoutAction.ENABLED) {
        group.addSeparator();
        group.add(new ConvertToConstraintLayoutAction(mySurface));
    }

    return group;
}

From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java

License:Apache License

public static void enableCapability(final JTextPane desc, Project project, String value, boolean editable,
        boolean navigation) {
    value = removeSmallFont(value);//from   w  ww.  java2s  .c  o  m
    HTMLEditorKit kit = new HTMLLetterWrappingEditorKit();
    desc.setEditorKit(kit);
    desc.setDocument(kit.createDefaultDocument());
    if (!editable && navigation) {
        value = NavigationDecorator.explodeHtml(project, value);
    }
    desc.setText(value);
    if (!editable) {
        desc.setCaret(new NonAdjustingCaret());
    }
    desc.addCaretListener(new BodyLimitCaretListener(desc));
    if (editable) {
        String element = checkElements(desc.getDocument().getDefaultRootElement());
        if (element != null) {
            desc.setToolTipText("Found unsupported element '" + element + "', editing is disabled.");
            editable = false;
        }
    }
    desc.setEditable(editable);

    if (editable && SpellCheckerManager.isAvailable()
            && ApplicationManager.getApplication().getComponent(AliConfiguration.class).spellChecker) {
        desc.getDocument().addDocumentListener(new SpellCheckDocumentListener(project, desc));
    }

    Font font = UIManager.getFont("Label.font");
    String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize()
            + "pt; }";
    ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(bodyRule);

    // AGM uses plain "p" to create lines, we need to avoid excessive spacing this by default creates
    String paragraphRule = "p { margin-top: 0px; }";
    ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(paragraphRule);

    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // following is needed to make copy work in the IDE
            try {
                StringSelection selection = new StringSelection(desc.getText(desc.getSelectionStart(),
                        desc.getSelectionEnd() - desc.getSelectionStart()));
                CopyPasteManager.getInstance().setContents(selection);
            } catch (Exception ex) {
                // no clipboard, so what
            }
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_COPY)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // avoid pasting non-supported HTML markup by always converting to plain text
            Transferable contents = CopyPasteManager.getInstance().getContents();
            try {
                desc.getActionMap().get(DefaultEditorKit.cutAction).actionPerformed(null);
                desc.getDocument().insertString(desc.getSelectionStart(),
                        (String) contents.getTransferData(DataFlavor.stringFlavor), null);
            } catch (Exception ex) {
                // no clipboard, so what
            }
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_PASTE)), desc);
    installNavigationShortCuts(desc);

}

From source file:com.intellij.ide.errorTreeView.NewErrorTreeViewPanel.java

License:Apache License

private void popupInvoked(Component component, int x, int y) {
    final TreePath path = myTree.getLeadSelectionPath();
    if (path == null) {
        return;//from   www . j  av  a2 s .  c  o m
    }
    DefaultActionGroup group = new DefaultActionGroup();
    if (getData(PlatformDataKeys.NAVIGATABLE.getName()) != null) {
        group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
    }
    group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY));
    addExtraPopupMenuActions(group);

    ActionPopupMenu menu = ActionManager.getInstance()
            .createActionPopupMenu(ActionPlaces.COMPILER_MESSAGES_POPUP, group);
    menu.getComponent().show(component, x, y);
}

From source file:com.jetbrains.lang.dart.ide.errorTreeView.DartProblemsViewPanel.java

License:Apache License

private void popupInvoked(final Component component, final int x, final int y) {
    final DefaultActionGroup group = new DefaultActionGroup();
    if (getData(CommonDataKeys.NAVIGATABLE.getName()) != null) {
        group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
    }//from w  ww . j  a  v  a  2s.  c o m

    group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY));

    final ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.TOOLBAR, group);
    menu.getComponent().show(component, x, y);
}

From source file:com.vladsch.MissingInActions.actions.MultiplePasteActionBase.java

License:Apache License

@Override
final public void actionPerformed(final AnActionEvent e) {
    Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
    if (!(component instanceof JComponent))
        return;// w  w w .  ja va2  s .co  m

    final ApplicationSettings settings = ApplicationSettings.getInstance();
    final DataContext dataContext = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    final JComponent focusedComponent = (JComponent) component;
    final CopyPasteManagerEx copyPasteManager = CopyPasteManagerEx.getInstanceEx();
    final HashMap<Transferable, ClipboardCaretContent> listEntryCarets = new HashMap<>();
    final boolean canCreateMultiCarets = editor != null && editor.getCaretModel().supportsMultipleCarets()
            && getCreateWithCaretsName(editor.getCaretModel().getCaretCount()) != null;
    final MultiPasteOptionsPane myEmptyContentDescription = new MultiPasteOptionsPane();
    final Shortcut[] moveLineUp = CommonUIShortcuts.getMoveLineUp().getShortcuts();
    final Shortcut[] moveLineDown = CommonUIShortcuts.getMoveLineDown().getShortcuts();
    final boolean[] inContentManipulation = new boolean[] { false };
    final boolean[] recreateCarets = new boolean[] { false };
    final HashMap<Transferable, String> stringTooLongSuffix = new HashMap<>();
    final DelayedRunner delayedRunner = new DelayedRunner();

    // Can change according to settings later
    // myEolText = "?";

    //noinspection unchecked
    final ContentChooser<Transferable>[] choosers = new ContentChooser[] { null };
    AwtRunnable listUpdater = new AwtRunnable(true, () -> {
        if (choosers[0] != null)
            choosers[0].updateListContents();
    });

    choosers[0] = new ContentChooser<Transferable>(project, getContentChooserTitle(editor, focusedComponent),
            true, true) {
        @Override
        protected String getStringRepresentationFor(final Transferable content) {
            //return (String) content.getTransferData(DataFlavor.stringFlavor);
            return getStringRep(editor, content, settings.isMultiPasteShowEolInViewer(), false, true);
        }

        @NotNull
        @Override
        protected String getShortStringFor(final Transferable content, final String fullString) {
            ClipboardCaretContent caretContent = getCaretContent(content);
            final int caretCount = caretContent == null ? 1 : caretContent.getCaretCount();
            String contentText = getStringRep(editor, content, false, false, false);
            String eolText = settings.isMultiPasteShowEolInList() && contentText.endsWith("\n")
                    && (caretCount == 1 || caretContent.allFullLines()) ? myEolText : "";
            stringTooLongSuffix.put(content, eolText);
            return String.format("[%d] %s", caretCount, super.getShortStringFor(content, contentText));
        }

        @NotNull
        @Override
        protected String getShortStringTooLongSuffix(Transferable content) {
            final String s = stringTooLongSuffix.get(content);
            return super.getShortStringTooLongSuffix(content) + (s == null ? "" : s);
        }

        @Override
        protected Editor createIdeaEditor(final String text) {
            delayedRunner.runAll();

            final Editor viewer = super.createIdeaEditor(text);
            final EditorSettings settings = viewer.getSettings();
            settings.setFoldingOutlineShown(false);
            settings.setIndentGuidesShown(false);
            settings.setLeadingWhitespaceShown(true);
            settings.setLineMarkerAreaShown(true);
            settings.setLineNumbersShown(true);
            settings.setTrailingWhitespaceShown(true);
            return viewer;
        }

        @Override
        protected void updateViewerForSelection(@NotNull final Editor viewer,
                @NotNull List<Transferable> allContents, @NotNull int[] selectedIndices) {
            if (viewer.getDocument().getTextLength() > 0) {
                // can create highlights in the editor to separate carets
                final ClipboardCaretContent caretContent;
                final Transferable content;
                if (selectedIndices.length > 1) {
                    // combine indices
                    content = EditHelpers.getMergedTransferable(editor, allContents, selectedIndices, true);
                    caretContent = ClipboardCaretContent.studyTransferable(editor, content);
                } else {
                    int index = selectedIndices[0];
                    content = allContents.get(index);
                    caretContent = getCaretContent(content);
                }

                assert caretContent != null;

                // convert multi caret text to \n separated ranges
                final String[] texts = caretContent.getTexts();
                if (texts != null) {
                    updateEditorHighlightRegions(viewer, caretContent, settings.isMultiPasteShowEolInViewer());

                    final FocusAdapter focusAdapter = new FocusAdapter() {
                        @Override
                        public void focusGained(final FocusEvent e) {
                            WriteCommandAction.runWriteCommandAction(viewer.getProject(), () -> {
                                final Document document = viewer.getDocument();
                                document.setReadOnly(false);
                                document.replaceString(0, document.getTextLength(),
                                        getStringRep(editor, content, false, true, false));
                                document.setReadOnly(true);
                                updateEditorHighlightRegions(viewer, caretContent, false);
                            });
                        }

                        @Override
                        public void focusLost(final FocusEvent e) {
                            final Document document = viewer.getDocument();
                            final int textLength = document.getTextLength();
                            if (textLength > 0) {
                                WriteCommandAction.runWriteCommandAction(viewer.getProject(), () -> {
                                    document.setReadOnly(false);
                                    document.replaceString(0, document.getTextLength(), getStringRep(editor,
                                            content, settings.isMultiPasteShowEolInViewer(), false, true));
                                    document.setReadOnly(true);
                                    updateEditorHighlightRegions(viewer, caretContent,
                                            settings.isMultiPasteShowEolInViewer());
                                });
                            }
                        }
                    };

                    viewer.getContentComponent().addFocusListener(focusAdapter);
                    delayedRunner.addRunnable(() -> {
                        viewer.getContentComponent().removeFocusListener(focusAdapter);
                    });
                }
            }
        }

        private void updateEditorHighlightRegions(@NotNull Editor viewer, ClipboardCaretContent caretContent,
                boolean multiPasteShowEolInViewer) {
            final TextRange[] textRanges = caretContent.getTextRanges();
            final int iMax = textRanges.length;
            MarkupModelEx markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(viewer.getDocument(),
                    project, true);
            final GutterIconRenderer charLinesSelection = new CaretIconRenderer(
                    PluginIcons.Clipboard_char_lines_caret);
            final GutterIconRenderer charSelection = new CaretIconRenderer(PluginIcons.Clipboard_char_caret);
            final GutterIconRenderer lineSelection = new CaretIconRenderer(PluginIcons.Clipboard_line_caret);
            int offset = 0;

            markupModel.removeAllHighlighters();

            for (int i = 0; i < iMax; i++) {
                final TextRange range = textRanges[i];
                final int startOffset = range.getStartOffset() + offset;
                offset += caretContent.isFullLine(i) && !multiPasteShowEolInViewer && i == iMax - 1 ? 0 : 1;
                RangeHighlighter highlighter = markupModel
                        .addLineHighlighter(viewer.offsetToLogicalPosition(startOffset).line, 1, null);
                highlighter.setGutterIconRenderer(caretContent.isFullLine(i) ? lineSelection
                        : caretContent.isCharLine(i) ? charLinesSelection : charSelection);
            }
        }

        @Override
        protected List<Transferable> getContents() {
            final Transferable[] contents = copyPasteManager.getAllContents();
            final ArrayList<Transferable> list = new ArrayList<>();
            list.addAll(Arrays.asList(contents));
            list.removeIf(content -> {
                if (content instanceof StringSelection) {
                    try {
                        final String data = (String) content.getTransferData(DataFlavor.stringFlavor);
                        return data.isEmpty();
                    } catch (UnsupportedFlavorException e1) {
                        LOG.error("", e1);
                    } catch (IOException e1) {
                        LOG.error("", e1);
                    }
                }
                return false;
            });
            return list;
        }

        @NotNull
        @Override
        public String getSelectedText() {
            if (choosers[0] == null) {
                return super.getSelectedText();
            } else {
                final int[] selectedIndices = choosers[0].getSelectedIndices();
                if (selectedIndices.length > 1) {
                    // combine indices
                    Transferable content = EditHelpers.getMergedTransferable(editor,
                            choosers[0].getAllContents(), selectedIndices, true);
                    return getStringRep(editor, content, settings.isMultiPasteShowEolInViewer(), false, true);
                } else {
                    return super.getSelectedText();
                }
            }
        }

        @Override
        protected void removeContentAt(final Transferable content) {
            copyPasteManager.removeContent(content);
            listEntryCarets.remove(content);
        }

        @Override
        protected void listKeyPressed(final KeyEvent event) {
            ContentChooser<Transferable> chooser = choosers[0];
            if (event.getKeyCode() != 0 && chooser != null) {
                if (event.getKeyCode() == KeyEvent.VK_UP && (event.getModifiers() & KeyEvent.ALT_MASK) != 0) {
                    // move selection up
                    moveSelections(chooser, true);
                    event.consume();
                } else if (event.getKeyCode() == KeyEvent.VK_DOWN
                        && (event.getModifiers() & KeyEvent.ALT_MASK) != 0) {
                    moveSelections(chooser, false);
                    event.consume();
                }
            }
        }

        @NotNull
        @Override
        protected Action[] createActions() {
            Action[] actions = super.createActions();
            if (canCreateMultiCarets) {
                Action[] multiCaretActions = new Action[actions.length + 1];
                System.arraycopy(actions, 0, multiCaretActions, 0, actions.length);
                Action createWithMultiCarets = new OkAction() {
                    @Override
                    protected void doAction(final ActionEvent e) {
                        recreateCarets[0] = true;
                        super.doAction(e);
                    }
                };
                final String name = getCreateWithCaretsName(editor.getCaretModel().getCaretCount());
                createWithMultiCarets.putValue(Action.NAME,
                        name == null ? Bundle.message("content-chooser.add-with-carets.label") : name);
                multiCaretActions[actions.length] = createWithMultiCarets;
                return multiCaretActions;
            }
            return actions;
        }

        @NotNull
        @Override
        protected Action[] createLeftSideActions() {
            Action showOptionsAction = new OkAction() {
                @Override
                protected void doAction(final ActionEvent e) {
                    final boolean showOptions = !settings.isMultiPasteShowOptions();
                    settings.setMultiPasteShowOptions(showOptions);
                    putValue(Action.NAME, showOptions ? Bundle.message("content-chooser.hide-options.label")
                            : Bundle.message("content-chooser.show-options.label"));
                    myEmptyContentDescription.myPanel.setVisible(showOptions);
                }
            };

            final boolean showOptions = settings.isMultiPasteShowOptions();
            showOptionsAction.putValue(Action.NAME,
                    showOptions ? Bundle.message("content-chooser.hide-options.label")
                            : Bundle.message("content-chooser.show-options.label"));
            return new Action[] { showOptionsAction };
        }

        @Nullable
        @Override
        protected JComponent getAboveEditorComponent() {
            String copyShortcut = CommonUIShortcuts
                    .getNthShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY), 1);
            String deleteShortcut = CommonUIShortcuts
                    .getNthShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_DELETE), 1);
            String moveLineUpShortcut = CommonUIShortcuts.getNthShortcutText(
                    ActionManager.getInstance().getAction(CommonUIShortcuts.ACTION_MOVE_LINE_UP_ACTION), 2);
            String moveLineDownShortcut = CommonUIShortcuts.getNthShortcutText(
                    ActionManager.getInstance().getAction(CommonUIShortcuts.ACTION_MOVE_LINE_DOWN_ACTION), 2);
            if (!copyShortcut.isEmpty())
                copyShortcut = String.format(" (%s)", copyShortcut);
            if (!deleteShortcut.isEmpty())
                deleteShortcut = String.format(" (%s)", deleteShortcut);
            if (!moveLineUpShortcut.isEmpty())
                moveLineUpShortcut = String.format(" (%s)", moveLineUpShortcut);
            if (!moveLineDownShortcut.isEmpty())
                moveLineDownShortcut = String.format(" (%s)", moveLineDownShortcut);
            String bannerSlogan = Bundle.indexedMessage("content-chooser.above-editor.description",
                    copyShortcut, deleteShortcut, moveLineUpShortcut, moveLineDownShortcut);
            myEmptyContentDescription.setContentBody(
                    Utils.join(bannerSlogan.split("\n"), "<ul align='left'>", "</ul>", "<li>", "</li>"));
            myEmptyContentDescription.setSettingsChangedRunnable(() -> {
                if (choosers[0] != null) {
                    final int[] indices = choosers[0].getSelectedIndices();
                    choosers[0].updateListContents();
                    choosers[0].setSelectedIndices(indices);
                }
            });

            myEmptyContentDescription.myPanel.setVisible(settings.isMultiPasteShowOptions());
            return myEmptyContentDescription.myPanel;
        }

        private void moveSelections(final ContentChooser<Transferable> chooser, boolean moveUp) {
            final int[] indices = chooser.getSelectedIndices();
            final List<Transferable> allContents = new ArrayList<>(chooser.getAllContents());
            boolean allConsecutive = true;
            int firstIndex = -1;
            int lastIndex = -1;

            for (int index : indices) {
                if (firstIndex == -1) {
                    firstIndex = index;
                    lastIndex = index;
                } else {
                    if (lastIndex + 1 != index) {
                        allConsecutive = false;
                    }
                    lastIndex = index;
                }
            }

            List<Transferable> moved = new ArrayList<>();

            int anchorIndex = moveUp ? firstIndex : lastIndex;
            for (int index : indices) {
                if (allConsecutive || index != anchorIndex) {
                    moved.add(allContents.get(index));
                }
            }

            if (!allConsecutive) {
                allContents.removeAll(moved);
                allContents.addAll(anchorIndex + (moveUp ? 1 : 0), moved);
                reOrderContentList(allContents);
            } else {
                final int size = lastIndex - firstIndex + 1;
                final int halfSize = size / 2;
                if (moveUp) {
                    if (firstIndex <= 0) {
                        // reverse
                        if (halfSize > 0) {
                            for (int i = 0; i < halfSize; i++) {
                                Transferable first = allContents.get(firstIndex + i);
                                Transferable last = allContents.get(lastIndex - i);
                                allContents.set(firstIndex + i, last);
                                allContents.set(lastIndex - i, first);
                            }
                            reOrderContentList(allContents);
                        }
                    } else {
                        allContents.removeAll(moved);
                        allContents.addAll(firstIndex - 1, moved);
                        reOrderContentList(allContents);
                        anchorIndex = firstIndex - 1;
                    }
                } else {
                    if (lastIndex + 1 >= allContents.size()) {
                        // reverse order
                        if (halfSize > 0) {
                            for (int i = 0; i < halfSize; i++) {
                                Transferable first = allContents.get(firstIndex + i);
                                Transferable last = allContents.get(lastIndex - i);
                                allContents.set(firstIndex + i, last);
                                allContents.set(lastIndex - i, first);
                            }
                            reOrderContentList(allContents);
                        }
                    } else {
                        allContents.removeAll(moved);
                        allContents.addAll(lastIndex + 2 - moved.size(), moved);
                        reOrderContentList(allContents);
                        anchorIndex = lastIndex + 1;
                    }
                }
            }

            chooser.updateListContents();
            int index = 0;
            if (moveUp) {
                for (int i = anchorIndex; index < indices.length; i++)
                    indices[index++] = i;
            } else {
                for (int i = anchorIndex; index < indices.length; i--)
                    indices[index++] = i;
            }
            chooser.setSelectedIndices(indices);
        }

        private void reOrderContentList(@NotNull List<Transferable> allContents) {
            inContentManipulation[0] = true;
            try {
                int iMax = allContents.size();
                Transferable[] currentOrder = copyPasteManager.getAllContents();
                int i;
                for (i = iMax; i-- > 0;) {
                    if (currentOrder[i] != allContents.get(i))
                        break;
                }

                for (i++; i-- > 0;) {
                    copyPasteManager.moveContentToStackTop(allContents.get(i));
                }
            } finally {
                inContentManipulation[0] = false;
            }
        }

        @Override
        protected Icon getListEntryIcon(@NotNull final Transferable content) {
            final ClipboardCaretContent caretContent = getCaretContent(content);
            return caretContent != null && caretContent.getCaretCount() > 1 ? PluginIcons.Clipboard_carets
                    : PluginIcons.Clipboard_text;
        }

        @Nullable
        private ClipboardCaretContent getCaretContent(final @NotNull Transferable content) {
            ClipboardCaretContent caretContent = listEntryCarets.get(content);
            if (!listEntryCarets.containsKey(content)) {
                caretContent = ClipboardCaretContent.studyTransferable(editor, content);
                listEntryCarets.put(content, caretContent);
            }
            return caretContent;
        }
    };

    final ContentChooser<Transferable> chooser = choosers[0];
    final CopyPasteManager.ContentChangedListener contentChangedListener = new CopyPasteManager.ContentChangedListener() {
        @Override
        public void contentChanged(@Nullable final Transferable oldTransferable,
                final Transferable newTransferable) {
            if (!inContentManipulation[0]) {
                listUpdater.run();
            }
        }
    };

    try {
        copyPasteManager.addContentChangedListener(contentChangedListener);
        if (!chooser.getAllContents().isEmpty()) {
            chooser.show();
        } else {
            chooser.close(DialogWrapper.CANCEL_EXIT_CODE);
        }
    } finally {
        copyPasteManager.removeContentChangedListener(contentChangedListener);
    }

    if (chooser.isOK()) {
        final int[] selectedIndices = chooser.getSelectedIndices();
        if (selectedIndices.length == 1) {
            copyPasteManager.moveContentToStackTop(chooser.getAllContents().get(selectedIndices[0]));
        } else {
            copyPasteManager.setContents(
                    EditHelpers.getMergedTransferable(editor, chooser.getAllContents(), selectedIndices, true));
        }

        if (editor != null) {
            if (editor.isViewer())
                return;

            final AnAction pasteAction = getPasteAction(editor, recreateCarets[0]);

            AnActionEvent newEvent = new AnActionEvent(e.getInputEvent(),
                    DataManager.getInstance().getDataContext(focusedComponent), e.getPlace(),
                    e.getPresentation(), ActionManager.getInstance(), e.getModifiers());

            pasteAction.actionPerformed(newEvent);
        } else {
            final Action pasteAction = getPasteAction(focusedComponent);
            if (pasteAction != null) {
                pasteAction
                        .actionPerformed(new ActionEvent(focusedComponent, ActionEvent.ACTION_PERFORMED, ""));
            }
        }
    }
}

From source file:gradleplug.messages.MessagesPanel.java

License:Apache License

public MessagesPanel(Project project) {
    this.project = project;
    setLayout(new BorderLayout());
    JPanel rootPanel = new JPanel(new BorderLayout());

    errorViewStructure = new ErrorViewStructure(project, true);
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    root.setUserObject(errorViewStructure.createDescriptor(errorViewStructure.getRootElement(), null));
    final DefaultTreeModel treeModel = new DefaultTreeModel(root);
    messageTree = new Tree(treeModel);
    errorViewTreeBuilder = new ErrorViewTreeBuilder(messageTree, treeModel, errorViewStructure);
    exporterToTextFile = new ErrorViewTextExporter(errorViewStructure);

    TreeUtil.installActions(messageTree);
    UIUtil.setLineStyleAngled(messageTree);
    messageTree.setRootVisible(false);//from  www.  j a v  a 2s . c o m
    messageTree.setShowsRootHandles(true);
    messageTree.setLargeModel(true);
    JScrollPane scrollPane = NewErrorTreeRenderer.install(messageTree);
    rootPanel.add(scrollPane, BorderLayout.CENTER);

    add(createToolbarPanel(), BorderLayout.WEST);
    add(rootPanel, BorderLayout.CENTER);

    messageTree.addMouseListener(new PopupHandler() {
        public void invokePopup(Component component, int x, int y) {
            final TreePath path = messageTree.getLeadSelectionPath();
            if (path == null) {
                return;
            }
            DefaultActionGroup group = new DefaultActionGroup();
            group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY));
            ActionPopupMenu menu = ActionManager.getInstance()
                    .createActionPopupMenu(ActionPlaces.COMPILER_MESSAGES_POPUP, group);
            menu.getComponent().show(component, x, y);
        }
    });
}

From source file:ivyplug.ui.messages.MessagesPanel.java

License:Apache License

public MessagesPanel(Project project) {
    this.project = project;
    setLayout(new BorderLayout());
    JPanel rootPanel = new JPanel(new BorderLayout());

    errorViewStructure = new ErrorViewStructure(project, true);
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    root.setUserObject(errorViewStructure.createDescriptor(errorViewStructure.getRootElement(), null));
    final DefaultTreeModel treeModel = new DefaultTreeModel(root);
    messageTree = JTreeFactory.createJTree(treeModel);
    errorViewTreeBuilder = new ErrorViewTreeBuilder(messageTree, treeModel, errorViewStructure);
    exporterToTextFile = new ErrorViewTextExporter(errorViewStructure);

    TreeUtil.installActions(messageTree);
    UIUtil.setLineStyleAngled(messageTree);
    messageTree.setRootVisible(false);/*from  w w  w  .  j  a  v a 2s .c  om*/
    messageTree.setShowsRootHandles(true);
    messageTree.setLargeModel(true);
    JScrollPane scrollPane = NewErrorTreeRenderer.install(messageTree);
    rootPanel.add(scrollPane, BorderLayout.CENTER);

    add(createToolbarPanel(), BorderLayout.WEST);
    add(rootPanel, BorderLayout.CENTER);

    messageTree.addMouseListener(new PopupHandler() {
        public void invokePopup(Component component, int x, int y) {
            final TreePath path = messageTree.getLeadSelectionPath();
            if (path == null) {
                return;
            }
            DefaultActionGroup group = new DefaultActionGroup();
            group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY));
            ActionPopupMenu menu = ActionManager.getInstance()
                    .createActionPopupMenu(ActionPlaces.COMPILER_MESSAGES_POPUP, group);
            menu.getComponent().show(component, x, y);
        }
    });
}

From source file:org.cordovastudio.editors.designer.actions.DesignerActionPanel.java

License:Apache License

public DesignerActionPanel(CordovaDesignerEditorPanel designer, JComponent shortcuts) {
    myDesigner = designer;//from w w w  .j  a  v a  2  s.c  om
    myCommonEditActionsProvider = new CommonEditActionsProvider(designer);
    myShortcuts = shortcuts;

    createInplaceEditingAction(myShortcuts).setDesignerPanel(designer);

    myActionGroup = createActionGroup();
    myToolbar = createToolbar();

    ActionManager actionManager = ActionManager.getInstance();
    myPopupGroup.add(actionManager.getAction(IdeActions.ACTION_CUT));
    myPopupGroup.add(actionManager.getAction(IdeActions.ACTION_COPY));
    myPopupGroup.add(actionManager.getAction(IdeActions.ACTION_PASTE));
    myPopupGroup.addSeparator();
    myPopupGroup.add(actionManager.getAction(IdeActions.ACTION_DELETE));
    myPopupGroup.addSeparator();
    myPopupGroup.add(createSelectActionGroup(designer));
    myPopupGroup.addSeparator();
    myPopupGroup.add(myDynamicPopupGroup);

    designer.getSurfaceArea().addSelectionListener(new ComponentSelectionListener() {
        @Override
        public void selectionChanged(IEditableArea area) {
            updateSelectionActions(area.getSelection());
        }
    });
}

From source file:org.cordovastudio.editors.designer.CordovaDesignerActionPanel.java

License:Apache License

public CordovaDesignerActionPanel(CordovaDesignerEditorPanel designer, JComponent shortcuts) {
    myDesigner = designer;//from w w  w.j  a v a  2 s  .c  om
    myCommonEditActionsProvider = new CommonEditActionsProvider(designer);
    myShortcuts = shortcuts;

    createInplaceEditingAction(myShortcuts).setDesignerPanel(designer);

    myActionGroup = createActionGroup();
    myToolbar = createToolbar();

    ActionManager actionManager = ActionManager.getInstance();
    myPopupGroup.add(actionManager.getAction(IdeActions.ACTION_CUT));
    myPopupGroup.add(actionManager.getAction(IdeActions.ACTION_COPY));
    myPopupGroup.add(actionManager.getAction(IdeActions.ACTION_PASTE));
    myPopupGroup.addSeparator();
    myPopupGroup.add(actionManager.getAction(IdeActions.ACTION_DELETE));
    myPopupGroup.addSeparator();
    myPopupGroup.add(createSelectActionGroup(designer));
    myPopupGroup.addSeparator();
    myPopupGroup.add(myDynamicPopupGroup);

    designer.getSurfaceArea().addSelectionListener(new ComponentSelectionListener() {
        @Override
        public void selectionChanged(IEditableArea area) {
            updateSelectionActions(area.getSelection());
        }
    });
}

From source file:org.jetbrains.jet.plugin.codeInsight.AbstractInsertImportOnPasteTest.java

License:Apache License

public void doTestCopy(String path) throws Exception {
    doTestAction(IdeActions.ACTION_COPY, path);
}