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

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

Introduction

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

Prototype

String ACTION_PASTE

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

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());
        }/*from w w w . ja  v  a 2  s  .  c om*/

        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  www .ja v  a 2 s . 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.vladsch.MissingInActions.actions.character.MiaMultiplePasteAction.java

License:Apache License

@NotNull
@Override/*from   ww  w .ja  v  a2 s .co m*/
protected AnAction getPasteAction(@NotNull final Editor editor, boolean recreateCaretsAction) {
    if (recreateCaretsAction) {
        return new DuplicateForClipboardCaretsAction(true, true);
    } else {
        return ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE);
    }
}

From source file:com.vladsch.MissingInActions.actions.line.DuplicateForClipboardCaretsActionHandler.java

License:Apache License

@Override
public void executeWriteAction(Editor editor, Caret unusedCaret, DataContext dataContext) {
    ClipboardCaretContent clipboardCaretContent = ClipboardCaretContent.studyClipboard(editor, dataContext);
    if (clipboardCaretContent == null)
        return;/*w w w.ja va2 s .  c o  m*/

    EditorEx editorEx = editor instanceof EditorEx ? (EditorEx) editor : null;
    int iMax = clipboardCaretContent.getCaretCount();
    LineSelectionManager manager = LineSelectionManager.getInstance(editor);
    Document doc = editor.getDocument();
    CaretModel caretModel = editor.getCaretModel();
    List<Couple<Integer>> copies = new ArrayList<>(iMax);
    boolean duplicateForCaretsPreserveOriginal = ApplicationSettings.getInstance()
            .isMultiPastePreserveOriginal();

    if (editor.getCaretModel().getCaretCount() > 1) {
        // already multi-caret, use the caret span to figure out which block to copy,
        // span: line block from first to last caret
        // if span == 1 line, keep all carets and all selections
        // if span > 1 line:
        // if have selections: keep carets with selections relative to start of block after duplication
        // if no selections: remove first and last, if they have no selection
        boolean haveSelections = false;
        Transferable mergedTransferable = null;

        EditHelpers.StudiedCarets studiedCarets = EditHelpers.studyCarets(editor, caretModel.getAllCarets());

        caretModel.removeSecondaryCarets();
        if (editorEx != null)
            editorEx.setColumnMode(false);

        if (studiedCarets.range.getSpan() == 0) {
            // remove carets without selections
            if (studiedCarets.caretSelections.total > 0) {
                // remove carets without selections
                studiedCarets.carets.removeIf(caret -> !caret.hasSelection());
            }
        } else {
            if (studiedCarets.caretSelections.total > 0) {
                // remove carets without selections on corresponding lines
                studiedCarets.carets.removeIf((editorCaret) -> !editorCaret.hasSelection());
            } else {
                // if not all lines have same number of carets, remove first and last, if they have no selection assuming they are there to mark the span of copied lines
                if (studiedCarets.eachLineCarets.total == -1 && studiedCarets.eachLineCarets.code <= 0
                        && studiedCarets.eachLineCarets.comment <= 0
                        && studiedCarets.eachLineCarets.blank <= 0) {
                    // remove first and last carets
                    studiedCarets.carets.removeIf((editorCaret) -> editorCaret == null
                            || editorCaret == studiedCarets.firstLineCaret
                                    && !studiedCarets.firstLineCaret.hasSelection()
                            || editorCaret == studiedCarets.lastLineCaret
                                    && !studiedCarets.lastLineCaret.hasSelection());
                }
            }
        }

        ArrayList<EditorCaret> carets = studiedCarets.carets;
        Range selRange = studiedCarets.range;

        // we need to duplicate the content, each caret in content duplicated for number of caret copies
        if (carets.size() > 1) {
            // make dupes so that the block carets are duped
            mergedTransferable = EditHelpers.getSplitRepeatedTransferable(clipboardCaretContent, carets.size());
        }

        // now we are ready to duplicate selRange block, and put carets on each duplicate relative to the first block which will not be included
        EditorCaret editorCaret = carets.get(0).copy();
        EditorPosition startPosition = editorCaret.getCaretPosition().onLine(selRange.getStart())
                .atStartOfLine();
        EditorPosition endPosition = editorCaret.getCaretPosition().onLine(selRange.getEnd())
                .atStartOfNextLine();
        editorCaret.setCaretPosition(startPosition);
        int offset = startPosition.getOffset();

        // do it in reverse order so as not to affect the offset
        String s = doc.getCharsSequence().subSequence(startPosition.getOffset(), endPosition.getOffset())
                .toString();
        int inserted = 0;
        int span = selRange.getSpan() + 1;
        for (int i = iMax; i-- > 0;) {
            Couple<Integer> couple;
            if (i == 0 && !duplicateForCaretsPreserveOriginal) {
                // don't insert, re-use
                couple = new Couple<>(selRange.getStart(), selRange.getEnd());
            } else {
                doc.insertString(startPosition.getOffset(), s);
                inserted += span;
                couple = new Couple<>(selRange.getStart() + inserted, selRange.getEnd() + inserted);
            }
            copies.add(couple);
        }

        manager.guard(() -> {
            // create multiple carets, copies from carets, but relative to start of original selection
            editorCaret.removeSelection();
            caretModel.removeSecondaryCarets();

            // build the carets
            int accumulatedOffset = 0;
            boolean firstCaret = true;
            for (int i = 0; i < iMax; i++) {
                Couple<Integer> couple = copies.get(i);

                int firstLine = couple.first;

                for (EditorCaret copyCaret : carets) {
                    EditorPosition editorPosition = copyCaret.getCaretPosition()
                            .onLine(copyCaret.getCaretPosition().line - selRange.getStart() + firstLine).copy();
                    EditorPosition selectionStart = copyCaret.getSelectionStart()
                            .onLine(copyCaret.getSelectionStart().line - selRange.getStart() + firstLine)
                            .copy();
                    EditorPosition selectionEnd = copyCaret.getSelectionEnd()
                            .onLine(copyCaret.getSelectionEnd().line - selRange.getStart() + firstLine).copy();

                    Caret caret = firstCaret ? caretModel.getPrimaryCaret()
                            : caretModel.addCaret(editorPosition.toVisualPosition());
                    if (caret != null) {
                        firstCaret = false;
                        accumulatedOffset += editorPosition.ensureRealSpaces();
                        accumulatedOffset += selectionStart.ensureRealSpaces();
                        accumulatedOffset += selectionEnd.ensureRealSpaces();

                        // replicate selection to this position
                        int selectionSize = selectionEnd.getOffset() - selectionStart.getOffset();
                        if (selectionSize > 0) {
                            caret.moveToOffset(selectionEnd.getOffset());
                            caret.setSelection(selectionStart.getOffset(), selectionEnd.getOffset());
                            manager.resetSelectionState(caret);
                        } else {
                            caret.moveToLogicalPosition(editorPosition);
                        }
                    }
                }
            }

            ClipboardCaretContent.setLastPastedClipboardCarets(editor, null);
        });

        if (myDoPaste) {
            // clear last pasted information, it is no good and will be cleared by running our action
            if (mergedTransferable != null) {
                CopyPasteManager.getInstance().setContents(mergedTransferable);
            }

            // now we paste
            final AnAction pasteAction = ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE);
            LineSelectionManager.getInstance(editor).runActionWithAdjustments(pasteAction);
            //AnActionEvent newEvent = AnActionEvent.createFromDataContext("MiaMultiPaste Recreate Carets",null,dataContext);
            //pasteAction.actionPerformed(newEvent);
        } else {
            if (mergedTransferable != null) {
                CopyPasteManager.getInstance().setContents(mergedTransferable);
            }
        }

        EditHelpers.scrollToCaret(editor);
    } else {
        manager.guard(() -> {
            EditorCaret editorCaret = manager.getEditorCaret(editor.getCaretModel().getPrimaryCaret());

            int selectionSize = editorCaret.getSelectionEnd().getOffset()
                    - editorCaret.getSelectionStart().getOffset();
            boolean isStartAnchor = editorCaret.isStartAnchor();

            if (myInsertBlankLine) {
                // we create a line above/below and recreate carets
                final ApplicationSettings settings = ApplicationSettings.getInstance();

                final EditorPosition pastePosition = settings.getLinePasteCaretAdjustmentType()
                        .getPastePosition(editorCaret.getCaretPosition());
                doc.insertString(pastePosition.atColumn(0).getOffset(), "\n");
                editorCaret.setCaretPosition(pastePosition.atColumn(editorCaret.getColumn()));
                editorCaret.commit();
            }

            if (editorCaret.hasLines() || editorCaret.isLine()) {
                editorCaret.trimOrExpandToFullLines();
                selectionSize = 0;
            } else {
                // dupe the line with selection replicated for each caret
                editorCaret.removeSelection();
                editor.getSelectionModel().removeSelection();
            }

            boolean useFirstLine = myInsertBlankLine || !duplicateForCaretsPreserveOriginal;
            for (int i = 0; i < iMax; i++) {
                final Couple<Integer> couple;
                if (useFirstLine) {
                    useFirstLine = false;
                    EditorPosition position = editorCaret.getCaretPosition();
                    couple = new Couple<>(position.atStartOfLine().getOffset(),
                            position.atStartOfNextLine().getOffset());
                } else {
                    couple = EditHelpers.duplicateLineOrSelectedBlockAtCaret(editor, editor.getDocument(),
                            editor.getCaretModel().getPrimaryCaret(), true);
                }

                if (couple != null)
                    copies.add(couple);
            }

            // create multiple carets on first line of every copy
            EditorPosition pos = editorCaret.getCaretPosition();
            editorCaret.removeSelection();

            // build the carets
            int accumulatedOffset = 0;
            for (int i = 0; i < iMax; i++) {
                Couple<Integer> couple = copies.get(i);

                int lineNumber = doc.getLineNumber(couple.first + accumulatedOffset);

                EditorPosition editorPosition = pos.onLine(lineNumber);
                Caret caret1 = i == 0 ? caretModel.getPrimaryCaret()
                        : caretModel.addCaret(editorPosition.toVisualPosition());
                if (caret1 != null) {
                    accumulatedOffset += editorPosition.ensureRealSpaces();
                    int offset = editorPosition.getOffset();

                    caret1.moveToLogicalPosition(editorPosition);

                    // replicate selection to this position
                    if (isStartAnchor) {
                        caret1.setSelection(offset - selectionSize, offset);
                    } else {
                        caret1.setSelection(offset, offset + selectionSize);
                    }
                    manager.resetSelectionState(caret1);
                }
            }
        });

        if (myDoPaste) {
            // clear last pasted information, it is no good and will be cleared by running our action
            ClipboardCaretContent.setLastPastedClipboardCarets(editor, null);

            // now we paste
            final AnAction pasteAction = ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE);
            LineSelectionManager.getInstance(editor).runActionWithAdjustments(pasteAction);
            //AnActionEvent newEvent = AnActionEvent.createFromDataContext("MiaMultiPaste Recreate Carets",null,dataContext);
            //pasteAction.actionPerformed(newEvent);
        } else {
            // clear clipboard information so adjustments don't get messed up
            ClipboardCaretContent.setLastPastedClipboardCarets(editor, null);
        }

        EditHelpers.scrollToCaret(editor);
    }
}

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

