Search in sources :

Example 61 with StringSelection

use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.

the class TextCopyProvider method performCopy.

@Override
public void performCopy(@NotNull DataContext dataContext) {
    Collection<String> lines = getTextLinesToCopy();
    if (lines != null && !lines.isEmpty()) {
        String text = StringUtil.join(lines, getLinesSeparator());
        CopyPasteManager.getInstance().setContents(new StringSelection(text));
    }
}
Also used : StringSelection(java.awt.datatransfer.StringSelection)

Example 62 with StringSelection

use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.

the class CopyUrlAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    String url = findUrlAtCaret(e);
    assert url != null;
    CopyPasteManager.getInstance().setContents(new StringSelection(url));
}
Also used : StringSelection(java.awt.datatransfer.StringSelection)

Example 63 with StringSelection

use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.

the class EditorCopyPasteHelperImpl method copySelectionToClipboard.

@Override
public void copySelectionToClipboard(@NotNull Editor editor) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    List<TextBlockTransferableData> extraData = new ArrayList<>();
    String s = editor.getCaretModel().supportsMultipleCarets() ? getSelectedTextForClipboard(editor, extraData) : editor.getSelectionModel().getSelectedText();
    if (s == null)
        return;
    s = TextBlockTransferable.convertLineSeparators(s, "\n", extraData);
    Transferable contents = editor.getCaretModel().supportsMultipleCarets() ? new TextBlockTransferable(s, extraData, null) : new StringSelection(s);
    CopyPasteManager.getInstance().setContents(contents);
}
Also used : TextBlockTransferable(com.intellij.codeInsight.editorActions.TextBlockTransferable) ArrayList(java.util.ArrayList) TextBlockTransferableData(com.intellij.codeInsight.editorActions.TextBlockTransferableData) Transferable(java.awt.datatransfer.Transferable) TextBlockTransferable(com.intellij.codeInsight.editorActions.TextBlockTransferable) StringSelection(java.awt.datatransfer.StringSelection)

Example 64 with StringSelection

use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.

the class CopyConcatenatedStringToClipboardIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
    if (!(element instanceof PsiPolyadicExpression)) {
        return;
    }
    final PsiPolyadicExpression concatenationExpression = (PsiPolyadicExpression) element;
    final IElementType tokenType = concatenationExpression.getOperationTokenType();
    if (tokenType != JavaTokenType.PLUS) {
        return;
    }
    final PsiType type = concatenationExpression.getType();
    if (type == null || !type.equalsToText(JAVA_LANG_STRING)) {
        return;
    }
    final StringBuilder text = buildConcatenationText(concatenationExpression, new StringBuilder());
    CopyPasteManager.getInstance().setContents(new StringSelection(text.toString()));
}
Also used : IElementType(com.intellij.psi.tree.IElementType) StringSelection(java.awt.datatransfer.StringSelection)

Example 65 with StringSelection

use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.

the class EditorMultiCaretTest method testPastingLineWithBreakFromOutside.

public void testPastingLineWithBreakFromOutside() throws Exception {
    initText("<caret>\n" + "<caret>");
    CopyPasteManager.getInstance().setContents(new StringSelection("abc\n"));
    paste();
    checkResultByText("abc<caret>\n" + "abc<caret>");
}
Also used : StringSelection(java.awt.datatransfer.StringSelection)

Aggregations

StringSelection (java.awt.datatransfer.StringSelection)99 Clipboard (java.awt.datatransfer.Clipboard)28 ActionEvent (java.awt.event.ActionEvent)11 Transferable (java.awt.datatransfer.Transferable)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 JTextArea (javax.swing.JTextArea)7 Test (org.junit.Test)7 JPanel (javax.swing.JPanel)6 ActionListener (java.awt.event.ActionListener)5 JScrollPane (javax.swing.JScrollPane)5 Editor (com.intellij.openapi.editor.Editor)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)4 JMenuItem (javax.swing.JMenuItem)4 BibEntry (org.jabref.model.entry.BibEntry)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 PsiElement (com.intellij.psi.PsiElement)3 BorderLayout (java.awt.BorderLayout)3