Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Add command handler to a control
Add command handler to a control [message #330945] Mon, 18 August 2008 21:08 Go to next message
Eclipse UserFriend
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 #330953 is a reply to message #330945] Tue, 19 August 2008 13:45 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Add command handler to a control [message #330961 is a reply to message #330953] Tue, 19 August 2008 15:21 Go to previous message
Eclipse UserFriend
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
Previous Topic:Question about copy/paste behaviour on Linux
Next Topic:NullPointer exceptions in plug-in: "org.eclipse.ui.workbench"!?!
Goto Forum:
  


Current Time: Tue Nov 12 06:52:59 GMT 2024

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

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

Back to the top