License:Apache License

public DesignerActionPanel(CordovaDesignerEditorPanel designer, JComponent shortcuts) {
    myDesigner = designer;//from w ww .  j a  va 2 s . c o m
    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  ww .  j  av  a  2 s .c  o  m
    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

private void doTestAction(@NotNull String cutOrCopy, String path) throws Exception {
    myFixture.setTestDataPath(BASE_PATH);
    File testFile = new File(path);
    String testFileName = testFile.getName();

    configureByDependencyIfExists(testFileName.replace(".kt", ".dependency.kt"));
    configureByDependencyIfExists(testFileName.replace(".kt", ".dependency.java"));
    myFixture.configureByFile(testFileName);
    myFixture.performEditorAction(cutOrCopy);

    String toFileName = testFileName.replace(".kt", ".to.kt");
    JetFile toFile = configureToFile(toFileName);
    performNotWriteEditorAction(IdeActions.ACTION_PASTE);

    myFixture.checkResultByFile(testFileName.replace(".kt", ".expected.kt"));

    if (!InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(testFile), ALLOW_UNRESOLVED_DIRECTIVE)) {
        checkNoUnresolvedReferences(toFile);
    }//from   w ww. j a  v  a2s  .c  o  m
}

From source file:org.jetbrains.jet.plugin.conversion.copy.AbstractJavaToKotlinCopyPasteConversionTest.java

