예제 #1
0
  public void register(
      int modifiers,
      int keyCode,
      AppCommand command,
      String groupName,
      String title,
      String disableModes) {
    if (!BrowseCap.hasMetaKey() && (modifiers & KeyboardShortcut.META) != 0) return;

    register(new KeySequence(keyCode, modifiers), command, groupName, title, disableModes);
  }
예제 #2
0
  private void swallowEvents(Object object) {
    NativeEvent event = (NativeEvent) object;

    // Suppress save / quit events from reaching the browser
    KeyCombination keys = new KeyCombination(event);
    int keyCode = keys.getKeyCode();
    int modifiers = keys.getModifier();

    boolean isSaveQuitKey = keyCode == KeyCodes.KEY_S || keyCode == KeyCodes.KEY_W;

    boolean isSaveQuitModifier =
        BrowseCap.isMacintosh()
            ? modifiers == KeyboardShortcut.META
            : modifiers == KeyboardShortcut.CTRL;

    if (isSaveQuitKey && isSaveQuitModifier) event.preventDefault();
  }
예제 #3
0
  private String getDefaultPdfPreview() {
    if (Desktop.isDesktop()) {
      // if there is a desktop synctex viewer available then default to it
      if (Desktop.getFrame().getDesktopSynctexViewer().length() > 0) {
        return PDF_PREVIEW_DESKTOP_SYNCTEX;
      }

      // otherwise default to the system viewer on linux and the internal
      // viewer on mac (windows will always have a desktop synctex viewer)
      else {
        if (BrowseCap.isLinux()) {
          return PDF_PREVIEW_SYSTEM;
        } else {
          return PDF_PREVIEW_RSTUDIO;
        }
      }
    }

    // web mode -- always default to internal viewer
    else {
      return PDF_PREVIEW_RSTUDIO;
    }
  }
예제 #4
0
파일: Shell.java 프로젝트: jmhome/rstudio
    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;
          }
        }
      }
    }