Add command handler to a control [message #330945] |
Mon, 18 August 2008 21:08 |
Eclipse User |
|
|
|
Originally posted by: jamesblackburn.gmail.com
Hi All,
I asked this question in the swt group, but suspect it was off-topic for
there. I'm hoping someone can point me in the right direction...?
Basically I'm trying to improve a CDT custom control (which is actually
a simple class that wraps a List control) to add Cut / Copy / Paste
functionality.
The container class for the List is created with:
public FileListControl(Composite parent, String compTitle, int type)
When the class is created I would like to add a default handler for
these commands when the control has focus, and this shouldn't be
dependent on who's using the Control (at least I don't see why it should
be dependent on the IViewPart...).
Effectively i'm looking for the same behaviour that the Text Control
has. i.e. it doesn't involve me hard-coding a ctrl-x, ctrl-c, ctrl-v
key handler into the class -- it responds to the current key binding for
those commands.
Has anyone done this? Can you point me at any documentation? I've
google but nothing has come up :(.
Many thanks,
James
|
|
|
|
Re: Add command handler to a control [message #330961 is a reply to message #330953] |
Tue, 19 August 2008 15:21 |
Eclipse User |
|
|
|
Originally posted by: jamesblackburn+eclipse.mac.com
Paul Webster wrote:
> If you're a subclass of Control, you can implement cut(), copy(), and
> paste(). Eclipse's default handler for org.eclipse.ui.edit.copy, for
> example, calls controlInFocus.copy() if that method is available.
>
> Does that help?
Thanks a lot Paul for your reply. The wrapper doesn't extend Control
but extending the List locally did the trick :).
It's a bit hacky as I have to override the subclass check:
protected void checkSubclass() {
// Don't give an error here :s
}
but your solution seems to be an easy way (the only easy way?) to happiness.
The only thing doesn't work now is undo which doesn't appear to be
handled by default, but adding a handler did the trick:
<extension point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.ui.internal.handlers.WidgetMethodHandler:undo "
commandId="org.eclipse.ui.edit.undo">
</handler>
</extension>
Cheers again for the tip :)
James
|
|
|
Powered by
FUDForum. Page generated in 0.03066 seconds