License:Apache License

public void doTest(@SuppressWarnings("UnusedParameters") String path) throws Exception {
    myFixture.setTestDataPath(BASE_PATH);
    String testName = getTestName(false);
    myFixture.configureByFile(testName + ".java");
    myFixture.performEditorAction(IdeActions.ACTION_COPY);
    myFixture.configureByFile(testName + ".to.kt");
    myFixture.performEditorAction(IdeActions.ACTION_PASTE);
    myFixture.checkResultByFile(testName + ".expected.kt");
}

From source file:org.jetbrains.kotlin.idea.codeInsight.AbstractInsertImportOnPasteTest.java

License:Apache License

private void doTestAction(@NotNull String cutOrCopy, String path) throws Exception {
    myFixture.setTestDataPath(BASE_PATH);
    File testFile = new File(path);
    String testFileName = testFile.getName();

    configureByDependencyIfExists(testFileName.replace(".kt", ".dependency.kt"));
    configureByDependencyIfExists(testFileName.replace(".kt", ".dependency.java"));
    myFixture.configureByFile(testFileName);
    myFixture.performEditorAction(cutOrCopy);

    String toFileName = testFileName.replace(".kt", ".to.kt");
    JetFile toFile = configureToFile(toFileName);
    performNotWriteEditorAction(IdeActions.ACTION_PASTE);

    myFixture.checkResultByFile(testFileName.replace(".kt", ".expected.kt"));

    if (!InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(testFile, true),
            ALLOW_UNRESOLVED_DIRECTIVE)) {
        checkNoUnresolvedReferences(toFile);
    }//from   w w  w . j  av  a 2  s.  co  m
}