Exemple #1
0
  // {{{ userInput() method
  protected void userInput(char ch) {
    lastActionCount = 0;

    JEditTextArea textArea = view.getTextArea();

    /* Buffer buffer = view.getBuffer();
    if(!buffer.insideCompoundEdit())
    	buffer.beginCompoundEdit(); */

    if (repeatCount == 1) textArea.userInput(ch);
    else {
      // stop people doing dumb stuff like C+ENTER 100 C+n
      if (repeatCount > REPEAT_COUNT_THRESHOLD) {
        Object[] pp = {String.valueOf(ch), repeatCount};

        if (GUIUtilities.confirm(
                view,
                "large-repeat-count.user-input",
                pp,
                JOptionPane.WARNING_MESSAGE,
                JOptionPane.YES_NO_OPTION)
            != JOptionPane.YES_OPTION) {
          repeatCount = 1;
          view.getStatus().setMessage(null);
          return;
        }
      }

      JEditBuffer buffer = view.getBuffer();
      try {
        if (repeatCount != 1) buffer.beginCompoundEdit();
        for (int i = 0; i < repeatCount; i++) textArea.userInput(ch);
      } finally {
        if (repeatCount != 1) buffer.endCompoundEdit();
      }
    }

    Macros.Recorder recorder = view.getMacroRecorder();

    if (recorder != null) {
      recorder.recordInput(repeatCount, ch, textArea.isOverwriteEnabled());
    }

    repeatCount = 1;
  } // }}}
Exemple #2
0
  // {{{ invokeReadNextChar() method
  protected void invokeReadNextChar(char ch) {
    JEditBuffer buffer = view.getBuffer();

    /* if(buffer.insideCompoundEdit())
    buffer.endCompoundEdit(); */

    String charStr = StandardUtilities.charsToEscapes(String.valueOf(ch));

    // this might be a bit slow if __char__ occurs a lot
    int index;
    while ((index = readNextChar.indexOf("__char__")) != -1) {
      readNextChar =
          readNextChar.substring(0, index)
              + '\''
              + charStr
              + '\''
              + readNextChar.substring(index + 8);
    }

    Macros.Recorder recorder = view.getMacroRecorder();
    if (recorder != null) recorder.record(getRepeatCount(), readNextChar);

    view.getStatus().setMessage(null);

    if (getRepeatCount() != 1) {
      try {
        buffer.beginCompoundEdit();

        BeanShell.eval(
            view,
            BeanShell.getNameSpace(),
            "for(int i = 1; i < " + getRepeatCount() + "; i++)\n{\n" + readNextChar + "\n}");
      } finally {
        buffer.endCompoundEdit();
      }
    } else BeanShell.eval(view, BeanShell.getNameSpace(), readNextChar);

    readNextChar = null;
  } // }}}
