コード例 #1
0
  public final void testBindingTransform() throws Exception {
    ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class);
    IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class);

    ParameterizedCommand addWS =
        new ParameterizedCommand(
            commandService.getCommand("org.eclipse.ui.navigate.addToWorkingSet"), null);
    KeySequence m18w = KeySequence.getInstance("M1+8 W");
    KeySequence m28w = KeySequence.getInstance("M2+8 W");
    boolean foundDeleteMarker = false;
    int numOfMarkers = 0;
    Binding[] bindings = bindingService.getBindings();
    for (int i = 0; i < bindings.length; i++) {
      final Binding binding = bindings[i];
      if (binding.getType() == Binding.SYSTEM) {
        String platform = binding.getPlatform();
        int idx = (platform == null ? -1 : platform.indexOf(','));
        assertEquals(binding.toString(), -1, idx);
        if (addWS.equals(binding.getParameterizedCommand())) {
          if (m18w.equals(binding.getTriggerSequence())) {
            numOfMarkers++;
            assertNull(m18w.format(), binding.getPlatform());
          } else if (m28w.equals(binding.getTriggerSequence())) {
            numOfMarkers++;
            assertTrue(
                platform,
                Util.WS_CARBON.equals(platform)
                    || Util.WS_COCOA.equals(platform)
                    || Util.WS_GTK.equals(platform)
                    || Util.WS_WIN32.equals(platform));
          }
        } else if (binding.getParameterizedCommand() == null
            && m18w.equals(binding.getTriggerSequence())) {
          assertTrue(
              platform,
              Util.WS_CARBON.equals(platform)
                  || Util.WS_COCOA.equals(platform)
                  || Util.WS_GTK.equals(platform)
                  || Util.WS_WIN32.equals(platform));
          numOfMarkers++;
          foundDeleteMarker = true;
        }
      }
    }
    assertEquals(3, numOfMarkers);
    assertTrue("Unable to find delete marker", foundDeleteMarker);
    TriggerSequence[] activeBindingsFor = bindingService.getActiveBindingsFor(addWS);
    assertEquals(1, activeBindingsFor.length);
  }
コード例 #2
0
  public final void testSinglePlatform() throws Exception {
    // Get the services.
    ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class);
    IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class);

    ParameterizedCommand about =
        new ParameterizedCommand(
            commandService.getCommand("org.eclipse.ui.help.aboutAction"), null);
    KeySequence m18A = KeySequence.getInstance("M1+8 A");
    KeySequence m18B = KeySequence.getInstance("M1+8 B");
    int numAboutBindings = 0;

    Binding[] bindings = bindingService.getBindings();
    for (int i = 0; i < bindings.length; i++) {
      final Binding binding = bindings[i];
      if (binding.getType() == Binding.SYSTEM) {
        String platform = binding.getPlatform();
        int idx = (platform == null ? -1 : platform.indexOf(','));
        assertEquals(binding.toString(), -1, idx);
        if (about.equals(binding.getParameterizedCommand())) {
          if (m18A.equals(binding.getTriggerSequence())) {
            numAboutBindings++;
            assertNull("M+8 A", binding.getPlatform());
          } else if (m18B.equals(binding.getTriggerSequence())) {
            numAboutBindings++;
            // assertEquals(Util.WS_CARBON, binding.getPlatform());
            // temp work around for honouring carbon bindings
            assertTrue(
                "failure for platform: " + binding.getPlatform(),
                Util.WS_CARBON.equals(binding.getPlatform())
                    || Util.WS_COCOA.equals(binding.getPlatform()));
          }
        }
      }
    }
    if (Util.WS_CARBON.equals(SWT.getPlatform()) || Util.WS_COCOA.equals(SWT.getPlatform())) {
      assertEquals(2, numAboutBindings);
    } else {
      assertEquals(1, numAboutBindings);
    }
  }