|Switching binding context based on selection [message #1685533]
||Wed, 18 March 2015 22:14
| Colin Sharples
Registered: July 2009
Location: Wellington, New Zealand
I have a graphical editor in an e4 application, and I am trying to get key bindings working so that I can use key shortcuts to call actions on the selected object. There are several different types of object that are represented by different shapes, and these objects are backed by model objects in an inheritance tree. The actions that are available depend on the type of object selected, but I'd like to be able to use the same key shortcut with a different meaning depending on which type of object is selected.|
I have defined a different binding context for each of the object types, and associated all of those contexts to the editor view. In the controller where I handle object selection, I have an EContextService reference, which calls deactivateContext and activateContext to ensure that the relevant set of contexts are active.
However, this does not seem to be working.
Let's say I have three object types, Foo, Bar and Qux. Foo and Bar share a common superclass, FooBar, and FooBar and Qux share the superclass FooBarQux. I have five binding contexts relating to each of these classes.
Both Foo and Qux have the key binding CTRL+M (i.e. M1+M) in their binding context, but bound to different commands, "move.foo" and "move.qux" respectively, and each command has its own handler defined. The semantics of moving a Foo and moving a Qux are different, which is why they need to have different commands, even though to the user the CTRL+M command just means "move".
What I see in practice is that if I select a Qux object, the CTRL+M binding will correctly call the move.qux command, but if I then go and select a Foo object, and go back and select the Qux object again, now the CTRL+M binding only ever invokes the move.foo command.
I have debugged through my controller, and have confirmed that it does correctly call the EContextService to activate the correct contexts. It just seems that calling EContextService.deactivateService doesn't properly flush out the current bindings or something.
Is there something else I can do, or is it just a case of not being able to reuse the same key sequence in different contexts?
CTG Games Ltd
Wellington, New Zealand
Powered by FUDForum
. Page generated in 0.02127 seconds