Exemple #3
0
  private void invoke() {
    String cmd;
    if (popup != null) cmd = popup.list.getSelectedValue().toString();
    else {
      cmd = action.getText().trim();
      int index = cmd.indexOf('=');
      if (index != -1) {
        action.addCurrentToHistory();
        String propName = cmd.substring(0, index).trim();
        String propValue = cmd.substring(index + 1).trim();
        String code;

        if (propName.startsWith("buffer.")) {
          if (propName.equals("buffer.mode")) {
            code = "buffer.setMode(\"" + MiscUtilities.charsToEscapes(propValue) + "\");";
          } else {
            code =
                "buffer.setStringProperty(\""
                    + MiscUtilities.charsToEscapes(propName.substring("buffer.".length()))
                    + "\",\""
                    + MiscUtilities.charsToEscapes(propValue)
                    + "\");";
          }

          code += "\nbuffer.propertiesChanged();";
        } else if (propName.startsWith("!buffer.")) {
          code =
              "jEdit.setProperty(\""
                  + MiscUtilities.charsToEscapes(propName.substring(1))
                  + "\",\""
                  + MiscUtilities.charsToEscapes(propValue)
                  + "\");\n"
                  + "jEdit.propertiesChanged();";
        } else {
          code =
              "jEdit.setProperty(\""
                  + MiscUtilities.charsToEscapes(propName)
                  + "\",\""
                  + MiscUtilities.charsToEscapes(propValue)
                  + "\");\n"
                  + "jEdit.propertiesChanged();";
        }

        Macros.Recorder recorder = view.getMacroRecorder();
        if (recorder != null) recorder.record(code);
        BeanShell.eval(view, namespace, code);
        cmd = null;
      } else if (cmd.length() != 0) {
        String[] completions = getCompletions(cmd);
        if (completions.length != 0) {
          cmd = completions[0];
        }
      } else cmd = null;
    }

    if (popup != null) {
      popup.dispose();
      popup = null;
    }

    final String finalCmd = cmd;
    final EditAction act = (finalCmd == null ? null : jEdit.getAction(finalCmd));
    if (temp) view.removeToolBar(this);

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            view.getTextArea().requestFocus();
            if (act == null) {
              if (finalCmd != null) {
                view.getStatus()
                    .setMessageAndClear(jEdit.getProperty("view.action.no-completions"));
              }
            } else {
              view.getInputHandler().setRepeatCount(repeatCount);
              view.getInputHandler().invokeAction(act);
            }
          }
        });
  }
  // {{{ record() method
  private static void record(
      View view, String action, boolean replaceAction, boolean recordFileSet) {
    Macros.Recorder recorder = view.getMacroRecorder();

    if (recorder != null) {
      recorder.record(
          "SearchAndReplace.setSearchString(\""
              + StandardUtilities.charsToEscapes(search)
              + "\");");

      if (replaceAction) {
        recorder.record(
            "SearchAndReplace.setReplaceString(\""
                + StandardUtilities.charsToEscapes(replace)
                + "\");");
        recorder.record("SearchAndReplace.setBeanShellReplace(" + beanshell + ");");
      } else {
        // only record this if doing a find next
        recorder.record("SearchAndReplace.setAutoWrapAround(" + wrap + ");");
        recorder.record("SearchAndReplace.setReverseSearch(" + reverse + ");");
      }

      recorder.record("SearchAndReplace.setWholeWord(" + wholeWord + ");");
      recorder.record("SearchAndReplace.setIgnoreCase(" + ignoreCase + ");");
      recorder.record("SearchAndReplace.setRegexp(" + regexp + ");");

      if (recordFileSet) {
        recorder.record("SearchAndReplace.setSearchFileSet(" + fileset.getCode() + ");");
      }

      recorder.record("SearchAndReplace." + action + ';');
    }
  } // }}}
Exemple #5
0
  /**
   * Invokes the specified action, repeating and recording it as necessary.
   *
   * @param action The action
   */
  @Override
  public void invokeAction(EditAction action) {
    JEditBuffer buffer = view.getBuffer();

    /* if(buffer.insideCompoundEdit())
    buffer.endCompoundEdit(); */

    // remember the last executed action
    if (!action.noRememberLast()) {
      HistoryModel.getModel("action").addItem(action.getName());
      if (lastAction == action) lastActionCount++;
      else {
        lastAction = action;
        lastActionCount = 1;
      }
    }

    // remember old values, in case action changes them
    int _repeatCount = repeatCount;

    // execute the action
    if (action.noRepeat() || _repeatCount == 1) action.invoke(view);
    else {
      // stop people doing dumb stuff like C+ENTER 100 C+n
      if (_repeatCount > REPEAT_COUNT_THRESHOLD) {
        String label = action.getLabel();
        if (label == null) label = action.getName();
        else label = GUIUtilities.prettifyMenuLabel(label);

        Object[] pp = {label, _repeatCount};

        if (GUIUtilities.confirm(
                view,
                "large-repeat-count",
                pp,
                JOptionPane.WARNING_MESSAGE,
                JOptionPane.YES_NO_OPTION)
            != JOptionPane.YES_OPTION) {
          repeatCount = 1;
          view.getStatus().setMessage(null);
          return;
        }
      }

      try {
        buffer.beginCompoundEdit();

        for (int i = 0; i < _repeatCount; i++) action.invoke(view);
      } finally {
        buffer.endCompoundEdit();
      }
    }

    Macros.Recorder recorder = view.getMacroRecorder();

    if (recorder != null && !action.noRecord()) recorder.record(_repeatCount, action.getCode());

    // If repeat was true originally, clear it
    // Otherwise it might have been set by the action, etc
    if (_repeatCount != 1) {
      // first of all, if this action set a
      // readNextChar, do not clear the repeat
      if (readNextChar != null) return;

      repeatCount = 1;
      view.getStatus().setMessage(null);
    }
  } // }}}