mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup. Use base class for copying text to clipboard
This commit is contained in:
@@ -25,7 +25,6 @@ import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.ide.CopyPasteManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
@@ -76,7 +75,6 @@ import javax.swing.plaf.TreeUI;
|
||||
import javax.swing.plaf.basic.BasicTreeUI;
|
||||
import javax.swing.tree.*;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
@@ -1474,8 +1472,9 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
|
||||
return myModel.areTargetsValid();
|
||||
}
|
||||
|
||||
private class MyPanel extends JPanel implements TypeSafeDataProvider, OccurenceNavigator,Disposable, CopyProvider {
|
||||
private class MyPanel extends JPanel implements TypeSafeDataProvider, OccurenceNavigator,Disposable{
|
||||
@Nullable private OccurenceNavigatorSupport mySupport;
|
||||
private CopyProvider myCopyProvider;
|
||||
|
||||
private MyPanel(@NotNull JTree tree) {
|
||||
mySupport = new OccurenceNavigatorSupport(tree) {
|
||||
@@ -1496,6 +1495,21 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
|
||||
return UsageViewBundle.message("action.previous.occurrence");
|
||||
}
|
||||
};
|
||||
myCopyProvider = new TextCopyProvider() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Collection<String> getTextLinesToCopy() {
|
||||
final Node[] selectedNodes = getSelectedNodes();
|
||||
if (selectedNodes != null && selectedNodes.length > 0) {
|
||||
ArrayList<String> lines = ContainerUtil.newArrayList();
|
||||
for (Node node : selectedNodes) {
|
||||
lines.add(node.getText(UsageViewImpl.this));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1533,24 +1547,6 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
|
||||
return mySupport != null ? mySupport.getPreviousOccurenceActionName() : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performCopy(@NotNull DataContext dataContext) {
|
||||
final Node selectedNode = getSelectedNode();
|
||||
assert selectedNode != null;
|
||||
final String plainText = selectedNode.getText(UsageViewImpl.this);
|
||||
CopyPasteManager.getInstance().setContents(new StringSelection(plainText.trim()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyEnabled(@NotNull DataContext dataContext) {
|
||||
return getSelectedNode() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyVisible(@NotNull DataContext dataContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calcData(final DataKey key, final DataSink sink) {
|
||||
Node node = getSelectedNode();
|
||||
@@ -1590,7 +1586,7 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
|
||||
sink.put(PlatformDataKeys.HELP_ID, HELP_ID);
|
||||
}
|
||||
else if (key == PlatformDataKeys.COPY_PROVIDER) {
|
||||
sink.put(PlatformDataKeys.COPY_PROVIDER, this);
|
||||
sink.put(PlatformDataKeys.COPY_PROVIDER, myCopyProvider);
|
||||
}
|
||||
else if (node != null) {
|
||||
Object userObject = node.getUserObject();
|
||||
|
||||
Reference in New Issue
Block a user