diff --git a/app/Editor.java b/app/Editor.java index dfc8741e2..e0ccdeb13 100644 --- a/app/Editor.java +++ b/app/Editor.java @@ -116,6 +116,9 @@ public class Editor extends JFrame protected UndoAction undoAction; protected RedoAction redoAction; UndoManager undo; + // used internally, and only briefly + CompoundEdit compoundEdit; + //static public UndoManager undo = new UndoManager(); // editor needs this guy // @@ -234,22 +237,6 @@ public class Editor extends JFrame listener = new EditorListener(this, textarea); pain.add(box); - /* - // set the undo stuff for this feller - Document document = textarea.getDocument(); - //document.addUndoableEditListener(new PdeUndoableEditListener()); - document.addUndoableEditListener(new UndoableEditListener() { - public void undoableEditHappened(UndoableEditEvent e) { - if (undo != null) { - //System.out.println(e.getEdit()); - undo.addEdit(e.getEdit()); - undoAction.updateUndoState(); - redoAction.updateRedoState(); - } - } - }); - */ - DropTarget dt = new DropTarget(this, new DropTargetListener() { public void dragEnter(DropTargetDragEvent event) { @@ -994,66 +981,19 @@ public class Editor extends JFrame } - /** - * Called to update the text but not switch to a different - * set of code (which would affect the undo manager). - */ - //public void setText(String what) { //, boolean discardUndo) { - //setText(what, 0, 0); - //} - - /** * Called to update the text but not switch to a different * set of code (which would affect the undo manager). */ public void setText(String what, int selectionStart, int selectionEnd) { + beginCompoundEdit(); textarea.setText(what); + endCompoundEdit(); textarea.select(selectionStart, selectionEnd); textarea.requestFocus(); // get the caret blinking } - /** - * Called by Sketch when the tab is changed or a new set of files are opened. - */ - /* - public void setText(String currentProgram, - int selectionStart, int selectionEnd, - UndoManager currentUndo) { - //System.out.println("setting text, changing undo"); - this.undo = null; - - //if (discardUndo) undo.discardAllEdits(); - - // don't set the undo object yet otherwise gets hokey - textarea.setText(currentProgram); - textarea.select(selectionStart, selectionEnd); - textarea.requestFocus(); // get the caret blinking - - this.undo = currentUndo; - undoAction.updateUndoState(); - redoAction.updateRedoState(); - } - */ - - /* - public void setDocument(SyntaxDocument document, - int selectionStart, int selectionStop, - int scrollPosition, UndoManager undo) { - - textarea.setDocument(document, selectionStart, selectionStop, - scrollPosition); - - textarea.requestFocus(); // get the caret blinking - - this.undo = undo; - undoAction.updateUndoState(); - redoAction.updateRedoState(); - } - */ - - /** * Switch between tabs, this swaps out the Document object * that's currently being manipulated. @@ -1078,7 +1018,10 @@ public class Editor extends JFrame // connect the undo listener to the editor code.document.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { - if (undo != null) { + if (compoundEdit != null) { + compoundEdit.addEdit(e.getEdit()); + + } else if (undo != null) { undo.addEdit(e.getEdit()); undoAction.updateUndoState(); redoAction.updateRedoState(); @@ -1099,6 +1042,18 @@ public class Editor extends JFrame redoAction.updateRedoState(); } + public void beginCompoundEdit() { + compoundEdit = new CompoundEdit(); + } + + public void endCompoundEdit() { + compoundEdit.end(); + undo.addEdit(compoundEdit); + undoAction.updateUndoState(); + redoAction.updateRedoState(); + compoundEdit = null; + } + public void handleRun(boolean present) { diff --git a/app/SketchCode.java b/app/SketchCode.java index d923ed31d..d556a63be 100644 --- a/app/SketchCode.java +++ b/app/SketchCode.java @@ -46,7 +46,11 @@ public class SketchCode { /** Document object for this tab */ public SyntaxDocument document; - /** Undo Manager for this tab, each tab keeps track of their own */ + /** + * Undo Manager for this tab, each tab keeps track of their own + * Editor.undo will be set to this object when this code is the tab + * that's currently the front. + */ public UndoManager undo; // = new UndoManager(); // saved positions from last time this tab was used diff --git a/app/syntax/JEditTextArea.java b/app/syntax/JEditTextArea.java index 942039748..6c51edb32 100644 --- a/app/syntax/JEditTextArea.java +++ b/app/syntax/JEditTextArea.java @@ -883,27 +883,26 @@ public class JEditTextArea extends JComponent } } + /** * Sets the entire text of this text area. */ public void setText(String text) { - try - { - document.beginCompoundEdit(); - document.remove(0,document.getLength()); - document.insertString(0,text,null); - } - catch(BadLocationException bl) - { - bl.printStackTrace(); - } - finally - { - document.endCompoundEdit(); - } + try { + document.beginCompoundEdit(); + document.remove(0,document.getLength()); + document.insertString(0,text,null); + + } catch (BadLocationException bl) { + bl.printStackTrace(); + + } finally { + document.endCompoundEdit(); + } } + /** * Returns the specified substring of the document. * @param start The start offset diff --git a/app/tools/AutoFormat.java b/app/tools/AutoFormat.java index 9ec443c73..e405e9305 100644 --- a/app/tools/AutoFormat.java +++ b/app/tools/AutoFormat.java @@ -31,8 +31,8 @@ import java.util.StringTokenizer; /** - * Alternate handler for dealing with auto format, - * contributed by Martin Gomez. + * Alternate handler for dealing with auto format. + * Contributed by Martin Gomez, additional bug fixes by Ben Fry. */ public class AutoFormat { Editor editor; @@ -43,109 +43,11 @@ public class AutoFormat { } - /* - public void show() { - String prog = editor.textarea.getText(); - - // TODO re-enable history - //history.record(prog, SketchHistory.BEAUTIFY); - - //int tabSize = Preferences.getInteger("editor.tabs.size"); - - char program[] = prog.toCharArray(); - StringBuffer buffer = new StringBuffer(); - boolean gotBlankLine = false; - int index = 0; - int level = 0; - - while (index != program.length) { - int begin = index; - while ((program[index] != '\n') && - (program[index] != '\r')) { - index++; - if (program.length == index) - break; - } - int end = index; - if (index != program.length) { - if ((index+1 != program.length) && - // treat \r\n from windows as one line - (program[index] == '\r') && - (program[index+1] == '\n')) { - index += 2; - } else { - index++; - } - } // otherwise don't increment - - String line = new String(program, begin, end-begin); - line = line.trim(); - - if (line.length() == 0) { - if (!gotBlankLine) { - // let first blank line through - buffer.append('\n'); - gotBlankLine = true; - } - } else { - //System.out.println(level); - int idx = -1; - String myline = line.substring(0); - while (myline.lastIndexOf('}') != idx) { - idx = myline.indexOf('}'); - myline = myline.substring(idx+1); - level--; - } - //for (int i = 0; i < level*2; i++) { - // TODO i've since forgotten how i made this work (maybe it's even - // a bug) but for now, level is incrementing/decrementing in - // steps of two. in the interest of getting a release out, - // i'm just gonna roll with that since this function will prolly - // be replaced entirely and there are other things to worry about. - for (int i = 0; i < tabSize * level / 2; i++) { - buffer.append(' '); - } - buffer.append(line); - buffer.append('\n'); - //if (line.charAt(0) == '{') { - //level++; - //} - idx = -1; - myline = line.substring(0); - while (myline.lastIndexOf('{') != idx) { - idx = myline.indexOf('{'); - myline = myline.substring(idx+1); - level++; - } - gotBlankLine = false; - } - } - - // save current (rough) selection point - int selectionEnd = editor.textarea.getSelectionEnd(); - - // replace with new bootiful text - editor.setText(buffer.toString(), false); - - // make sure the caret would be past the end of the text - if (buffer.length() < selectionEnd - 1) { - selectionEnd = buffer.length() - 1; - } - - // at least in the neighborhood - editor.textarea.select(selectionEnd, selectionEnd); - - editor.sketch.setModified(); - //buttons.clear(); - } - */ - - StringBuffer strOut; String formattedText; int indentValue; String indentChar; - String uhOh = null; + //String uhOh = null; String theStuff; int EOF; BufferedInputStream bin = null; @@ -276,7 +178,7 @@ public class AutoFormat { public void fprintf(int outfil, String out_string) { - int out_len = out_string.length(); + //int out_len = out_string.length(); String j_string = new String(string); strOut.append(out_string); } @@ -287,491 +189,6 @@ public class AutoFormat { } - public void setUhOh(String s) { - uhOh = s; - } - - - public String grabUhOh() { - return uhOh; - } - - - public void show() { - StringBuffer onechar; - - theStuff = editor.textarea.getText(); - strOut = new StringBuffer(); - indentValue = Preferences.getInteger("editor.tabs.size"); - indentChar = new String(" "); - - lineNumber = 0; - BLOCK_MAXLEN = 256; - c_level = if_lev = level = e_flg = paren = 0; - a_flg = q_flg = j = b_flg = tabs = 0; - if_flg = peek = -1; - peekc = '`'; - s_flg = 1; - bblank = ' '; - jdoc = 0; - - s_level = new int[10]; - sp_flg = new int[20][10]; - s_ind = new int[20][10]; - s_if_lev = new int[10]; - s_if_flg = new int[10]; - ind = new int[10]; - p_flg = new int[10]; - s_tabs = new int[20][10]; - - w_else = new String ("else"); - w_if_ = new String ("if"); - w_for = new String ("for"); - w_ds = new String ("default"); - w_case = new String ("case"); - w_cpp_comment = new String ("//"); - w_jdoc = new String ("/**"); - line_feed = new String ("\n"); - - try { // opening input string - // open for input - ByteArrayInputStream in = - new ByteArrayInputStream(theStuff.getBytes()); - - // add buffering to that InputStream - bin = new BufferedInputStream(in); - - } catch(Exception e) { - System.out.println(e.toString()); - } - - // read as long as there is something to read - EOF = 0; // = 1 set in getchr when EOF - - bArray = new byte[BLOCK_MAXLEN]; - string = new char[BLOCK_MAXLEN]; - try { // the whole process - for (int ib = 0; ib < BLOCK_MAXLEN; ib++) bArray[ib] = '\0'; - - lineLength = nBytesRead = 0; - // read up a block - remember how many bytes read - nBytesRead = bin.read(bArray); - strBlock = new String(bArray); - - lineLength = nBytesRead; - lineNumber = 1; - indexBlock = -1; - j = 0; - while(EOF == 0) - { - c = getchr(); - switch(c) - { - default: - string[j++] = c; - if(c != ',') - { - l_char = c; - } - break; - case ' ': - case '\t': - if(lookup(w_else) == 1) - { - gotelse(); - if(s_flg == 0 || j > 0)string[j++] = c; - indent_puts(); - s_flg = 0; - break; - } - if(s_flg == 0 || j > 0)string[j++] = c; - break; - case '\r': /* for MS Windows 95 */ - case '\n': - lineNumber++; - if (EOF==1) - { - break; - } - String j_string = new String(string); - - e_flg = lookup(w_else); - if(e_flg == 1) gotelse(); - if (lookup_com(w_cpp_comment) == 1) - { - if (string[j] == '\n') - { - string[j] = '\0'; - j--; - } - } - - indent_puts(); - fprintf(outfil, line_feed); - s_flg = 1; - if(e_flg == 1) - { - p_flg[level]++; - tabs++; - } - else - if(p_char == l_char) - { - a_flg = 1; - } - break; - case '{': - if(lookup(w_else) == 1)gotelse(); - s_if_lev[c_level] = if_lev; - s_if_flg[c_level] = if_flg; - if_lev = if_flg = 0; - c_level++; - if(s_flg == 1 && p_flg[level] != 0) - { - p_flg[level]--; - tabs--; - } - string[j++] = c; - indent_puts(); - getnl() ; - indent_puts(); - fprintf(outfil,"\n"); - tabs++; - s_flg = 1; - if(p_flg[level] > 0) - { - ind[level] = 1; - level++; - s_level[level] = c_level; - } - break; - case '}': - c_level--; - if (c_level < 0) - { - EOF = 1; - string[j++] = c; - indent_puts(); - break; - } - if((if_lev = s_if_lev[c_level]-1) < 0)if_lev = 0; - if_flg = s_if_flg[c_level]; - indent_puts(); - tabs--; - p_tabs(); - peekc = getchr(); - if( peekc == ';') - { - onechar = new StringBuffer(); - onechar.append(c); /* } */ - onechar.append(';'); - fprintf(outfil, onechar.toString()); - peek = -1; - peekc = '`'; - } - else - { - onechar = new StringBuffer(); - onechar.append(c); - fprintf(outfil, onechar.toString()); - peek = 1; - } - getnl(); - indent_puts(); - fprintf(outfil,"\n"); - s_flg = 1; - if(c_level < s_level[level]) - if(level > 0) level--; - if(ind[level] != 0) - { - tabs -= p_flg[level]; - p_flg[level] = 0; - ind[level] = 0; - } - break; - case '"': - case '\'': - string[j++] = c; - cc = getchr(); - while(cc != c) - { - // max. length of line should be 256 - string[j++] = cc; - - if(cc == '\\') - { - cc = string[j++] = getchr(); - } - if(cc == '\n') - { - lineNumber++; - indent_puts(); - s_flg = 1; - } - cc = getchr(); - - } - string[j++] = cc; - if(getnl() == 1) - { - l_char = cc; - peek = 1; - peekc = '\n'; - } - break; - case ';': - string[j++] = c; - indent_puts(); - if(p_flg[level] > 0 && ind[level] == 0) - { - tabs -= p_flg[level]; - p_flg[level] = 0; - } - getnl(); - indent_puts(); - fprintf(outfil,"\n"); - s_flg = 1; - if(if_lev > 0) - if(if_flg == 1) - { - if_lev--; - if_flg = 0; - } - else if_lev = 0; - break; - case '\\': - string[j++] = c; - string[j++] = getchr(); - break; - case '?': - q_flg = 1; - string[j++] = c; - break; - case ':': - string[j++] = c; - peekc = getchr(); - if(peekc == ':') - { - indent_puts(); - fprintf (outfil,":"); - peek = -1; - peekc = '`'; - break; - } - else - { - int double_colon = 0; - peek = 1; - } - - if(q_flg == 1) - { - q_flg = 0; - break; - } - if(lookup(w_ds) == 0 && lookup(w_case) == 0) - { - s_flg = 0; - indent_puts(); - } - else - { - tabs--; - indent_puts(); - tabs++; - } - peekc = getchr(); - if(peekc == ';') - { - fprintf(outfil,";"); - peek = -1; - peekc = '`'; - } - else - { - peek = 1; - } - getnl(); - indent_puts(); - fprintf(outfil,"\n"); - s_flg = 1; - break; - - case '/': - c0 = string[j]; - string[j++] = c; - peekc = getchr(); - - if(peekc == '/') - { - string[j++] = peekc; - peekc = '`'; - peek = -1; - cpp_comment(); - fprintf(outfil,"\n"); - break; - } - else - { - peek = 1; - } - - if(peekc != '*') { - break; - } - else - { - if (j > 0) string[j--] = '\0'; - if (j > 0) indent_puts(); - string[j++] = '/'; - string[j++] = '*'; - peek = -1; - peekc = '`'; - comment(); - break; - } - case '#': - string[j++] = c; - cc = getchr(); - while(cc != '\n') - { - string[j++] = cc; - cc = getchr(); - } - string[j++] = cc; - s_flg = 0; - indent_puts(); - s_flg = 1; - break; - case ')': - paren--; - if (paren < 0) - { - EOF = 1; - } - string[j++] = c; - indent_puts(); - if(getnl() == 1) - { - peekc = '\n'; - peek = 1; - if(paren != 0) - { - a_flg = 1; - } - else if(tabs > 0) - { - p_flg[level]++; - tabs++; - ind[level] = 0; - } - } - break; - case '(': - string[j++] = c; - paren++; - if ((lookup(w_for) == 1)) - { - c = get_string(); - while(c != ';') c = get_string(); - ct=0; - int for_done = 0; - while (for_done==0) - { - c = get_string(); - while(c != ')') - { - if(c == '(') ct++; - c = get_string(); - } - if(ct != 0) - { - ct--; - } - else for_done = 1; - } /* endwhile for_done */ - paren--; - if (paren < 0) - { - EOF = 1; - } - indent_puts(); - if(getnl() == 1) - { - peekc = '\n'; - peek = 1; - p_flg[level]++; - tabs++; - ind[level] = 0; - } - break; - } - - if(lookup(w_if_) == 1) - { - indent_puts(); - s_tabs[c_level][if_lev] = tabs; - sp_flg[c_level][if_lev] = p_flg[level]; - s_ind[c_level][if_lev] = ind[level]; - if_lev++; - if_flg = 1; - } - } /* end switch */ - - String j_string = new String(string); - - } // end while not EOF - - //formattedText = strOut.toString(); - - // save current (rough) selection point - int selectionEnd = editor.textarea.getSelectionEnd(); - - // make sure the caret would be past the end of the text - if (strOut.length() < selectionEnd - 1) { - selectionEnd = strOut.length() - 1; - } - - // replace with new bootiful text - // selectionEnd hopefully at least in the neighborhood - editor.setText(strOut.toString(), selectionEnd, selectionEnd); - - editor.sketch.setModified(); - - bin.close(); // close buff - - } catch (IOException ioe) { - editor.error(ioe); - //ioe.printStackTrace(); - } - - - // () {} check - - String ck_paren = new String("left"); - if (paren < 0) ck_paren = "right"; - - if (paren != 0) { - setUhOh("Uh oh... too many " + ck_paren + " parentheses."); - - } else { // check braces only if parens are ok - ck_paren = "left"; - if (c_level < 0) { - ck_paren = "right"; - } else if (c_level != 0) { - setUhOh("Uh oh... too many " + ck_paren + " curled braces."); - } - } - } - - - /* throw back the stuff to the editor */ - public String getFormattedText() - { - return formattedText; - } - - /* special edition of put string for comment processing */ public void putcoms() { @@ -1008,4 +425,468 @@ public class AutoFormat { } return (1); } + + + public void show() { + StringBuffer onechar; + + theStuff = editor.textarea.getText(); + strOut = new StringBuffer(); + indentValue = Preferences.getInteger("editor.tabs.size"); + indentChar = new String(" "); + + lineNumber = 0; + BLOCK_MAXLEN = 256; + c_level = if_lev = level = e_flg = paren = 0; + a_flg = q_flg = j = b_flg = tabs = 0; + if_flg = peek = -1; + peekc = '`'; + s_flg = 1; + bblank = ' '; + jdoc = 0; + + s_level = new int[10]; + sp_flg = new int[20][10]; + s_ind = new int[20][10]; + s_if_lev = new int[10]; + s_if_flg = new int[10]; + ind = new int[10]; + p_flg = new int[10]; + s_tabs = new int[20][10]; + + w_else = new String ("else"); + w_if_ = new String ("if"); + w_for = new String ("for"); + w_ds = new String ("default"); + w_case = new String ("case"); + w_cpp_comment = new String ("//"); + w_jdoc = new String ("/**"); + line_feed = new String ("\n"); + + try { // opening input string + // open for input + ByteArrayInputStream in = + new ByteArrayInputStream(theStuff.getBytes()); + + // add buffering to that InputStream + bin = new BufferedInputStream(in); + + } catch(Exception e) { + System.out.println(e.toString()); + } + + // read as long as there is something to read + EOF = 0; // = 1 set in getchr when EOF + + bArray = new byte[BLOCK_MAXLEN]; + string = new char[BLOCK_MAXLEN]; + try { // the whole process + for (int ib = 0; ib < BLOCK_MAXLEN; ib++) bArray[ib] = '\0'; + + lineLength = nBytesRead = 0; + // read up a block - remember how many bytes read + nBytesRead = bin.read(bArray); + strBlock = new String(bArray); + + lineLength = nBytesRead; + lineNumber = 1; + indexBlock = -1; + j = 0; + while(EOF == 0) + { + c = getchr(); + switch(c) + { + default: + string[j++] = c; + if(c != ',') + { + l_char = c; + } + break; + + case ' ': + case '\t': + if(lookup(w_else) == 1) + { + gotelse(); + if(s_flg == 0 || j > 0)string[j++] = c; + indent_puts(); + s_flg = 0; + break; + } + if(s_flg == 0 || j > 0)string[j++] = c; + break; + + case '\r': // for MS Windows 95 + case '\n': + lineNumber++; + if (EOF==1) + { + break; + } + String j_string = new String(string); + + e_flg = lookup(w_else); + if(e_flg == 1) gotelse(); + if (lookup_com(w_cpp_comment) == 1) + { + if (string[j] == '\n') + { + string[j] = '\0'; + j--; + } + } + + indent_puts(); + fprintf(outfil, line_feed); + s_flg = 1; + if(e_flg == 1) + { + p_flg[level]++; + tabs++; + } + else + if(p_char == l_char) + { + a_flg = 1; + } + break; + + case '{': + if(lookup(w_else) == 1)gotelse(); + s_if_lev[c_level] = if_lev; + s_if_flg[c_level] = if_flg; + if_lev = if_flg = 0; + c_level++; + if(s_flg == 1 && p_flg[level] != 0) + { + p_flg[level]--; + tabs--; + } + string[j++] = c; + indent_puts(); + getnl() ; + indent_puts(); + fprintf(outfil,"\n"); + tabs++; + s_flg = 1; + if(p_flg[level] > 0) + { + ind[level] = 1; + level++; + s_level[level] = c_level; + } + break; + + case '}': + c_level--; + if (c_level < 0) + { + EOF = 1; + string[j++] = c; + indent_puts(); + break; + } + if((if_lev = s_if_lev[c_level]-1) < 0)if_lev = 0; + if_flg = s_if_flg[c_level]; + indent_puts(); + tabs--; + p_tabs(); + peekc = getchr(); + if( peekc == ';') + { + onechar = new StringBuffer(); + onechar.append(c); // } + onechar.append(';'); + fprintf(outfil, onechar.toString()); + peek = -1; + peekc = '`'; + } + else + { + onechar = new StringBuffer(); + onechar.append(c); + fprintf(outfil, onechar.toString()); + peek = 1; + } + getnl(); + indent_puts(); + fprintf(outfil,"\n"); + s_flg = 1; + if(c_level < s_level[level]) + if(level > 0) level--; + if(ind[level] != 0) + { + tabs -= p_flg[level]; + p_flg[level] = 0; + ind[level] = 0; + } + break; + + case '"': + case '\'': + string[j++] = c; + cc = getchr(); + while(cc != c) + { + // max. length of line should be 256 + string[j++] = cc; + + if(cc == '\\') + { + cc = string[j++] = getchr(); + } + if(cc == '\n') + { + lineNumber++; + indent_puts(); + s_flg = 1; + } + cc = getchr(); + + } + string[j++] = cc; + if(getnl() == 1) + { + l_char = cc; + peek = 1; + peekc = '\n'; + } + break; + case ';': + string[j++] = c; + indent_puts(); + if(p_flg[level] > 0 && ind[level] == 0) + { + tabs -= p_flg[level]; + p_flg[level] = 0; + } + getnl(); + indent_puts(); + fprintf(outfil,"\n"); + s_flg = 1; + if(if_lev > 0) + if(if_flg == 1) + { + if_lev--; + if_flg = 0; + } + else if_lev = 0; + break; + case '\\': + string[j++] = c; + string[j++] = getchr(); + break; + case '?': + q_flg = 1; + string[j++] = c; + break; + case ':': + string[j++] = c; + peekc = getchr(); + if(peekc == ':') + { + indent_puts(); + fprintf (outfil,":"); + peek = -1; + peekc = '`'; + break; + } + else + { + int double_colon = 0; + peek = 1; + } + + if(q_flg == 1) + { + q_flg = 0; + break; + } + if(lookup(w_ds) == 0 && lookup(w_case) == 0) + { + s_flg = 0; + indent_puts(); + } + else + { + tabs--; + indent_puts(); + tabs++; + } + peekc = getchr(); + if(peekc == ';') + { + fprintf(outfil,";"); + peek = -1; + peekc = '`'; + } + else + { + peek = 1; + } + getnl(); + indent_puts(); + fprintf(outfil,"\n"); + s_flg = 1; + break; + + case '/': + c0 = string[j]; + string[j++] = c; + peekc = getchr(); + + if(peekc == '/') + { + string[j++] = peekc; + peekc = '`'; + peek = -1; + cpp_comment(); + fprintf(outfil,"\n"); + break; + } + else + { + peek = 1; + } + + if(peekc != '*') { + break; + } + else + { + if (j > 0) string[j--] = '\0'; + if (j > 0) indent_puts(); + string[j++] = '/'; + string[j++] = '*'; + peek = -1; + peekc = '`'; + comment(); + break; + } + case '#': + string[j++] = c; + cc = getchr(); + while(cc != '\n') + { + string[j++] = cc; + cc = getchr(); + } + string[j++] = cc; + s_flg = 0; + indent_puts(); + s_flg = 1; + break; + case ')': + paren--; + if (paren < 0) + { + EOF = 1; + } + string[j++] = c; + indent_puts(); + if(getnl() == 1) + { + peekc = '\n'; + peek = 1; + if(paren != 0) + { + a_flg = 1; + } + else if(tabs > 0) + { + p_flg[level]++; + tabs++; + ind[level] = 0; + } + } + break; + case '(': + string[j++] = c; + paren++; + if ((lookup(w_for) == 1)) + { + c = get_string(); + while(c != ';') c = get_string(); + ct=0; + int for_done = 0; + while (for_done==0) + { + c = get_string(); + while(c != ')') + { + if(c == '(') ct++; + c = get_string(); + } + if(ct != 0) + { + ct--; + } + else for_done = 1; + } // endwhile for_done + paren--; + if (paren < 0) + { + EOF = 1; + } + indent_puts(); + if(getnl() == 1) + { + peekc = '\n'; + peek = 1; + p_flg[level]++; + tabs++; + ind[level] = 0; + } + break; + } + + if(lookup(w_if_) == 1) + { + indent_puts(); + s_tabs[c_level][if_lev] = tabs; + sp_flg[c_level][if_lev] = p_flg[level]; + s_ind[c_level][if_lev] = ind[level]; + if_lev++; + if_flg = 1; + } + } // end switch + + String j_string = new String(string); + + } // end while not EOF + + // save current (rough) selection point + int selectionEnd = editor.textarea.getSelectionEnd(); + + // make sure the caret would be past the end of the text + if (strOut.length() < selectionEnd - 1) { + selectionEnd = strOut.length() - 1; + } + + // replace with new bootiful text + // selectionEnd hopefully at least in the neighborhood + editor.setText(strOut.toString(), selectionEnd, selectionEnd); + + editor.sketch.setModified(); + + bin.close(); // close buff + + } catch (Exception e) { + editor.error(e); + } + + // warn user if there are too many parens in either direction + if (paren != 0) { + System.err.println("Warning: Too many " + + ((paren < 0) ? "right" : "left") + + " parentheses."); + + } else if (c_level != 0) { // check braces only if parens are ok + System.err.println("Warning: Too many " + + ((c_level < 0) ? "right" : "left") + + " curly braces."); + } + } } diff --git a/todo.txt b/todo.txt index 9000f7506..72f7723d9 100644 --- a/todo.txt +++ b/todo.txt @@ -13,6 +13,8 @@ X tweak linux version shell script to properly set directory name X http://dev.processing.org/bugs/show_bug.cgi?id=234 bugs in auto-format +X tools need to use a compound edit +X http://dev.processing.org/bugs/show_bug.cgi?id=139 X ArrayIndexOutOfBoundsException when trying to Auto Format X http://dev.processing.org/bugs/show_bug.cgi?id=110 _ autoformat mangling code @@ -506,8 +508,6 @@ _ getDefaultShortcut() -> returns the default shortcut this tools wants _ needs to be able to get current sketch code o getMenu() -> return non-null the tool is a submenu o no, bad idea.. don't want a zillion submenus on things -_ tools need to use a compound edit -_ http://dev.processing.org/bugs/show_bug.cgi?id=139 _ need a proper means to handle command keys for tools _ http://dev.processing.org/bugs/show_bug.cgi?id=140 _ make some kind of internal color picker