Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Enabling Handlers for copy/cut/paste commands
Enabling Handlers for copy/cut/paste commands [message #327941] Fri, 09 May 2008 00:20
Alex Smirnoff is currently offline Alex SmirnoffFriend
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.
Previous Topic:Providing contextual help in tooling
Next Topic:get the path of the openfile
Goto Forum:
  


Current Time: Thu Aug 29 23:24:09 GMT 2024

Powered by FUDForum. Page generated in 0.02901 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top