use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.
the class VcsLogGraphTable method performCopy.
@Override
public void performCopy(@NotNull DataContext dataContext) {
StringBuilder sb = new StringBuilder();
int[] selectedRows = getSelectedRows();
for (int i = 0; i < Math.min(VcsLogUtil.MAX_SELECTED_COMMITS, selectedRows.length); i++) {
int row = selectedRows[i];
for (int j = ROOT_COLUMN + 1; j < getModel().getColumnCount(); j++) {
sb.append(getModel().getValueAt(row, j).toString());
if (j < getModel().getRowCount() - 1)
sb.append(" ");
}
if (i != selectedRows.length - 1)
sb.append("\n");
}
CopyPasteManager.getInstance().setContents(new StringSelection(sb.toString()));
}
use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.
the class IdeGlassPaneImpl method preprocess.
private boolean preprocess(final MouseEvent e, final boolean motion, JRootPane eventRootPane) {
try {
if (UIUtil.getWindow(this) != UIUtil.getWindow(e.getComponent()))
return false;
final MouseEvent event = MouseEventAdapter.convert(e, eventRootPane);
if (event.isAltDown() && SwingUtilities.isLeftMouseButton(event) && event.getID() == MouseEvent.MOUSE_PRESSED) {
Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
Balloon balloon = JBPopupFactory.getInstance().getParentBalloonFor(c);
if (balloon instanceof BalloonImpl) {
JComponent component = ((BalloonImpl) balloon).getComponent();
component.getToolkit().getSystemClipboard().setContents(new StringSelection(UIUtil.getDebugText(component)), EmptyClipboardOwner.INSTANCE);
}
}
if (!IdeGlassPaneUtil.canBePreprocessed(e)) {
return false;
}
for (EventListener each : mySortedMouseListeners) {
if (motion && each instanceof MouseMotionListener) {
fireMouseMotion((MouseMotionListener) each, event);
} else if (!motion && each instanceof MouseListener) {
fireMouseEvent((MouseListener) each, event);
}
if (event.isConsumed()) {
e.consume();
return true;
}
}
return false;
} finally {
if (eventRootPane == myRootPane) {
Cursor cursor;
if (!myListener2Cursor.isEmpty()) {
cursor = myListener2Cursor.values().iterator().next();
final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myRootPane.getContentPane());
Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
if (canProcessCursorFor(target)) {
target = getCompWithCursor(target);
restoreLastComponent(target);
if (target != null) {
if (myLastCursorComponent != target) {
myLastCursorComponent = target;
myLastOriginalCursor = target.getCursor();
}
if (cursor != null && !cursor.equals(target.getCursor())) {
if (target instanceof JComponent) {
((JComponent) target).putClientProperty(PREPROCESSED_CURSOR_KEY, Boolean.TRUE);
}
target.setCursor(cursor);
}
}
getRootPane().setCursor(cursor);
}
} else if (!e.isConsumed() && e.getID() != MouseEvent.MOUSE_DRAGGED) {
cursor = Cursor.getDefaultCursor();
JRootPane rootPane = getRootPane();
if (rootPane != null) {
rootPane.setCursor(cursor);
} else {
LOG.warn("Root pane is null. Event: " + e);
}
restoreLastComponent(null);
myLastOriginalCursor = null;
myLastCursorComponent = null;
}
myListener2Cursor.clear();
}
}
}
use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.
the class FocusTracesDialog method getCopyStackTraceAction.
private Action getCopyStackTraceAction() {
return new AbstractAction("&Copy stacktrace") {
@Override
public void actionPerformed(ActionEvent e) {
String text = ExceptionUtil.getThrowableText(myRequests.get(myRequestsTable.getSelectedRow()).trace);
CopyPasteManager.getInstance().setContents(new StringSelection(text));
}
};
}
use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.
the class MultiplePasteAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
Project project = CommonDataKeys.PROJECT.getData(dataContext);
Component focusedComponent = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
if (!(focusedComponent instanceof JComponent))
return;
final CopyPasteManagerEx copyPasteManager = CopyPasteManagerEx.getInstanceEx();
final ContentChooser<Transferable> chooser = new ContentChooser<Transferable>(project, UIBundle.message("choose.content.to.paste.dialog.title"), true, true) {
@Override
protected String getStringRepresentationFor(final Transferable content) {
try {
return (String) content.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException | IOException e1) {
return "";
}
}
@Override
protected List<Transferable> getContents() {
return Arrays.asList(CopyPasteManager.getInstance().getAllContents());
}
@Override
protected void removeContentAt(final Transferable content) {
copyPasteManager.removeContent(content);
}
};
if (!chooser.getAllContents().isEmpty()) {
chooser.show();
} else {
chooser.close(DialogWrapper.CANCEL_EXIT_CODE);
}
if (chooser.isOK()) {
List<Transferable> selectedContents = chooser.getSelectedContents();
if (selectedContents.size() == 1) {
copyPasteManager.moveContentToStackTop(selectedContents.get(0));
} else {
copyPasteManager.setContents(new StringSelection(chooser.getSelectedText()));
}
if (editor != null) {
if (editor.isViewer())
return;
final AnAction pasteAction = ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE);
AnActionEvent newEvent = new AnActionEvent(e.getInputEvent(), DataManager.getInstance().getDataContext(focusedComponent), e.getPlace(), e.getPresentation(), ActionManager.getInstance(), e.getModifiers());
pasteAction.actionPerformed(newEvent);
} else {
final Action pasteAction = ((JComponent) focusedComponent).getActionMap().get(DefaultEditorKit.pasteAction);
if (pasteAction != null) {
pasteAction.actionPerformed(new ActionEvent(focusedComponent, ActionEvent.ACTION_PERFORMED, ""));
}
}
}
}
use of java.awt.datatransfer.StringSelection in project intellij-plugins by JetBrains.
the class DartProblemsViewPanel method performCopy.
@Override
public void performCopy(@NotNull DataContext dataContext) {
final List<DartProblem> selectedObjects = myTable.getSelectedObjects();
final String s = StringUtil.join(selectedObjects, problem -> problem.getSeverity().toLowerCase(Locale.US) + ": " + problem.getErrorMessage() + " (" + problem.getCode() + " at " + problem.getPresentableLocation() + ")", "\n");
if (!s.isEmpty()) {
CopyPasteManager.getInstance().setContents(new StringSelection(s));
}
}
Aggregations