开发者

swt: how to handle copy/paste operation?

开发者 https://www.devze.com 2022-12-16 22:11 出处:网络
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

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消