// {{{ 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; } // }}}
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); } } }); }
/** * 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); } } // }}}