From 249c9d21b945d0d2a62adfee23f280f012dd9220 Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 14 Mar 2011 21:17:44 +0100 Subject: [PATCH] copy from tests view (IDEA-65048 ) --- .../ide/actions/CopyReferenceAction.java | 2 +- .../execution/testframework/TestTreeView.java | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/actions/CopyReferenceAction.java b/platform/lang-impl/src/com/intellij/ide/actions/CopyReferenceAction.java index f2baa175ae5b..a46e3546de9f 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/CopyReferenceAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/CopyReferenceAction.java @@ -166,7 +166,7 @@ public class CopyReferenceAction extends AnAction { } @Nullable - private static String elementToFqn(final PsiElement element) { + public static String elementToFqn(final PsiElement element) { for(QualifiedNameProvider provider: Extensions.getExtensions(QualifiedNameProvider.EP_NAME)) { String result = provider.getQualifiedName(element); if (result != null) return result; diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java b/platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java index 66b7bb3e4b4a..d9a7bcaa345e 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java @@ -21,15 +21,20 @@ package com.intellij.execution.testframework; import com.intellij.execution.testframework.actions.ViewAssertEqualsDiffAction; +import com.intellij.ide.CopyProvider; +import com.intellij.ide.actions.CopyReferenceAction; import com.intellij.openapi.Disposable; -import com.intellij.openapi.actionSystem.ActionPlaces; -import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiNamedElement; import com.intellij.ui.PopupHandler; import com.intellij.ui.TreeSpeedSearch; import com.intellij.ui.treeStructure.Tree; import com.intellij.util.EditSourceOnDoubleClickHandler; +import com.intellij.util.Function; import com.intellij.util.containers.Convertor; import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NotNull; @@ -37,8 +42,9 @@ import org.jetbrains.annotations.Nullable; import javax.swing.plaf.TreeUI; import javax.swing.tree.*; +import java.awt.datatransfer.StringSelection; -public abstract class TestTreeView extends Tree implements DataProvider { +public abstract class TestTreeView extends Tree implements DataProvider, CopyProvider { private TestFrameworkRunningModel myModel; protected abstract TreeCellRenderer getRenderer(TestConsoleProperties properties); @@ -75,6 +81,9 @@ public abstract class TestTreeView extends Tree implements DataProvider { } public Object getData(final String dataId) { + if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) { + return this; + } final TreePath selectionPath = getSelectionPath(); if (selectionPath == null) return null; final AbstractTestProxy testProxy = getSelectedTest(selectionPath); @@ -82,6 +91,22 @@ public abstract class TestTreeView extends Tree implements DataProvider { return TestsUIUtil.getData(testProxy, dataId, myModel); } + @Override + public void performCopy(DataContext dataContext) { + final PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataContext); + CopyPasteManager.getInstance().setContents(new StringSelection(CopyReferenceAction.elementToFqn(element))); + } + + @Override + public boolean isCopyEnabled(DataContext dataContext) { + return LangDataKeys.PSI_ELEMENT.getData(dataContext) != null; + } + + @Override + public boolean isCopyVisible(DataContext dataContext) { + return true; + } + protected void installHandlers() { EditSourceOnDoubleClickHandler.install(this); new TreeSpeedSearch(this, new Convertor() {