Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWT: How to recreate a default context menu for text fields

I need to add some items to the default context menu of a text control in SWT, but already found out I cannot modify this menu and have to create a new one from scratch.

But how do I emulate the default functions Undo, Cut, Copy, Paste, Delete? Do I really have to re-implement all this Clipboard stuff for myself? And I don't even know how to access the Undo history of the control. Is there some maybe dirty hack to emulate the key codes that achieve the functionality?

like image 892
Daniel Avatar asked Mar 19 '26 20:03

Daniel


1 Answers

The StyledText has built-in support for Cut, Copy & Paste:

StyledText editor = new StyledText(...);
editor.invokeAction(ST.CUT);
editor.invokeAction(ST.COPY);
editor.invokeAction(ST.PASTE);

As for the Undo operation, I'm afraid you'll have to implement it yourself. SWT doesn't have anything useful here, AFAIK. Here's a good start if you want to do it yourself: SWT Undo Redo.

like image 164
python dude Avatar answered Mar 22 '26 09:03

python dude