Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Turning on key bindings in an editor
Turning on key bindings in an editor [message #334025] Fri, 16 January 2009 01:48 Go to next message
benson margulies is currently offline benson marguliesFriend
Messages: 5
Registered: July 2009
Junior Member
(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 #334056 is a reply to message #334025] Fri, 16 January 2009 18:13 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

benson margulies wrote:
> (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.

You mean activate your context.

A Scheme is an over-arching set of keybindings. i.e. most RCP apps will
create and use one and only one scheme.

You can activate your keybinding by activating your context (which it
seems you've done) ... assuming your keybinding is in the current active
scheme. Your definitions all look correct.

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


Re: Turning on key bindings in an editor [message #334065 is a reply to message #334056] Sat, 17 January 2009 14:04 Go to previous messageGo to next message
benson margulies is currently offline benson marguliesFriend
Messages: 5
Registered: July 2009
Junior Member
Here's what I've learned. There is no API to change the current scheme
except by horsing around with preferences.

I expected to find some sort of WorkbenchAdvisor.getDefaultSchemeId(), but
no such luck. BindingService goes directly to the prefs.

IBindingService is entirely read-only. BindingService is in an internal
package and final.

Since I have an RCP app, I gave up and put my bindings in the default
scheme, and all works.

Now I need to dynamically create bindings. 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.
Re: Turning on key bindings in an editor [message #334082 is a reply to message #334065] Mon, 19 January 2009 18:15 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

> 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


Previous Topic:Custom ISelectionProvider and checkEnabled for Visibility of commands does not work properly
Next Topic:[PDE Build] Feature builds question
Goto Forum:
  


Current Time: Wed Nov 06 21:59:42 GMT 2024

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

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

Back to the top