diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/CompareValueWithClipboardAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/CompareValueWithClipboardAction.java index 2d27120d1ab0..e415e08eacd4 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/CompareValueWithClipboardAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/CompareValueWithClipboardAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import com.intellij.openapi.diff.*; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.SystemInfo; +import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; @@ -72,16 +73,16 @@ public class CompareValueWithClipboardAction extends BaseValueAction { return DebuggerBundle.message("diff.clipboard.vs.value.dialog.title"); } + @Nullable private static DiffContent createClipboardContent() { Transferable content = CopyPasteManager.getInstance().getContents(); - String text = ""; - try { - text = (String) (content.getTransferData(DataFlavor.stringFlavor)); + if (content != null) { + try { + String text = (String) (content.getTransferData(DataFlavor.stringFlavor)); + return text != null ? new SimpleContent(text) : null; + } catch (Exception ignored) { } } - catch (Exception e) { - LOG.info(e); - } - return new SimpleContent(text); + return null; } } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java b/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java index 2918c5007409..04cdc5dcd564 100644 --- a/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java +++ b/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java @@ -48,6 +48,7 @@ public class FileListPasteProvider implements PasteProvider { if (project == null || ideView == null) return; final Transferable contents = CopyPasteManager.getInstance().getContents(); + if (contents == null) return; final List fileList = FileCopyPasteUtil.getFileList(contents); if (fileList == null) return; diff --git a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java index 9432d641d41d..96fe2949971e 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -131,7 +131,7 @@ public class EditorModificationUtil { @Nullable public static TextRange pasteFromClipboard(Editor editor) { - return pasteFromTransferrable(getClipboardContent(editor), editor); + return pasteFromTransferrable(CopyPasteManager.getInstance().getContents(), editor); } @Nullable @@ -165,19 +165,15 @@ public class EditorModificationUtil { return s; } - private static Transferable getClipboardContent(Editor editor) { - return CopyPasteManager.getInstance().getContents(); - } - public static void pasteFromClipboardAsBlock(Editor editor) { pasteTransferableAsBlock(editor, null); } public static void pasteTransferableAsBlock(Editor editor, @Nullable Transferable content) { if (content == null) { - content = getClipboardContent(editor); + content = CopyPasteManager.getInstance().getContents(); } - + if (content != null) { try { int caretLine = editor.getCaretModel().getLogicalPosition().line; diff --git a/platform/platform-api/src/com/intellij/openapi/ide/CopyPasteManager.java b/platform/platform-api/src/com/intellij/openapi/ide/CopyPasteManager.java index e5f5e8742374..24dc35739dc0 100644 --- a/platform/platform-api/src/com/intellij/openapi/ide/CopyPasteManager.java +++ b/platform/platform-api/src/com/intellij/openapi/ide/CopyPasteManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ public abstract class CopyPasteManager { public abstract boolean isDataFlavorAvailable(@NotNull DataFlavor flavor); + @Nullable public abstract Transferable getContents(); public abstract Transferable[] getAllContents(); diff --git a/platform/platform-impl/src/com/intellij/ide/CopyPasteManagerEx.java b/platform/platform-impl/src/com/intellij/ide/CopyPasteManagerEx.java index cddac678409e..3657a4a4cf31 100644 --- a/platform/platform-impl/src/com/intellij/ide/CopyPasteManagerEx.java +++ b/platform/platform-impl/src/com/intellij/ide/CopyPasteManagerEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -220,7 +220,6 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn } } - @Nullable public Transferable getContents() { return myClipboardSynchronizer.getContents(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareClipboardWithSelection.java b/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareClipboardWithSelection.java index 19c558da157c..57c2cbae7bbf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareClipboardWithSelection.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareClipboardWithSelection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,11 +75,11 @@ public class CompareClipboardWithSelection extends BaseDiffAction { SelectionModel selectionModel = myEditor.getSelectionModel(); if (selectionModel.hasSelection()) { TextRange range = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); - myContents[1] = new FragmentContent(DocumentContent.fromDocument(getProject(), getDocument()), + myContents[1] = new FragmentContent(DiffContent.fromDocument(getProject(), getDocument()), range, getProject(), getDocumentFile(getDocument())); } else { - myContents [1] = DocumentContent.fromDocument(getProject(), getDocument()); + myContents [1] = DiffContent.fromDocument(getProject(), getDocument()); } return myContents; } @@ -96,15 +96,16 @@ public class CompareClipboardWithSelection extends BaseDiffAction { } } + @Nullable private static DiffContent createClipboardContent() { Transferable content = CopyPasteManager.getInstance().getContents(); - String text; - try { - text = (String) (content.getTransferData(DataFlavor.stringFlavor)); - } catch (Exception e) { - return null; + if (content != null) { + try { + String text = (String) (content.getTransferData(DataFlavor.stringFlavor)); + return text != null ? new SimpleContent(text) : null; + } catch (Exception ignored) { } } - return text != null ? new SimpleContent(text) : null; + return null; } } } diff --git a/platform/platform-impl/testSrc/com/intellij/openapi/editor/actions/KillRegionActionTest.java b/platform/platform-impl/testSrc/com/intellij/openapi/editor/actions/KillRegionActionTest.java index 27b0c0bc5802..bf5318c829c1 100644 --- a/platform/platform-impl/testSrc/com/intellij/openapi/editor/actions/KillRegionActionTest.java +++ b/platform/platform-impl/testSrc/com/intellij/openapi/editor/actions/KillRegionActionTest.java @@ -39,6 +39,7 @@ public class KillRegionActionTest extends AbstractRegionToKillRingTest { killRegion(); if (parseResult.first != null) { Transferable contents = CopyPasteManager.getInstance().getContents(); + assertNotNull(contents); assertEquals(parseResult.first, contents.getTransferData(DataFlavor.stringFlavor)); } diff --git a/platform/platform-impl/testSrc/com/intellij/openapi/editor/actions/KillRingSaveActionTest.java b/platform/platform-impl/testSrc/com/intellij/openapi/editor/actions/KillRingSaveActionTest.java index 7b1e61a13e57..ac6ced391743 100644 --- a/platform/platform-impl/testSrc/com/intellij/openapi/editor/actions/KillRingSaveActionTest.java +++ b/platform/platform-impl/testSrc/com/intellij/openapi/editor/actions/KillRingSaveActionTest.java @@ -43,6 +43,7 @@ public class KillRingSaveActionTest extends AbstractRegionToKillRingTest { } Transferable contents = CopyPasteManager.getInstance().getContents(); + assertNotNull(contents); assertEquals(parseResult.first, contents.getTransferData(DataFlavor.stringFlavor)); assertEquals(textBefore, myEditor.getDocument().getText()); }