Beispiel #1
0
 public void handleEvent(Event event) {
   if (recordingSupport != null) {
     int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(event);
     KeySequence sequence =
         KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
     switch (recordingSupport.getMode()) {
       case Recording:
         TriggerSequence[] assertShortcuts =
             RecordingContextManager.Instance.getAssertModeShortcuts();
         if (assertShortcuts != null) {
           for (TriggerSequence s : assertShortcuts) {
             if (sequence.equals(s)) {
               recordingSupport.setMode(RecordingMode.Asserting);
             }
           }
         }
         handleStopRecordShortcutPressed(sequence);
         break;
       case Asserting:
         TriggerSequence[] recordShortcuts =
             RecordingContextManager.Instance.getRecordModeShortcuts();
         if (recordShortcuts != null) {
           for (TriggerSequence s : recordShortcuts) {
             if (sequence.equals(s)) {
               recordingSupport.setMode(RecordingMode.Recording);
             }
           }
         }
         handleStopRecordShortcutPressed(sequence);
         break;
       case Stopped:
         TriggerSequence[] startShortcuts =
             RecordingContextManager.Instance.getStartRecordShortcuts();
         if (startShortcuts != null) {
           for (TriggerSequence s : startShortcuts) {
             if (sequence.equals(s)) {
               recordingSupport.setMode(RecordingMode.Connecting);
             }
           }
         }
         TriggerSequence[] replayShortcuts =
             RecordingContextManager.Instance.getReplayShortcuts();
         if (replayShortcuts != null) {
           for (TriggerSequence s : replayShortcuts) {
             if (sequence.equals(s)) {
               recordingSupport.setMode(RecordingMode.Replaying);
             }
           }
         }
         break;
       case Connecting:
       case ImageRecognition:
       case Replaying:
       case WaitingForAUTRestart:
       default:
         break;
     }
   }
 }
  /**
   * Tests whether the preference store will be read automatically when a change to the preference
   * store is made.
   *
   * @throws ParseException If "ALT+SHIFT+Q A" cannot be parsed by KeySequence.
   */
  public final void testAutoLoad() throws ParseException {
    // Get the services.
    ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class);
    IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class);
    bindingService.readRegistryAndPreferences(commandService);

    // Check the pre-conditions.
    final String emacsSchemeId = EMACS_SCHEME_ID;
    assertFalse(
        "The active scheme should be Emacs yet",
        emacsSchemeId.equals(bindingService.getActiveScheme().getId()));
    final KeySequence formalKeySequence = KeySequence.getInstance("ALT+SHIFT+Q A");
    final String commandId = "org.eclipse.ui.views.showView";
    Binding[] bindings = bindingService.getBindings();
    int i;
    for (i = 0; i < bindings.length; i++) {
      final Binding binding = bindings[i];
      if ((binding.getType() == Binding.USER)
          && (formalKeySequence.equals(binding.getTriggerSequence()))) {
        final ParameterizedCommand command = binding.getParameterizedCommand();
        final String actualCommandId = (command == null) ? null : command.getCommand().getId();
        assertFalse("The command should not yet be bound", commandId.equals(actualCommandId));
        break;
      }
    }
    assertEquals("There shouldn't be a matching command yet", bindings.length, i);

    // Modify the preference store.
    final IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
    store.setValue(
        "org.eclipse.ui.commands",
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?><org.eclipse.ui.commands><activeKeyConfiguration keyConfigurationId=\""
            + emacsSchemeId
            + "\"/><keyBinding commandId=\""
            + commandId
            + "\" contextId=\"org.eclipse.ui.contexts.window\" keyConfigurationId=\"org.eclipse.ui.defaultAcceleratorConfiguration\" keySequence=\""
            + formalKeySequence
            + "\"/></org.eclipse.ui.commands>");

    // Check that the values have changed.
    assertEquals(
        "The active scheme should now be Emacs",
        emacsSchemeId,
        bindingService.getActiveScheme().getId());
    bindings = bindingService.getBindings();
    for (i = 0; i < bindings.length; i++) {
      final Binding binding = bindings[i];
      if ((binding.getType() == Binding.USER)
          && (formalKeySequence.equals(binding.getTriggerSequence()))) {
        final ParameterizedCommand command = binding.getParameterizedCommand();
        final String actualCommandId = (command == null) ? null : command.getCommand().getId();
        assertEquals("The command should be bound to 'ALT+SHIFT+Q A'", commandId, actualCommandId);
        break;
      }
    }
    assertFalse("There should be a matching command now", (bindings.length == i));
  }
  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);
  }
Beispiel #4
0
 private void handleStopRecordShortcutPressed(KeySequence sequence) {
   TriggerSequence[] shortcuts = RecordingContextManager.Instance.getStopRecordShortcuts();
   if (shortcuts != null) {
     for (TriggerSequence s : shortcuts) {
       if (sequence.equals(s)) {
         recordingSupport.setMode(RecordingMode.Stopped);
       }
     }
   }
 }
  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);
    }
  }