[SOLVED] Enable Keybinding only when menu visible [message #819952] |
Tue, 13 March 2012 14:40 |
Martin Missing name Messages: 10 Registered: March 2011 |
Junior Member |
|
|
Hi,
I have a rather simple goal, but I cannot figure out how to do this:
I want key bindings only be active when the menu is visible. The menu includes a special toolchain, which shall be reachable only when a certain editor type is open.
For that I have defined a menu contribution, which only gets visible, when the active editor is of a certain kind, done through core expression - works fine. That menu is attached to a command id, for which in turn I defined a key binding.
Now, when the menu is invisible (no such editor active), then the key binding is still active, which is bad. Defining a context for it should do it somehow, but the only thing I got to work was defining a context "org.example.my.ui.KeybindingScope" and by letting the Editor set the scope when opened:
protected void initializeKeyBindingScopes() {
setKeyBindingScopes(new String[] { "org.example.my.ui.KeybindingScope" });
System.out.println("Activating my key binding context ...");
}
Unfortunately the key binding is now only considered active when the editor is focussed, whereas the menu visibility is true as long as the editor is "opened" (which is the wanted behavior).
How do I set the key binding to be effective ONLY when the menu is visible, or better - only for that certain kind of editor?
plugin.xml:
<extension
point="org.eclipse.ui.commands">
<category
description="Delegates to a special toolchain"
id="org.example.my.builder.commands.category"
name="Esterel Category">
</category>
<command
categoryId="org.example.my.builder.commands.category"
description="Calls toolchain in mode 1"
id="org.example.my.builder.commands.buildMode1"
name="Build Mode 1...">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.example.my.builder.menues.HBuildMode1"
commandId="org.example.my.builder.commands.buildMode1">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="org.example.my.builder.commands.buildMode1"
contextId="org.example.my.ui.KeybindingScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="F7 F7">
</key>
</extension>
<extension
point="org.eclipse.ui.contexts">
<context
id="org.example.my.ui.KeybindingScope"
name="My Editor Opened">
</context>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
id="org.example.my.builder.ui.menus.sampleMenu"
label="My Toolchain"
mnemonic="T">
<command
commandId="org.example.my.builder.commands.buildMode1"
id="org.example.my.builder.ui.menus.buildMode1"
mnemonic="1">
</command>
<visibleWhen>
<reference
definitionId="onlyForMyEditor">
</reference>
</visibleWhen>
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="onlyForMyEditor">
<with variable="activeEditor">
<test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
value="org.example.my.My"/>
</with>
</definition>
</extension>
</plugin>
Thanks,
vbmazter
[Updated on: Tue, 20 March 2012 09:26] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03787 seconds