Contribute both a command Id plus an action implementation to another plugin. [message #324039] |
Wed, 16 January 2008 18:53  |
Eclipse User |
|
|
|
My plugin wants to contribute a key bindable action/handler to, for example,
the Navigator view. There doesn't seem to be a way to do this. I am able to
contribute menu items and toolbar buttons to editors and views from other
plugins using the actionSets extension. But I can't find any way to simply
make a contributed action available for binding to a key.
My plugin defines various new command Ids in this way,
<extension
point="org.eclipse.ui.commands">
<category
name="%Category.Navigate.name"
description="%Category.Navigate.description"
id="com.ui.category.navigate">
</category>
<command
id="com.ui.menu.navigate.visit"
name="%Button.visit.name"
description="%Button.visit.tooltip"
categoryId="com.ui.category.navigate">
</command>
</extension>
These allow the user to go into Window>Preferences, the Editor>Key page, and
to assign one of these command Ids to a key. If the user marks the key as
being used "In Windows" then Eclipse will attempt to locate an action handler
for the Id every time that key is pressed in any window, including for example
in the Navigator view.
And using actionSets I can define actions for my own editors and views like this,
<action
id="com.ui.menu.navigate.visit"
definitionId="com.ui.menu.navigate.visit"
label="%Button.visit.label"
tooltip="%Button.visit.tooltip"
class="com.action.delegate.navigate.Button_visit"
menubarPath="navigate/open.ext2"
style="push">
</action>
I am then able add a handler for these Ids in editors and views in my plugin
by adding code to each of the editors and views individually. The code
activates the handlers when the editor or view becomes active.
However I can't find any way to add a command Id handler for an editor or view
where I don't control the source code.
I know that the command Ids are being defined and properly bound, and I know
that Eclipse is looking for a handler when the keys are pressed, I have a
CommandManager.ExecutionListener set up in my plugin that is notified whenever
Eclipse went looking for a handler but didn't find one or didn't find one that
was enabled. In this case it isn't finding one (handler field in the
ParameterizedCommand is null). What I don't know is how to tell Eclipse what
action (or class or whatever) to use when the active workspace part doesn't
itself have a hard coded handler for a particular command Id.
I suppose I could put a hack into my ExecutionListener but that seems an
awkward way to do something that must have come up before.
Gary
|
|
|
|
|
Re: Contribute both a command Id plus an action implementation to another plugin. [message #324296 is a reply to message #324277] |
Tue, 22 January 2008 09:16   |
Eclipse User |
|
|
|
Gary E. Barnes wrote:
>
> I'm using 3.2. There doesn't appear to be a HandlerUtil in 3.2. So I'm
> doing,
OK, in 3.2 you're using the best code, although you can actually use
ISources.ACTIVE_PART_NAME instead of the string literal.
>> You can also simply supply a default handler in your command
>> definition (but you can only supply one).
>
> Does that work in 3.2? It is documented in the 3.2 Help files but if I
> specify a default handler it never gets invoked. Never even gets
> constructed (I put a breakpoint in the constructor).
It should work, but maybe that's a bug in 3.2 ... a number of bugs with
commands, handlers, and menus were fixed in 3.3, and even more in 3.4M4
(M5 will be coming out in 3 weeks or so).
> With the activeWhen commented out the handler is never invoked. With
> the activeWhen not commented out then the handler is invoked.
>
> Is there perhaps a way to specify an activeWhen expression that is
> simply a constant TRUE literal? Looking at the documentation there
> doesn't seem to be a way.
Your syntax looks correct, it must be a bug in 3.2. If you can write a
property tester in 3.2(depend on org.eclipse.core.expressions plugin)
that extends PropertyTester then you can just return TRUE all the time.
Later,
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04000 seconds