Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » [SOLVED] Key Binding only works when menu visible?
[SOLVED] Key Binding only works when menu visible? [message #988232] Thu, 29 November 2012 02:44 Go to next message
Jim Klo is currently offline Jim KloFriend
Messages: 49
Registered: September 2012
Member
Hi,

I've got a multi-plugin rcp project that builds upon a custom editor.

Plugin 1: Editor
Plugin 2: Query Viewer + Query Command

I want to be able to add a key binding to execute the query command when after a selection is made in the editor.

Right now I have a popup menu that contains the command to execute (with a key binding visible). The key binding only seems to work when the popup is open and visible! How can I enable my command so that all I need to do is select text, and press the key binding?

Here is the relevant snippets from Plugin 2's plugin.xml:

<extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="com.sri.rave.flora.query.command.execute_query"
            contextId="org.eclipse.ui.textEditorScope"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="M1+y">
      </key>
   </extension>
   <extension
         point="org.eclipse.ui.commands">
      <command
            defaultHandler="com.sri.rave.flora.query.commands.ExecuteQueryCommand"
            id="com.sri.rave.flora.query.command.execute_query"
            name="Execute Query">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="true"
            locationURI="popup:#TextEditorContext?after=additions">
         <command
               commandId="com.sri.rave.flora.query.command.execute_query"
               icon="icons/query.png"
               label="Execute Query"
               style="push">
         </command>
      </menuContribution>
      <menuContribution
            allPopups="false"
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="net.sourceforge.flora.eclipse.menu"
               label="Flora">
            <command
                  commandId="com.sri.rave.flora.query.command.execute_query"
                  icon="icons/query.png"
                  label="Execute Query"
                  style="push">
            </command>
         </menu>
      </menuContribution>
   </extension>



Thanks,

- Jim

[Updated on: Fri, 30 November 2012 17:53]

Report message to a moderator

Re: Key Binding only works when menu visible? [message #988564 is a reply to message #988232] Fri, 30 November 2012 14:20 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi,

I'm not familiar with contexts, but

  1. Are you sure you have defined a handler for that command and that handler is active?
  2. Are you sure the org.eclipse.ui.textEditorScope is active when you press the key sequence?

[Updated on: Fri, 30 November 2012 14:21]

Report message to a moderator

[SOLVED] Key Binding only works when menu visible? [message #988625 is a reply to message #988564] Fri, 30 November 2012 17:52 Go to previous message
Jim Klo is currently offline Jim KloFriend
Messages: 49
Registered: September 2012
Member
So:

1. It's relying upon the defaultHandler in the command declaration below.

    <extension
         point="org.eclipse.ui.commands">
      <command
            defaultHandler="com.sri.rave.flora.query.commands.ExecuteQueryCommand"
            id="com.sri.rave.flora.query.command.execute_query"
            name="Execute Query">
      </command>
   </extension>


2. I don't think contexts had any impact here, as regardless of what I set it to (whether it be the default org.eclipse.ui.window or one that I create), I still had the same behavior. Key binding works in visible menu, and nowhere else.

That said I believe I found the problem, since I got it working - sadly it is because of the VERY POORLY WRITTEN DOCUMENTATION FOR BINDINGS!!! It's not that te information isn't there, it's just so wordy that requirements aren't explicit and clear, thus it's easy to miss little details.

Within this block the only thing I change?
   <extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="com.sri.rave.flora.query.command.execute_query"
            contextId="org.eclipse.ui.textEditorScope"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="M1+y">
      </key>
   </extension>


sequence="M1+y"
should have been
 sequence="M1+Y"


I'm guessing that something in the handler within the menus deals with the lowercase version, but globally it only works if uppercase.

Note the documentation is extremely wordy - and I missed the one little mention about 'in uppercase', which is somewhat mentioned like an aside!

[Updated on: Fri, 30 November 2012 17:52]

Report message to a moderator

Previous Topic:how we add a plugin to a RCP project
Next Topic:Separate external jars from plugin
Goto Forum:
  


Current Time: Tue Apr 23 13:16:08 GMT 2024

Powered by FUDForum. Page generated in 0.03670 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top