tags:

views:

172

answers:

2

Hi

I'm using SWT Text component. Do someone know how can I handle copy/paste operation and modify data when copying to the buffer and when copying from the buffer? I don't want just handle Ctrl-C Ctrl-V because there are a lot of other keys to do that thing (Shift-Del/Shift-Insert) and even user can override these keys.

Thanks

A: 

The package you should look at is: import org.eclipse.swt.dnd.*

Simple example:

Clipboard clipboard = new Clipboard(parent.getDisplay());
            String data = sb.toString();
            clipboard.setContents(new Object[] { data }, new Transfer[] {    TextTransfer.getInstance() });
            clipboard.dispose();
nanda
I think the original question is about how to override the copy/paste behaviour, and not about what to do in handling code.
Vladimir
A: 

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

Don't forget to override checkSubclass method.

Vladimir