Exemplo n.º 1
0
  public void register(
      KeySequence keys, AppCommand command, String groupName, String title, String disableModes) {
    KeyboardShortcut shortcut = new KeyboardShortcut(keys, groupName, title, disableModes);

    // Update state related to key dispatch.
    updateKeyPrefixes(shortcut);

    if (command == null) {
      // If the shortcut is unbound, check to see whether there's another
      // unbound shortcut with the same title; replace it if there is.
      boolean existingShortcut = false;
      for (int i = 0; i < unboundShortcuts_.size(); i++) {
        if (unboundShortcuts_.get(i).getTitle().equals(title)) {
          unboundShortcuts_.set(i, shortcut);
          existingShortcut = true;
          break;
        }
      }
      if (!existingShortcut) unboundShortcuts_.add(shortcut);
    } else {
      // Setting the shortcut on a command is done purely for UI-related tasks.
      // We don't want to set modal shortcuts (the binding will be active regardless
      // of whether we let the command 'know' about the binding).
      if (disableModes.indexOf("default") != 0) command.setShortcut(shortcut);

      commands_.addCommandBinding(keys, command, shortcut);
    }
  }
Exemplo n.º 2
0
  private boolean dispatch(
      KeyboardShortcut shortcut,
      AppCommandBindings bindings,
      NativeEvent event,
      Map<AppCommand, Boolean> maskedCommandsMap) {
    KeySequence keys = shortcut.getKeySequence();

    // If the shortcut manager is disabled, bail
    if (!isEnabled()) return false;

    // If we have no binding, bail
    if (!bindings.containsKey(keys)) return false;

    AppCommand command = bindings.getCommand(keys, editorMode_, maskedCommandsMap);
    if (command == null) return false;

    event.preventDefault();
    command.executeFromShortcut();
    return true;
  }
Exemplo n.º 3
0
    public AppCommand getCommand(
        KeySequence keys, int editorMode, Map<AppCommand, Boolean> maskedCommands) {
      if (!bindings_.containsKey(keys)) return null;

      List<AppCommandBinding> commands = bindings_.get(keys);
      for (AppCommandBinding binding : commands) {
        int disableModes = binding.getShortcut().getDisableModes();
        AppCommand command = binding.getCommand();

        // If this command is masked by another command, skip it.
        if (maskedCommands != null && maskedCommands.containsKey(command)) continue;

        // Check to see whether this command is enabled for the current
        // editor mode.
        boolean enabled = command.isEnabled() && (disableModes & editorMode) == 0;

        if (enabled) return command;
      }

      return null;
    }
Exemplo n.º 4
0
  private boolean dispatch(
      KeyboardShortcut shortcut,
      Map<KeyboardShortcut, ArrayList<AppCommand>> bindings,
      NativeEvent event,
      Map<AppCommand, Boolean> maskedCommandsMap) {
    if (!bindings.containsKey(shortcut) || bindings.get(shortcut) == null) return false;

    AppCommand command = null;
    for (int i = 0; i < bindings.get(shortcut).size(); i++) {
      command = bindings.get(shortcut).get(i);
      if (command != null) {
        boolean enabled = isEnabled() && command.isEnabled();

        // some commands want their keyboard shortcut to pass through
        // to the browser when they are disabled (e.g. Cmd+W)
        if (!enabled && !command.preventShortcutWhenDisabled()) return false;

        // if we've remapped an AppCommand to a new binding, it's
        // implicitly disabled
        if (maskedCommandsMap != null && maskedCommandsMap.containsKey(command)) {
          command = null;
          continue;
        }

        event.preventDefault();

        // if this command is enabled, execute it and stop looking
        if (enabled) {
          command.executeFromShortcut();
          break;
        }
      }
    }

    return command != null;
  }
Exemplo n.º 5
0
  public void register(
      KeySequence keys, AppCommand command, String groupName, String title, String disableModes) {

    KeyboardShortcut shortcut = new KeyboardShortcut(keys, groupName, title, disableModes);

    if (command == null) {
      // If the shortcut is unbound, check to see whether there's another
      // unbound shortcut with the same title; replace it if there is.
      boolean existingShortcut = false;
      for (int i = 0; i < unboundShortcuts_.size(); i++) {
        if (unboundShortcuts_.get(i).getTitle().equals(title)) {
          unboundShortcuts_.set(i, shortcut);
          existingShortcut = true;
          break;
        }
      }
      if (!existingShortcut) unboundShortcuts_.add(shortcut);
    } else {
      ArrayList<AppCommand> commands;
      if (commands_.containsKey(shortcut)) {
        // already have a command for this shortcut; add this one
        commands = commands_.get(shortcut);
      } else {
        // no commands yet, make a new list
        commands = new ArrayList<AppCommand>();
        commands_.put(shortcut, commands);
      }
      commands.add(command);

      command.setShortcut(shortcut);
    }

    if (shortcut.isModalShortcut()) {
      modalShortcuts_.add(shortcut);
    }
  }