Example #1
0
  private void handleRowClick(MouseDownEvent event, TableRowElement row) {
    int modifiers = KeyboardShortcut.getModifierValue(event.getNativeEvent());
    modifiers &= ~KeyboardShortcut.ALT; // ALT has no effect

    if (!allowMultiSelect_) modifiers = KeyboardShortcut.NONE;

    // We'll treat Ctrl and Meta as equivalent--and normalize to Ctrl.
    if (KeyboardShortcut.META == (modifiers & KeyboardShortcut.META))
      modifiers |= KeyboardShortcut.CTRL;
    modifiers &= ~KeyboardShortcut.META;

    if (modifiers == KeyboardShortcut.NONE) {
      // Select only the target row
      clearSelection();
      setSelected(row, true);
    } else if (modifiers == KeyboardShortcut.CTRL) {
      // Toggle the target row
      setSelected(row, !isSelected(row));
    } else {
      // SHIFT or CTRL+SHIFT

      int target = row.getRowIndex();
      Integer min = null;
      Integer max = null;
      for (TableRowElement selectedRow : selectedRows_) {
        if (min == null) min = selectedRow.getRowIndex();
        max = selectedRow.getRowIndex();
      }

      int offset; // selection offset
      int length; // selection length

      if (min == null) {
        // Nothing is selected
        offset = target;
        length = 1;
      } else if (target < min) {
        // Select target..max
        offset = target;
        length = max - target + 1;
      } else if (target > max) {
        offset = min;
        length = target - min + 1;
      } else {
        // target is in between min and max
        if (modifiers == (KeyboardShortcut.CTRL | KeyboardShortcut.SHIFT)) {
          offset = min;
          length = target - min + 1;
        } else {
          offset = target;
          length = 1;
        }
      }

      clearSelection();
      if (length > 0) {
        setSelectedPhysical(offset, length, true);
      }
    }
  }
Example #2
0
  private void handleKeyDown(KeyDownEvent event) {
    int modifiers = KeyboardShortcut.getModifierValue(event.getNativeEvent());
    switch (event.getNativeKeyCode()) {
      case KeyCodes.KEY_UP:
      case KeyCodes.KEY_DOWN:
        break;
      default:
        return;
    }

    if (!allowMultiSelect_) modifiers = KeyboardShortcut.NONE;

    event.preventDefault();
    event.stopPropagation();

    switch (modifiers) {
      case 0:
      case KeyboardShortcut.SHIFT:
        break;
      default:
        return;
    }

    sortSelectedRows();
    int min = table_.getRows().getLength();
    int max = -1;
    if (selectedRows_.size() > 0) {
      min = selectedRows_.get(0).getRowIndex();
      max = selectedRows_.get(selectedRows_.size() - 1).getRowIndex();
    }

    switch (event.getNativeKeyCode()) {
      case KeyCodes.KEY_UP:
        {
          Integer row = findNextValueRow(min, true);
          if (row != null) {
            if (modifiers != KeyboardShortcut.SHIFT) clearSelection();
            setSelectedPhysical(row, 1, true);
            ensureRowVisible(row);
          }
          break;
        }
      case KeyCodes.KEY_DOWN:
        {
          Integer row = findNextValueRow(max, false);
          if (row != null) {
            if (modifiers != KeyboardShortcut.SHIFT) clearSelection();
            setSelectedPhysical(row, 1, true);
            ensureRowVisible(row);
          }
          break;
        }
    }
  }
Example #3
0
    public void onKeyDown(KeyDownEvent event) {
      int keyCode = event.getNativeKeyCode();

      for (KeyDownPreviewHandler handler : keyDownPreviewHandlers_) {
        if (handler.previewKeyDown(event.getNativeEvent())) {
          event.preventDefault();
          event.stopPropagation();
          return;
        }
      }

      if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) event.preventDefault();

      int modifiers = KeyboardShortcut.getModifierValue(event.getNativeEvent());

      if (event.isUpArrow() && modifiers == 0) {
        if ((input_.getCurrentLineNum() == 0) || input_.isCursorAtEnd()) {
          event.preventDefault();
          event.stopPropagation();

          navigateHistory(-1);
        }
      } else if (event.isDownArrow() && modifiers == 0) {
        if ((input_.getCurrentLineNum() == input_.getCurrentLineCount() - 1)
            || input_.isCursorAtEnd()) {
          event.preventDefault();
          event.stopPropagation();

          navigateHistory(1);
        }
      } else if (keyCode == KeyCodes.KEY_ENTER && modifiers == 0) {
        event.preventDefault();
        event.stopPropagation();

        restoreFocus_ = true;
        processCommandEntry();
      } else if (keyCode == KeyCodes.KEY_ESCAPE && modifiers == 0) {
        event.preventDefault();

        if (input_.getText().length() == 0) {
          // view_.isPromptEmpty() is to check for cases where the
          // server is prompting but not at the top level. Escape
          // needs to send null in those cases.
          // For example, try "scan()" function
          if (view_.isPromptEmpty()) {
            // interrupt server
            server_.interrupt(
                new VoidServerRequestCallback() {
                  @Override
                  public void onError(ServerError error) {
                    super.onError(error);
                    globalDisplay_.showErrorMessage(
                        "Error Interrupting Server", error.getUserMessage());
                  }
                });
          } else {
            // if the input is already empty then send a console reset
            // which will jump us back to the main prompt
            eventBus_.fireEvent(new ConsoleInputEvent(null));
          }
        }

        input_.clear();
      } else {
        int mod = KeyboardShortcut.getModifierValue(event.getNativeEvent());
        if (mod == KeyboardShortcut.CTRL) {
          switch (keyCode) {
            case 'L':
              Shell.this.onConsoleClear();
              event.preventDefault();
              break;
          }
        } else if (mod == KeyboardShortcut.ALT) {
          switch (keyCode) {
            case 189: // hyphen
              event.preventDefault();
              event.stopPropagation();
              input_.replaceSelection(" <- ", true);
              break;
          }
        } else if ((BrowseCap.hasMetaKey()
                && (mod == (KeyboardShortcut.META + KeyboardShortcut.SHIFT)))
            || (!BrowseCap.hasMetaKey()
                && (mod == (KeyboardShortcut.CTRL + KeyboardShortcut.SHIFT)))) {
          switch (keyCode) {
            case KeyCodes.KEY_M:
              event.preventDefault();
              event.stopPropagation();
              input_.replaceSelection(" %>% ", true);
              break;
          }
        }
      }
    }