| Turning on key bindings in an editor [message #334025] | 
Thu, 15 January 2009 20:48   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
(The following is happening in an RCP environment, but I doubt that RCP  
has anything to do with it.) 
 
In org.eclipse.ui.bindings, I've got a schema and a key. 
 
I've got a command. 
 
In my editor, I make the recommend call to activate my scheme. 
 
My command is not called. My editor returns false to isEditable(), in case  
that matters. Can anyone suggest a debugging strategy? 
 
<extension 
         point="org.eclipse.ui.bindings"> 
      <scheme 
            id="com.basistech.rex2009.annote.scheme" 
            name="Annotation Key Binding Scheme"> 
      </scheme> 
      <key 
            commandId="com.basistech.rex2009.annotate.clear" 
            contextId="com.basistech.rex2009.annote" 
            schemeId="com.basistech.rex2009.annote.scheme" 
            sequence="CTRL+;"> 
      </key> 
</extension> 
 <extension 
         point="org.eclipse.ui.contexts"> 
      <context 
            id="com.basistech.rex2009.annote" 
            name="Annotation" 
            parentId="org.eclipse.ui.contexts.window"> 
      </context> 
   </extension> 
<extension 
         point="org.eclipse.ui.commands"> 
      <command 
             
defaultHandler="com.basistech.rex2009.annote.ClearAnnotationHandler " 
            id="com.basistech.rex2009.annotate.clear" 
            name="Clear Annotation"> 
      </command> 
   </extension>
 |  
 |  
  | 
 | 
 | 
| Re: Turning on key bindings in an editor [message #334082 is a reply to message #334065] | 
Mon, 19 January 2009 13:15   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
> Now I need to dynamically create bindings. 
 
What are you trying to do (i.e. what behaviour do you expect your users  
to see)?  Normally, an RCP app can include the keys preference page and  
allow users to change their keybindings (without having to code it  
yourself).  Changing keybindings is an expensive operation, and the API  
is set up specifically to prevent people from using keybindings to  
activate and de-activate commands. 
 
> I can either play games  
> surrounding the IBindingService, or I can fake out the preferences, or I  
> can precreate all the possible bindings and then fiddle with handlers to  
> turn them on and off, but I can't seem to just make a call to create a  
> binding. 
 
That's because the cost to fiddle around with bindings is much greater  
than the cost to update commands with different handlers based on the  
currently executing context (and that is what is designed into the system). 
 
If you need to provide functionality like a keys preference page (and  
can't include the preference page itself) then you need to code it like  
the keys preference page (make changes to a local binding manager and  
then save the bindings to the preference store).  That's supported and  
mostly API. 
 
If you need to activate different behaviour for CTRL+8 depending on if  
you are in an editor or a view, that's done by using  
org.eclipse.ui.contexts and attaching different commands to those keys  
in different contexts. 
 
If you need the behaviour of a command to change depending on if you are  
in an editor or a view (like copy in an editor gives text but copy in  
the project explorer gives an IResource) the you use one keybinding, one  
command, and multiple handlers. 
 
Schemes are designed to never change.  Context are designed to allow  
different sets of keybindings to be swapped in depending on a major  
change, like switching to a different view or editor.  Handlers are  
designed to be swapped in depending on the executing context. 
 
PW 
 
--  
Paul Webster 
http://wiki.eclipse.org/Platform_Command_Framework 
http://wiki.eclipse.org/Command_Core_Expressions 
http://wiki.eclipse.org/Menu_Contributions 
http://wiki.eclipse.org/Menus_Extension_Mapping 
 http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.03740 seconds