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 h开发者_JS百科andle 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
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.
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();
精彩评论