How to remove/replace the default key binding scheme [message #333038] |
Fri, 21 November 2008 10:14  |
Eclipse User |
|
|
|
Hi,
I hope that someone can help me? I would like to use the "Keys" preference
window in my Eclipse RCP application.
However, I don't want the default key bindings to appear in the list of
keys. Is there a way for me to remove the default scheme and only have my
own scheme appear in the "Scheme:" dropdown? Or better yet, can I remove the
default scheme and have my own scheme appear as the default scheme?
Thanks in advance,
Anders Baumann
|
|
|
|
|
Re: How to remove/replace the default key binding scheme [message #333094 is a reply to message #333089] |
Tue, 25 November 2008 16:50   |
Eclipse User |
|
|
|
I think it possible. I am struggling with the same issue but have put it
temporarily aside.
The reason I think it is possible is that NewKeysPreferencePage does it.
Press Shift-Ctrl-L twice and then unbind a command then press Shift-Ctrl-l
again, you will see that the command you unbound is not in the list.
So in theory it should be possible unbind any and or all the commands you
want.
Have a look at the code I posted, it is titled "Wwitch between Groups of
Key Bindings Dynamically", I reckon I am doing something silly wrong,
maybe later I will try and tackle this again.
|
|
|
|
Re: How to remove/replace the default key binding scheme [message #333133 is a reply to message #333098] |
Wed, 26 November 2008 18:11   |
Eclipse User |
|
|
|
Ok, I have a solution at least for my needs.
The solution below will filter all commands that are not in the category
mycategory, you can define the criteria as you need.
To test do Ctrl+Shift+L you should see only the commands you have not
filtered.
######################
IBindingService bindingService = (IBindingService) PlatformUI
getWorkbench().getAdapter(IBindingService.class);
BindingManager localChangeManager = new BindingManager(
new ContextManager(), new CommandManager());
try {
localChangeManager
.setActiveScheme(bindingService.getActiveScheme());
} catch (final NotDefinedException e) {
throw new Error(
"Error"); //$NON-NLS-1$
}
localChangeManager.setLocale(bindingService.getLocale());
localChangeManager.setPlatform(bindingService.getPlatform()) ;
localChangeManager.setBindings(bindingService.getBindings()) ;
Binding[] bindings = bindingService.getBindings();
for (Binding binding : bindings) {
if (binding.getTriggerSequence().format().equals("Ctrl+Shift+L ")) {
continue;
}
KeyBinding keyBinding = (KeyBinding) binding;
String contextId = binding.getContextId();
String schemeId = binding.getSchemeId();
KeySequence triggerSequence = keyBinding.getKeySequence();
ParameterizedCommand parameterizedCommand = binding
.getParameterizedCommand();
if (parameterizedCommand == null) {
continue;
}
Command command = parameterizedCommand.getCommand();
if (command == null) {
continue;
}
try {
if (!binding
getParameterizedCommand()
getCommand()
getCategory()
getId()
equals(
"mycategory")) {
KeyBinding deleteBinding = new KeyBinding(triggerSequence,
null, schemeId, contextId, null, null, null,
Binding.USER);
localChangeManager.addBinding(deleteBinding);
}
} catch (NotDefinedException e) {
e.printStackTrace();
}
}
try {
bindingService.savePreferences(
localChangeManager.getActiveScheme(), localChangeManager
.getBindings());
} catch (IOException e) {
e.printStackTrace();
}
|
|
|
|
Re: How to remove/replace the default key binding scheme [message #333141 is a reply to message #333135] |
Wed, 26 November 2008 19:12  |
Eclipse User |
|
|
|
Put this on top of your IApplication.start()
public Object start(IApplicationContext context) {
// set the default shortcuts
PlatformUI.getPreferenceStore().setDefault(IWorkbenchPrefere nceConstants.KEY_CONFIGURATION_ID,
"your.scheme"); //$NON-NLS-1$
// start your app
}
and you will have the default scheme set to your.
Cheers.
Laurent Marchal.
kent gibson wrote:
> does anyone know how I can get this to work without a dependency on
> org.eclipse.ui.ide?
|
|
|
Powered by
FUDForum. Page generated in 0.04687 seconds