예제 #1
0
    @Override
    public void run() {
      try {
        PySelection selection = new PySelection(edit);

        ScriptConsole console = ScriptConsole.getActiveScriptConsole();

        if (console == null) {
          // if no console is available, create it (if possible).
          PydevConsoleFactory factory = new PydevConsoleFactory();
          String cmd = null;

          // Check if the current selection should be sent to the editor.
          if (InteractiveConsolePrefs.getSendCommandOnCreationFromEditor()) {
            cmd = getCommandToSend(edit, selection);
            if (cmd != null) {
              cmd = "\n" + cmd;
            }
          }
          factory.createConsole(cmd);

        } else {
          if (console instanceof ScriptConsole) {
            // ok, console available
            sendCommandToConsole(selection, console, this.edit);
          }
        }
      } catch (Exception e) {
        Log.log(e);
      }
    }
예제 #2
0
  /** Sends the current selected text/editor to the console. */
  private static void sendCommandToConsole(
      PySelection selection, ScriptConsole console, PyEdit edit) throws BadLocationException {
    ScriptConsole pydevConsole = console;
    IDocument document = pydevConsole.getDocument();

    String cmd = getCommandToSend(edit, selection);
    if (cmd != null) {
      document.replace(document.getLength(), 0, cmd);
    }

    if (InteractiveConsolePrefs.getFocusConsoleOnSendCommand()) {
      ScriptConsoleViewer viewer = pydevConsole.getViewer();
      if (viewer == null) {
        return;
      }
      StyledText textWidget = viewer.getTextWidget();
      if (textWidget == null) {
        return;
      }
      textWidget.setFocus();
    }
  }