Search in sources :

Example 21 with StringSelection

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

the class DartServerHighlightingTest method testServerDataUpdateOnPaste.

public void testServerDataUpdateOnPaste() {
    initServerDataTest();
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(getProject());
    final VirtualFile file = getFile().getVirtualFile();
    checkServerDataInitialState(file);
    CopyPasteManager.getInstance().setContents(new StringSelection("long text 012345678901234567890123456789"));
    // paste a lot at the beginning of the region
    getEditor().getCaretModel().moveToOffset(27);
    myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE);
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), TextRange.create(67, 78), TextRange.create(87, 98));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 79), TextRange.create(20, 26), TextRange.create(67, 78), TextRange.create(80, 99), TextRange.create(80, 86), TextRange.create(87, 98));
    undoAndUpdateHighlighting(file);
    // paste a lot in the middle of the region
    getEditor().getCaretModel().moveToOffset(29);
    myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE);
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), /*TextRange.create(28, 39),*/
    TextRange.create(87, 98));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 79), TextRange.create(20, 26), TextRange.create(27, 78), TextRange.create(80, 99), TextRange.create(80, 86), TextRange.create(87, 98));
    undoAndUpdateHighlighting(file);
    // paste a lot at the end of the region
    getEditor().getCaretModel().moveToOffset(38);
    myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE);
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), TextRange.create(27, 38), TextRange.create(87, 98));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 79), TextRange.create(20, 26), TextRange.create(27, 38), TextRange.create(80, 99), TextRange.create(80, 86), TextRange.create(87, 98));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) StringSelection(java.awt.datatransfer.StringSelection)

Example 22 with StringSelection

use of java.awt.datatransfer.StringSelection in project android by JetBrains.

the class TranslationsEditorTest method translationTextFieldFontCanDisplayPastedHebrew.

@Test
public void translationTextFieldFontCanDisplayPastedHebrew() {
    myTranslationsEditor.getTable().selectCell(TableCell.row(1).column(5));
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection("יישום פשוט"), EmptyClipboardOwner.INSTANCE);
    JTextComponentFixture translationTextField = myTranslationsEditor.getTranslationTextField();
    KeyStroke keyStroke = getKeyStroke(translationTextField.target().getInputMap(), DefaultEditorKit.pasteAction);
    translationTextField.pressAndReleaseKey(KeyPressInfo.keyCode(keyStroke.getKeyCode()).modifiers(keyStroke.getModifiers()));
    assertEquals(-1, translationTextField.font().target().canDisplayUpTo("יישום פשוט"));
}
Also used : JTextComponentFixture(org.fest.swing.fixture.JTextComponentFixture) StringSelection(java.awt.datatransfer.StringSelection) Test(org.junit.Test)

Example 23 with StringSelection

use of java.awt.datatransfer.StringSelection in project android by JetBrains.

the class RenderErrorContributor method reportThrowable.

/**
   * Display the problem list encountered during a render.
   *
   * @return if the throwable was hidden.
   */
