Get the code from the editor in a tool?

I want to get the code from Processings editor for my tool. I can't find too much documentation on this but I know its using the processing.app.Editor. Any help?

Answers

  • edited May 2014

    You can use editor.getText(); to get the code in a tool. Is that what you wanted?

  • That just gets the code in the selected tab. I want the whole code in every tab. Any more help?

  • edited May 2014 Answer ✓

    Processing PDE organises program code by tabs and this is reflected in the API.

    Start with the Editor class object

    Editor editor;
    

    Then get the current sketch

    Sketch sketch = editor.getSketch();
    

    Then find out the number of tabs

    int nbrTabs = sketch.getCodeCount();
    

    Then iterator over each tab get the code and do something with it.

    SketchCode sketchCode;
    String tabText;
    for(int i = 0; i < nbrTabs; i++){
      sketchCode = sketch.getCode(i);
      tabText = sketchCode.getProgram();
      System.out.println(tabText);
    }
    

    NOTE: code was typed straight into comment so maybe syntax errors

  • edited May 2014

    Thanks quark that helped :)

    EDIT: nope 0 errors good job

Sign In or Register to comment.