|
|
|
|
|
Re: Command and KeyBinding in "classic" window [message #463238 is a reply to message #463061] |
Wed, 07 February 2007 10:37 |
Nicolas Mura Messages: 24 Registered: July 2009 |
Junior Member |
|
|
Thanks, that works great with handlers, but i didn't manage to do the same with IAction.
If I replace :
handlerService.activateHandler("AATestSWT.command1", myHandler, new ActiveShellExpression(testDialog.getDialogShell()));
by :
TestAction2 a = new TestAction2(); //TestAction2 implements IAction
a.setActionDefinitionId("AATestSWT.command1");
Nothing appends when I use the key sequence of my command in my Shell.
I think this is because context of my shell is not active (there is no "ActiveShellExpression(*)" like with handler).
I haven't seen anything that deals with context in the IAction class.
Is it possible to use Command with Action in a "classic" window ?
I need IAction because, I need the same behavior on a button, a key binding and a menu item (popup menu)
and I seem that this is not possible with handler. (And Action have the setActive(*) method that is very useful to
disable binding,button and menu item at the same time)
[XML]
//////////////////////////////////////////////////////////// //////////////////////////////
<extension
point="org.eclipse.ui.commands">
<command
description="Test command"
id="AATestSWT.command1"
name="AATestSWT.command1"/>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="AATestSWT.command1"
contextId="org.eclipse.ui.contexts.dialog"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+A"/>
</extension>
//////////////////////////////////////////////////////////// //////////////////////////////
[XML]
[Code]
//////////////////////////////////////////////////////////// //////////////////////////////
IHandler myHandler = new org.eclipse.core.commands.AbstractHandler() {
public Object execute(ExecutionEvent event) throws ExecutionException{
System.out.println("This is MyHandler");
return event;
}
};
IContextService contextService = (IContextService)PlatformUI.getWorkbench()
.getService(IContextService.class);
contextService.registerShell(testDialog.getDialogShell(), IContextService.TYPE_DIALOG);
IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench()
.getService(IHandlerService.class);
TestAction2 a = new TestAction2();
a.setActionDefinitionId("AATestSWT.command1");
//handlerService.activateHandler("AATestSWT.command1", myHandler, new //ActiveShellExpression(testDialog.getDialogShell()));
//////////////////////////////////////////////////////////// //////////////////////////////
[Code]
Thanks,
Nicolas
|
|
|
|
|
Re: Command and KeyBinding in "classic" window [message #463334 is a reply to message #463288] |
Thu, 08 February 2007 15:07 |
|
Nicolas Mura wrote:
> Yes, but the setEnable(*) method of the action won't enable or disable
> the command (so the keybinding is still active/inactive).
Right ... the IAction is just appearance. It's your handler that has to
override isEnabled() to return true or false depending on its state. If
the active handler is disabled, so is the command.
> I think it would great to be able to link the a command to a button/menu
> item by code and be able to enable/disable the command that
> will enable/disable the keybinding and the linked widget.
That's coming in 3.3. Using org.eclipse.ui.menus and menuContribution,
a command placed in a menu or toolbar gets notified when the actual
command becomes enabled or disabled.
>
> So I have 2 possibilities:
> * I can add an "enable" property to my handler class but it less useful.
This is the new model. It's the active handler that determines if it is
enabled or not (and by extension, the command is enabled or not). What
you show on a button or menu item is just appearance, not state.
> * implement the IHandler interface in my Action class : so the
> isEnable(*) method work the action and for the Handler, but maybe there
> is another problem doing this that I don't know.
I'd be hesitant to do this, since you really don't want to mix up Action
and AbstractHandler (or IHandler) classes.
PW
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Powered by
FUDForum. Page generated in 0.04579 seconds