How to declare an Action to an existing Command? [message #318295] |
Wed, 25 July 2007 01:09  |
Eclipse User |
|
|
|
Hi,
I would like to know if there is a way for me to assign my own action to one
of the Commands provided by Eclipse.
I already have created my very own commands and actions, but on this way I'm
not using the same commands that Eclipse is using (I also had to give them a
different name).
However it sounds lame to have a command named "paste (my style)" being
assigned to my context.
It would look a lot better if I could just tell what Action should be
executed when the user "executes" the command (in this case paste).
However I have not yet found a description on how to connect to the Eclipse
provided commands (not new ones created by me), and I absolutely have not
found any data about the Eclipse provided commands (commandID and such).
Thanks,
Kristof
|
|
|
|
|
|
|
Re: How to declare an Action to an existing Command? [message #318568 is a reply to message #318482] |
Tue, 31 July 2007 19:51   |
Eclipse User |
|
|
|
Well, what I wound up doing was:
1) define my own command-id (say, "com.mun.ist.open")
2) set "com.mun.ist.open" as the "definitionId" of my plugged-in
context-menu's action
3) then in the part (as it happens, View), I wrote:
theStructuredViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
IHandlerService hs = (IHandlerService)
PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
try {
// although javadocs for this method claim one
// can pass any event, using the
// DoubleClickEvent will not compile:
hs.executeCommand("com.mun.ist.open", null);
} catch (Exception e) {
// TODO keyser: handle somehow: rare
// handler-exceptions of various kinds
}
}});
4) =>, and, like magic, it works!
thanks,
Paul
|
|
|
Re: How to declare an Action to an existing Command? [message #318610 is a reply to message #318568] |
Wed, 01 August 2007 08:35  |
Eclipse User |
|
|
|
And that looks exactly like it is meant to be used :-)
Paul Th. Keyser wrote:
> IHandlerService hs = (IHandlerService)
> PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
The only suggestion that I would make is use a closer IServiceLocator
than the workbench:
IHandlerService hs
= (IHandlerService) getSite().getService(IHandlerService.class);
since you are creating an anonymous inner class to your view.
Later,
PW
|
|
|
Powered by
FUDForum. Page generated in 0.04912 seconds