Swt: how to handle copy / paste operation?

I am using the SWT Text component. Does anyone know how I can handle a copy / paste operation and change data when copying to the clipboard and when copying from the clipboard? I don’t want to just handle Ctrl-C Ctrl-V, because there are many other keys for this (Shift-Del / Shift-Insert), and even the user can override these keys.

thank

+3
source share
2 answers

Create your own text component based on Text or StyledText and override copy () and paste (). It can do what you want.

Remember to override the checkSubclass method.

+3
source

Package you should pay attention to: import org.eclipse.swt.dnd. *

:

Clipboard clipboard = new Clipboard(parent.getDisplay());
            String data = sb.toString();
            clipboard.setContents(new Object[] { data }, new Transfer[] {    TextTransfer.getInstance() });
            clipboard.dispose();
-1

Source: https://habr.com/ru/post/1728908/


All Articles