Making generated code visible in a tab
in
Library and Tool Development
•
2 years ago
I am currently working on a tool that generates code and places it in a secondary tab that has already been created.
I am using the SketchCode method setProgram(String replacement) to replace the existing code with new code and then saving the tab but the new code does not show in the Processing IDE even though it is changed on disk. If I close the Processing editor and reopen the sketch the new code appears.
This is the source code I am creating
Line 3 : gets the SketchCode for the code tab previously created
Line 4 : displays the current program
Line 6 : changes the program for this tab
Line 8 : displays the new program (successfully)
Line 10: saves the new program
Line 16 loads the new program (my attempt to force a refresh of the tab text - unsuccessful)
So the question is what do I need to do to refresh the editor display to show the changed program text?
I am using the SketchCode method setProgram(String replacement) to replace the existing code with new code and then saving the tab but the new code does not show in the Processing IDE even though it is changed on disk. If I close the Processing editor and reopen the sketch the new code appears.
This is the source code I am creating
Line 3 : gets the SketchCode for the code tab previously created
Line 4 : displays the current program
Line 6 : changes the program for this tab
Line 8 : displays the new program (successfully)
Line 10: saves the new program
Line 16 loads the new program (my attempt to force a refresh of the tab text - unsuccessful)
So the question is what do I need to do to refresh the editor display to show the changed program text?
- public void generateCode(){
- Sketch sketch = editor.getSketch();
- SketchCode gui_tab = getTab(sketch, PDE_TAB_PRETTY_NAME);
- System.out.println("==================================================");
- System.out.println(gui_tab.getProgram());
- gui_tab.setProgram("generated code"); // dummy code for test
- System.out.println("==================================================");
- System.out.println(gui_tab.getProgram());
- try {
- gui_tab.save();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- gui_tab.load();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //DBase DBase = tree.getRoot();
- }
1