Search in sources :

Example 6 with EBindingService

use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.

the class BindingLookupTest method testFindBinding.

@Test
public void testFindBinding() {
    ECommandService cs = workbenchContext.get(ECommandService.class);
    ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null);
    EBindingService bs = workbenchContext.get(EBindingService.class);
    TriggerSequence seq = bs.createSequence("CTRL+5 T");
    Binding db = createDefaultBinding(bs, seq, cmd, ID_DIALOG_AND_WINDOW);
    bs.activateBinding(db);
    Binding perfectMatch = bs.getPerfectMatch(seq);
    assertEquals(cmd, perfectMatch.getParameterizedCommand());
    bs.deactivateBinding(db);
    assertNull(bs.getPerfectMatch(seq));
    bs.activateBinding(db);
    assertEquals(cmd, bs.getPerfectMatch(seq).getParameterizedCommand());
}
Also used : Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) EBindingService(org.eclipse.e4.ui.bindings.EBindingService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Example 7 with EBindingService

use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.

the class BindingLookupTest method testLookupAllShortcutsWithChild.

@Test
public void testLookupAllShortcutsWithChild() {
    ECommandService cs = workbenchContext.get(ECommandService.class);
    ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null);
    EBindingService wBS = workbenchContext.get(EBindingService.class);
    TriggerSequence seq2 = wBS.createSequence("ALT+5 X");
    Binding db2 = createDefaultBinding(wBS, seq2, cmd, ID_DIALOG_AND_WINDOW);
    wBS.activateBinding(db2);
    IEclipseContext c1 = workbenchContext.createChild("c1");
    c1.activate();
    EContextService es = c1.get(EContextService.class);
    es.activateContext(ID_WINDOW);
    EBindingService bs1 = c1.get(EBindingService.class);
    TriggerSequence seq = bs1.createSequence("CTRL+5 T");
    Binding db = createDefaultBinding(wBS, seq, cmd, ID_WINDOW);
    bs1.activateBinding(db);
    // the list will always be ordered
    ArrayList<TriggerSequence> list = new ArrayList<>();
    list.add(seq);
    list.add(seq2);
    assertEquals(list, wBS.getSequencesFor(cmd));
}
Also used : Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) EBindingService(org.eclipse.e4.ui.bindings.EBindingService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ArrayList(java.util.ArrayList) EContextService(org.eclipse.e4.ui.services.EContextService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Example 8 with EBindingService

use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.

the class BindingLookupTest method testGetPartialMatches.

@Test
public void testGetPartialMatches() {
    ECommandService cs = workbenchContext.get(ECommandService.class);
    ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null);
    ParameterizedCommand cmd2 = cs.createCommand(TEST_ID2, null);
    EBindingService wBS = workbenchContext.get(EBindingService.class);
    TriggerSequence seq2 = wBS.createSequence("ALT+5 X");
    Binding wbBind = createDefaultBinding(wBS, seq2, cmd, ID_DIALOG_AND_WINDOW);
    wBS.activateBinding(wbBind);
    IEclipseContext c1 = workbenchContext.createChild("c1");
    c1.activate();
    EBindingService bs1 = c1.get(EBindingService.class);
    TriggerSequence seq = bs1.createSequence("CTRL+5 T");
    Binding b1 = createDefaultBinding(wBS, seq, cmd, ID_DIALOG_AND_WINDOW);
    bs1.activateBinding(b1);
    TriggerSequence sseq = bs1.createSequence("CTRL+5 Y");
    Binding b2 = createDefaultBinding(bs1, sseq, cmd2, ID_DIALOG_AND_WINDOW);
    bs1.activateBinding(b2);
    ArrayList<Binding> commandMatches = new ArrayList<>();
    commandMatches.add(b1);
    commandMatches.add(b2);
    TriggerSequence partialMatch = bs1.createSequence("CTRL+5");
    TriggerSequence partialNoMatch = bs1.createSequence("CTRL+8");
    assertFalse(bs1.isPartialMatch(partialNoMatch));
    assertTrue(bs1.isPartialMatch(partialMatch));
    Collection<Binding> matches = bs1.getPartialMatches(partialMatch);
    assertEquals(commandMatches, matches);
}
Also used : Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) EBindingService(org.eclipse.e4.ui.bindings.EBindingService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ArrayList(java.util.ArrayList) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Example 9 with EBindingService

use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.

the class BindingLookupTest method testLookupChildBinding.

@Test
public void testLookupChildBinding() {
    ECommandService cs = workbenchContext.get(ECommandService.class);
    ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null);
    IEclipseContext c1 = workbenchContext.createChild("c1");
    c1.activate();
    EBindingService bs1 = c1.get(EBindingService.class);
    TriggerSequence seq = bs1.createSequence("CTRL+5 T");
    Binding db = createDefaultBinding(bs1, seq, cmd, ID_DIALOG_AND_WINDOW);
    bs1.activateBinding(db);
    EBindingService wBS = workbenchContext.get(EBindingService.class);
    assertEquals(cmd, wBS.getPerfectMatch(seq).getParameterizedCommand());
    assertEquals(cmd, bs1.getPerfectMatch(seq).getParameterizedCommand());
    bs1.deactivateBinding(db);
    assertNull(wBS.getPerfectMatch(seq));
    assertNull(bs1.getPerfectMatch(seq));
}
Also used : Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) EBindingService(org.eclipse.e4.ui.bindings.EBindingService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Example 10 with EBindingService

use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.

the class BindingLookupTest method testLookupShortcutsTwoChildren.

@Test
public void testLookupShortcutsTwoChildren() {
    ECommandService cs = workbenchContext.get(ECommandService.class);
    ParameterizedCommand cmd1 = cs.createCommand(TEST_ID1, null);
    ParameterizedCommand cmd2 = cs.createCommand(TEST_ID2, null);
    EBindingService wBS = workbenchContext.get(EBindingService.class);
    TriggerSequence seq = wBS.createSequence("CTRL+5 T");
    IEclipseContext c1 = workbenchContext.createChild("c1");
    c1.activate();
    EContextService es = c1.get(EContextService.class);
    es.activateContext(ID_WINDOW);
    EBindingService bs1 = c1.get(EBindingService.class);
    Binding db = createDefaultBinding(bs1, seq, cmd1, ID_WINDOW);
    bs1.activateBinding(db);
    IEclipseContext c2 = workbenchContext.createChild("c2");
    EContextService es2 = c2.get(EContextService.class);
    es2.activateContext(ID_DIALOG);
    EBindingService bs2 = c2.get(EBindingService.class);
    Binding db2 = createDefaultBinding(bs2, seq, cmd2, ID_DIALOG);
    bs2.activateBinding(db2);
    assertEquals(seq, wBS.getBestSequenceFor(cmd1));
    assertNull(wBS.getBestSequenceFor(cmd2));
    assertEquals(seq, bs1.getBestSequenceFor(cmd1));
    assertNull(bs1.getBestSequenceFor(cmd2));
    assertEquals(seq, bs2.getBestSequenceFor(cmd2));
    assertNull(bs2.getBestSequenceFor(cmd1));
}
Also used : Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) EBindingService(org.eclipse.e4.ui.bindings.EBindingService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) EContextService(org.eclipse.e4.ui.services.EContextService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Aggregations

EBindingService (org.eclipse.e4.ui.bindings.EBindingService)24 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)23 Binding (org.eclipse.jface.bindings.Binding)21 TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)18 Test (org.junit.Test)18 ECommandService (org.eclipse.e4.core.commands.ECommandService)17 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)9 EContextService (org.eclipse.e4.ui.services.EContextService)5 Scheme (org.eclipse.jface.bindings.Scheme)4 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)4 KeySequence (org.eclipse.jface.bindings.keys.KeySequence)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)3 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 Category (org.eclipse.core.commands.Category)1 Command (org.eclipse.core.commands.Command)1 CommandManager (org.eclipse.core.commands.CommandManager)1 ContextManager (org.eclipse.core.commands.contexts.ContextManager)1