private boolean reportThrowable(@NotNull HtmlBuilder builder, @NotNull final Throwable throwable, boolean hideIfIrrelevant) {
    StackTraceElement[] frames = throwable.getStackTrace();
    int end = -1;
    boolean haveInterestingFrame = false;
    for (int i = 0; i < frames.length; i++) {
        StackTraceElement frame = frames[i];
        if (isInterestingFrame(frame)) {
            haveInterestingFrame = true;
        }
        String className = frame.getClassName();
        if (className.equals(RENDER_SESSION_IMPL_FQCN)) {
            end = i;
            break;
        }
    }
    if (end == -1 || !haveInterestingFrame) {
        // Not a recognized stack trace range: just skip it
        if (hideIfIrrelevant) {
            if (RenderLogger.isLoggingAllErrors()) {
                ShowExceptionFix detailsFix = new ShowExceptionFix(myResult.getModule().getProject(), throwable);
                builder.addLink("Show Exception", myLinkManager.createRunnableLink(detailsFix));
            }
            return true;
        } else {
            // List just the top frames
            for (int i = 0; i < frames.length; i++) {
                StackTraceElement frame = frames[i];
                if (!isVisible(frame)) {
                    end = i;
                    if (end == 0) {
                        // Find end instead
                        for (int j = 0; j < frames.length; j++) {
                            frame = frames[j];
                            String className = frame.getClassName();
                            if (className.equals(RENDER_SESSION_IMPL_FQCN)) {
                                end = j;
                                break;
                            }
                        }
                    }
                    break;
                }
            }
        }
    }
    builder.addHtml(StringUtil.replace(throwable.toString(), "\n", "<BR/>")).newline();
    boolean wasHidden = false;
    int indent = 2;
    File platformSource = null;
    boolean platformSourceExists = true;
    for (int i = 0; i < end; i++) {
        StackTraceElement frame = frames[i];
        if (isHiddenFrame(frame)) {
            wasHidden = true;
            continue;
        }
        String className = frame.getClassName();
        String methodName = frame.getMethodName();
        builder.addNbsps(indent);
        builder.add("at ").add(className).add(".").add(methodName);
        String fileName = frame.getFileName();
        if (fileName != null && !fileName.isEmpty()) {
            int lineNumber = frame.getLineNumber();
            String location = fileName + ':' + lineNumber;
            if (isInterestingFrame(frame)) {
                if (wasHidden) {
                    builder.addNbsps(indent).add("    ...").newline();
                    wasHidden = false;
                }
                String url = myLinkManager.createOpenStackUrl(className, methodName, fileName, lineNumber);
                builder.add("(").addLink(location, url).add(")");
            } else {
                // Try to link to local documentation
                String url = null;
                if (isFramework(frame) && platformSourceExists) {
                    // try to link to documentation, if available
                    if (platformSource == null) {
                        IAndroidTarget target = myResult.getRenderTask() != null ? myResult.getRenderTask().getConfiguration().getRealTarget() : null;
                        platformSource = target != null ? AndroidSdks.getInstance().findPlatformSources(target) : null;
                        platformSourceExists = platformSource != null;
                    }
                    if (platformSourceExists) {
                        File classFile = new File(platformSource, frame.getClassName().replace('.', File.separatorChar) + DOT_JAVA);
                        if (!classFile.exists()) {
                            // Probably an innerclass like foo.bar.Outer.Inner; the above would look for foo/bar/Outer/Inner.java; try
                            // again at foo/bar/
                            File parentFile = classFile.getParentFile();
                            classFile = new File(parentFile.getParentFile(), parentFile.getName() + DOT_JAVA);
                            if (!classFile.exists()) {
                                // in theory we should keep trying this repeatedly for more deeply nested inner classes
                                classFile = null;
                            }
                        }
                        if (classFile != null) {
                            url = HtmlLinkManager.createFilePositionUrl(classFile, lineNumber, 0);
                        }
                    }
                }
                if (url != null) {
                    builder.add("(").addLink(location, url).add(")");
                } else {
                    builder.add("(").add(location).add(")");
                }
            }
            builder.newline();
        }
    }
    builder.addLink("Copy stack to clipboard", myLinkManager.createRunnableLink(() -> {
        String text = Throwables.getStackTraceAsString(throwable);
        try {
            CopyPasteManager.getInstance().setContents(new StringSelection(text));
            RenderErrorPanel.showNotification("Stack trace copied to clipboard");
        } catch (Exception ignore) {
        }
    }));
    return false;
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) IOException(java.io.IOException) StringSelection(java.awt.datatransfer.StringSelection)

Example 24 with StringSelection

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

the class PsiCopyPasteManager method clear.

public void clear() {
    myRecentData = null;
    myCopyPasteManager.setContents(new StringSelection(""));
}
Also used : StringSelection(java.awt.datatransfer.StringSelection)

Example 25 with StringSelection

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

the class PsiViewerDialog method createActions.

@NotNull
@Override
protected Action[] createActions() {
    AbstractAction copyPsi = new AbstractAction("Cop&y PSI") {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            PsiElement element = parseText(myEditor.getDocument().getText());
            List<PsiElement> allToParse = new ArrayList<>();
            if (element instanceof PsiFile) {
                allToParse.addAll(((PsiFile) element).getViewProvider().getAllFiles());
            } else if (element != null) {
                allToParse.add(element);
            }
            String data = "";
            for (PsiElement psiElement : allToParse) {
                data += DebugUtil.psiToString(psiElement, !myShowWhiteSpacesBox.isSelected(), true);
            }
            CopyPasteManager.getInstance().setContents(new StringSelection(data));
        }
    };
    return ArrayUtil.mergeArrays(new Action[] { copyPsi }, super.createActions());
}
Also used : NotNull(org.jetbrains.annotations.NotNull) StringSelection(java.awt.datatransfer.StringSelection) NotNull(org.jetbrains.annotations.NotNull)

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