use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.
the class BindingLookupTest method testLookupBestShortcut.
@Test
public void testLookupBestShortcut() {
ECommandService cs = workbenchContext.get(ECommandService.class);
ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null);
EBindingService bs = workbenchContext.get(EBindingService.class);
TriggerSequence seq2 = bs.createSequence("ALT+5 X");
Binding db2 = createDefaultBinding(bs, seq2, cmd, ID_DIALOG_AND_WINDOW);
bs.activateBinding(db2);
TriggerSequence seq = bs.createSequence("CTRL+5 T");
Binding db = createDefaultBinding(bs, seq, cmd, ID_DIALOG_AND_WINDOW);
bs.activateBinding(db);
TriggerSequence foundSequence = bs.getBestSequenceFor(cmd);
assertNotNull(foundSequence);
assertEquals(seq, foundSequence);
}
use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.
the class KeyController method loadModelBackend.
private static BindingManager loadModelBackend(IServiceLocator locator) {
IBindingService bindingService = locator.getService(IBindingService.class);
BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
try {
Scheme modelActiveScheme = null;
for (final Scheme scheme : definedSchemes) {
final Scheme copy = bindingManager.getScheme(scheme.getId());
copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
if (scheme.getId().equals(bindingService.getActiveScheme().getId())) {
modelActiveScheme = copy;
}
}
bindingManager.setActiveScheme(modelActiveScheme);
} catch (final NotDefinedException e) {
StatusManager.getManager().handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH, "Keys page found an undefined scheme", // $NON-NLS-1$
e));
}
bindingManager.setLocale(bindingService.getLocale());
bindingManager.setPlatform(bindingService.getPlatform());
Set<Binding> bindings = new HashSet<>();
EBindingService eBindingService = locator.getService(EBindingService.class);
bindings.addAll(eBindingService.getActiveBindings());
bindings.addAll(Arrays.asList(bindingService.getBindings()));
bindingManager.setBindings(bindings.toArray(new Binding[0]));
return bindingManager;
}
use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.
the class BindingPersistenceTest method testAboutBindingIn3x.
@Test
public void testAboutBindingIn3x() throws Exception {
if (Util.isMac()) {
// TODO investigate on Mac
return;
}
final Scheme activeScheme = bindingService.getActiveScheme();
ParameterizedCommand aboutCmd = new ParameterizedCommand(commandService.getCommand(IWorkbenchCommandConstants.HELP_ABOUT), null);
ParameterizedCommand activateEditorCmd = new ParameterizedCommand(commandService.getCommand(IWorkbenchCommandConstants.WINDOW_ACTIVATE_EDITOR), null);
final KeySequence keyF12 = Util.isMac() ? KeySequence.getInstance("M1+F12") : KeySequence.getInstance("F12");
final Binding editorBinding = bindingService.getPerfectMatch(keyF12);
assertNotNull(editorBinding);
assertEquals(activateEditorCmd, editorBinding.getParameterizedCommand());
EBindingService ebs = PlatformUI.getWorkbench().getService(EBindingService.class);
HashMap<String, String> attrs = new HashMap<>();
attrs.put(EBindingService.TYPE_ATTR_TAG, "user");
final Binding localAboutBinding = ebs.createBinding(keyF12, aboutCmd, IContextService.CONTEXT_ID_WINDOW, attrs);
assertEquals(Binding.USER, localAboutBinding.getType());
final Binding[] bindings = bindingService.getBindings();
Binding[] added = new Binding[bindings.length + 1];
System.arraycopy(bindings, 0, added, 0, bindings.length);
added[bindings.length] = localAboutBinding;
bindingService.savePreferences(activeScheme, added);
final Binding secondMatch = bindingService.getPerfectMatch(keyF12);
// fails
assertNotNull(secondMatch);
assertEquals(aboutCmd, secondMatch.getParameterizedCommand());
}
use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.
the class BindingPersistenceTest method testAboutBinding.
@Test
public void testAboutBinding() throws Exception {
if (Util.isMac()) {
return;
}
final Scheme activeScheme = bindingService.getActiveScheme();
final Binding[] originalBindings = bindingService.getBindings();
ParameterizedCommand aboutCmd = new ParameterizedCommand(commandService.getCommand(IWorkbenchCommandConstants.HELP_ABOUT), null);
ParameterizedCommand activateEditorCmd = new ParameterizedCommand(commandService.getCommand(IWorkbenchCommandConstants.WINDOW_ACTIVATE_EDITOR), null);
final KeySequence keyF12 = Util.isMac() ? KeySequence.getInstance("M1+F12") : KeySequence.getInstance("F12");
final KeySequence keyAltCtrlShiftI = KeySequence.getInstance("ALT+CTRL+SHIFT+I");
final Binding editorBinding = bindingService.getPerfectMatch(keyF12);
assertNotNull(editorBinding);
assertEquals(activateEditorCmd, editorBinding.getParameterizedCommand());
EBindingService ebs = PlatformUI.getWorkbench().getService(EBindingService.class);
HashMap<String, String> attrs = new HashMap<>();
attrs.put(EBindingService.TYPE_ATTR_TAG, "user");
final Binding localAboutBinding = ebs.createBinding(keyF12, aboutCmd, IContextService.CONTEXT_ID_WINDOW, attrs);
assertEquals(Binding.USER, localAboutBinding.getType());
// test unbinding a system binding and adding a user binding (same
// triggers and context)
final Binding[] bindings = originalBindings;
Binding[] added = new Binding[bindings.length + 2];
System.arraycopy(bindings, 0, added, 0, bindings.length);
Binding del = new KeyBinding(keyF12, null, IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID, IContextService.CONTEXT_ID_WINDOW, null, null, null, Binding.USER);
added[bindings.length] = del;
added[bindings.length + 1] = localAboutBinding;
bindingService.savePreferences(activeScheme, added);
// the match should be the user binding that we just added
final Binding secondMatch = bindingService.getPerfectMatch(keyF12);
assertNotNull(secondMatch);
assertEquals(aboutCmd, secondMatch.getParameterizedCommand());
// go back to the defaults
bindingService.savePreferences(activeScheme, originalBindings);
final Binding thirdMatch = bindingService.getPerfectMatch(keyF12);
assertNotNull(thirdMatch);
assertEquals(activateEditorCmd, thirdMatch.getParameterizedCommand());
// try assigning alt-ctrl-shift-i (no other binding uses this for this
// context) to the 'about' command
final Binding localAboutBinding1 = ebs.createBinding(keyAltCtrlShiftI, aboutCmd, IContextService.CONTEXT_ID_WINDOW, attrs);
assertEquals(Binding.USER, localAboutBinding1.getType());
Binding[] added1 = new Binding[bindings.length + 1];
System.arraycopy(bindings, 0, added1, 0, bindings.length);
added1[bindings.length] = localAboutBinding1;
bindingService.savePreferences(activeScheme, added1);
final Binding fourthMatch = bindingService.getPerfectMatch(keyAltCtrlShiftI);
assertNotNull(fourthMatch);
assertEquals(aboutCmd, fourthMatch.getParameterizedCommand());
}
use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.
the class GlobalKeyAssistDialog method getInfoText.
/**
* Determines what keybinding was used to open this dialog and returns an info
* string using that binding. ex: "Press 'Ctrl-Shift-L') to open the preference
* page";
*
* @return info text for this dialog
*/
private String getInfoText() {
ECommandService commandService = context.getActiveLeaf().get(ECommandService.class);
Command cmd = commandService.getCommand(IWorkbenchCommandConstants.WINDOW_SHOW_KEY_ASSIST);
if (cmd != null) {
EBindingService bindingService = context.getActiveLeaf().get(EBindingService.class);
TriggerSequence keySeq = bindingService.getBestSequenceFor(new ParameterizedCommand(cmd, null));
if (keySeq != null) {
return NLS.bind(KeyAssistMessages.openPreferencePage, keySeq.format());
}
}
// $NON-NLS-1$
return "";
}
Aggregations