GWT: context menu in RichTextArea
I'm using a RichTextArea in a GWT app. I want to add a context menu to my RichTextArea:
public class MyRichTextArea extends RichTextArea implements HasContextMenuHandlers {
public HandlerRegistration addContextMenuHandler(ContextMenuHandler h) {
return addDomHandler(h, ContextMenuEvent.getType());
}
}
(...)
myRichTextArea.addContextMenuHandler(new ContextMenuHandler() {
public void onContextMenu(ContextMenuEvent event) {
contextMenu.show();
}
});
This works, however, the context menu only appears when I right-click on the border of the Ric开发者_如何转开发hTextArea. If I right-click into the RichTextArea, e.g. on the contained text, the browser's default context menu is shown.
How can I display my own context menu?
Prevent default context memu:
myRichTextArea.addDomHandler(new ContextMenuHandler() {
@Override public void onContextMenu(ContextMenuEvent event) {
event.preventDefault();
event.stopPropagation();
// do what you want to do instead
}
}, ContextMenuEvent.getType());
I would go after a method that tells you that the rich text area has the focus, like hasfocus, or maybe better, an event listener (addFocusListener) to tell you when the focus is there on a mouse click for the right mouse button?
Does that make sense?
精彩评论