Search in sources :

Example 66 with StringSelection

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

the class EditorActionTest method testPasteInOneLineMode.

public void testPasteInOneLineMode() throws Exception {
    init("", TestFileType.TEXT);
    ((EditorEx) myEditor).setOneLineMode(true);
    CopyPasteManager.getInstance().setContents(new StringSelection("a\rb"));
    executeAction(IdeActions.ACTION_EDITOR_PASTE);
    checkResultByText("a b<caret>");
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) StringSelection(java.awt.datatransfer.StringSelection)

Example 67 with StringSelection

use of java.awt.datatransfer.StringSelection in project otertool by wuntee.

the class GuiWorkshop method setClipboardContents.

public static void setClipboardContents(String s) {
    StringSelection stringSelection = new StringSelection(s);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(stringSelection, new ClipboardOwner() {

        public void lostOwnership(Clipboard arg0, Transferable arg1) {
        }
    });
}
Also used : Transferable(java.awt.datatransfer.Transferable) ClipboardOwner(java.awt.datatransfer.ClipboardOwner) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 68 with StringSelection

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

the class CopyLineStatusRangeAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final String content = myLineStatusTracker.getVcsContent(myRange) + "\n";
    CopyPasteManager.getInstance().setContents(new StringSelection(content));
}
Also used : StringSelection(java.awt.datatransfer.StringSelection)

Example 69 with StringSelection

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

the class EnvVariablesTable method createExtraActions.

@NotNull
@Override
protected AnActionButton[] createExtraActions() {
    AnActionButton copyButton = new AnActionButton(ActionsBundle.message("action.EditorCopy.text"), AllIcons.Actions.Copy) {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            stopEditing();
            StringBuilder sb = new StringBuilder();
            List<EnvironmentVariable> variables = getSelection();
            for (EnvironmentVariable environmentVariable : variables) {
                if (environmentVariable.getIsPredefined() || isEmpty(environmentVariable))
                    continue;
                if (sb.length() > 0)
                    sb.append('\n');
                sb.append(StringUtil.escapeChar(environmentVariable.getName(), '=')).append('=').append(StringUtil.escapeChar(environmentVariable.getValue(), '='));
            }
            CopyPasteManager.getInstance().setContents(new StringSelection(sb.toString()));
        }

        @Override
        public boolean isEnabled() {
            return super.isEnabled() && !getSelection().isEmpty();
        }
    };
    AnActionButton pasteButton = new AnActionButton(ActionsBundle.message("action.EditorPaste.text"), AllIcons.Actions.Menu_paste) {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            removeSelected();
            stopEditing();
            String content = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
            if (content == null || !content.contains("="))
                return;
            List<EnvironmentVariable> parsed = new ArrayList<>();
            List<String> lines = StringUtil.split(content, "\n");
            for (String line : lines) {
                int pos = line.indexOf('=');
                if (pos == -1)
                    continue;
                while (pos > 0 && line.charAt(pos - 1) == '\\') {
                    pos = line.indexOf('=', pos + 1);
                }
                line = line.replaceAll("[\\\\]{1}", "\\\\\\\\");
                parsed.add(new EnvironmentVariable(StringUtil.unescapeStringCharacters(line.substring(0, pos)), StringUtil.unescapeStringCharacters(line.substring(pos + 1)), false));
            }
            List<EnvironmentVariable> variables = new ArrayList<>(getEnvironmentVariables());
            variables.addAll(parsed);
            setValues(variables);
        }
    };
    return new AnActionButton[] { copyButton, pasteButton };
}
Also used : ArrayList(java.util.ArrayList) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnActionButton(com.intellij.ui.AnActionButton) NotNull(org.jetbrains.annotations.NotNull) StringSelection(java.awt.datatransfer.StringSelection) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with StringSelection

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

the class CopyQuickDocAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    String selected = e.getData(DocumentationManager.SELECTED_QUICK_DOC_TEXT);
    if (selected == null || selected.isEmpty()) {
        return;
    }
    CopyPasteManager.getInstance().setContents(new StringSelection(selected));
}
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