Enabling Handlers for copy/cut/paste commands [message #327941] |
Fri, 09 May 2008 00:20 |
Alex Smirnoff Messages: 28 Registered: July 2009 |
Junior Member |
|
|
I have a simple scenario: In form editor and form view I want each text
widget map to copy/cut/paste command.
I tried TextActionHandler (programmatic approach). It works only for
editors and doesn't work for views (maybe I do something wrong here, but I
tried different scenarios).
If I use WidgetMethodHandler it only works to execute copy/cut/paste
methods but it is *always* enabled. My goal is to enable handler when it
is possible to execute corresponding command. Here isEnabled method which
I changed to allow this:
public boolean isEnabled() {
if (methodName.equals("paste")){
Clipboard cb = new Clipboard(Display.getCurrent());
TextTransfer transfer = TextTransfer.getInstance();
if (cb.getContents(transfer) != null){
return true;
}
} else if (methodName.equals("copy") || methodName.equals("cut")){
Control focusControl = Display.getCurrent().getFocusControl();
if (focusControl != null && focusControl instanceof Text) {
Text text = (Text)focusControl;
String selection = text.getSelectionText();
if (selection != null && !selection.equals("")){
return true;
}
}
}
return false;
}
This works great, but only for focus in/out events (I track my Text
widgets with IFocusService). When I do selections, it does not enables the
handler. I have feeling that focus service is not a good choice for my
requirements.
So is there an elegant way that will allow me to validate handler not only
on focus change, but also on text selections events?
Thanks,
Alex.
|
|
|
Powered by
FUDForum. Page generated in 0.02834 seconds