问题描述
我需要在SWT中的文本控件的默认上下文菜单中添加一些项目,但是已经发现我无法修改此菜单并且必须从头开始创建一个新项目。
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?
推荐答案
StyledText
内置支持Cut,Copy&粘贴:
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);
至于撤销操作,我担心你必须自己实施。 SWT
这里没有任何有用的东西,AFAIK。如果您想自己动手,这是一个良好的开端:。
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.
这篇关于SWT:如何为文本字段重新创建默认上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!