Пример #1
0
    public void onKeyDown(KeyDownEvent e) {

      // stopping propagation is needed to prevent duplicate events
      e.stopPropagation();

      checkCursorKeys(e);
      int keyCode = e.getNativeKeyCode();

      switch (keyCode) {
        case KeyCodes.KEY_ESCAPE:
          e.preventDefault();
          GeoElement oldGeo = kernel.getGeoAt(column, row);
          cancelCellEditing();

          // restore old text in spreadsheet
          table.getModel().setValueAt(oldGeo, row, column);

          // stopCellEditing(0,0);
          // force nice redraw
          table.setSelection(column, row);

          // update the formula bar after escape
          // ?//table.getView().updateFormulaBar();

          break;
      }
    }
Пример #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;
        }
    }
  }
Пример #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;
          }
        }
      }
    }