| 
| Solution or Workaround: keybinding in viewer's popup menu [message #281243] | Thu, 17 February 2005 06:06 |  | 
| Eclipse User  |  |  |  |  | I read a lot about problems with keybindings and yesterday I also got into trouble.
 
 1. Goal: A popup menu in a view which is also accessible by an accelerator.
 
 2. plugin.xml Configuration (only the important parts):
 
 <extension
 point="org.eclipse.ui.popupMenus">
 <viewerContribution
 targetID="com.camline.so.rcp.genview.Dispatch"
 id="com.camline.so.rcp.genview.Dispatch.actions">
 <action
 enablesFor="1"
 label="%soReserve"
 definitionId="com.camline.so.client.reserve"
 class="com.camline.so.rcp.actions.ReserveAction"
 tooltip="%soReserveTooltip"
 menubarPath="entryActions"
 id="com.camline.so.rcp.actions.ReserveAction"/>
 </viewerContribution>
 ...
 </extension>
 <extension
 point="org.eclipse.ui.commands">
 <category
 description="Command for a button bar"
 name="com.camline.so.client.ButtonBar"
 id="com.camline.so.client.buttonBar"/>
 <command
 category="com.camline.so.client.buttonBar"
 description="Reserve"
 categoryId="com.camline.so.client.buttonBar"
 name="%soReserve"
 id="com.camline.so.client.reserve"/>
 <keyBinding
 string="Ctrl+r"
 scope="org.eclipse.ui.globalScope"
 command="com.camline.so.client.reserve"
 configuration="org.eclipse.ui.defaultAcceleratorConfiguration ">
 </keyBinding>
 </extension>
 
 
 3. Result:
 
 The popup menu appears correctly, the action is accessible by mouse and
 the corresponding menu item shows "Reserve Ctrl+R" correctly.
 
 Accessing the action using the Ctrl+R shortcut does not work. The trace
 says
 
 KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+R])
 KEYS >>> WorkbenchKeyboard.executeCommand(commandId =
 'com.camline.so.client.reserve')
 KEYS >>>     not handled
 
 
 4. Solution or workaround
 
 I added the following lines in my ReserveAction class, which implements
 IViewActionDelegate.
 
 public void selectionChanged(IAction action, ISelection _selection) {
 this.selection = (IStructuredSelection) _selection;
 if (action.isEnabled())
 view.getSite().getKeyBindingService().registerAction(action) ;
 else
 view.getSite().getKeyBindingService().unregisterAction(actio n);
 }
 }
 
 Now everything works as expected.
 
 5. Final question
 
 I would have expected, that this works automatically. So the following
 questions go to the Eclipse wizards out there:
 
 - Is this the correct solution to the problem?
 - Is this a workaround needed because I made something wrong in plugin.xml
 configuration?
 - Is this a workaround for an Eclipse bug or a missing feature?
 
 
 Many thanks in advance.
 
 Best Regards,
 
 Matze
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.57712 seconds