How to remove/replace the default key binding scheme [message #333038] |
Fri, 21 November 2008 05: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 #333133 is a reply to message #333098] |
Wed, 26 November 2008 13: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 14: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.02612 seconds