How to create tools that tweak the PDE?
in
Library and Tool Development
•
1 year ago
With all the focus on Processing tools lately, I've been motivated to look into this. I have set a modest goal for my first tool (or so I thought
). The tool I want to develop is one that allows for other file extensions (besides pde and java) to be edited in the PDE. This means for example glsl-shaders (glsl, vert, frag), xml, txt etc. All kinds of files that are currently discarded by the PDE, but that actually would be very useful to edit within the PDE.
Route 1 - Hard coding it in the source code
To test the feasibility of my idea I took a hard coded shortcut, by changing 1 single line in Processing's original source code and compiling it myself with ant. Et voilà! It worked. I was able to edit txt and other files directly inside the PDE. For completeness, the line to change is in the getExtensions() function in JavaMode.java.
Of course, the above was just a test and not a long-term, flexible solution for multiple users. So I though this tiny tweak would be a perfect simple thing for a first entry in the world of tool development. Well, this is where my search starts...
Route 2 - An "add extensions" tool
I started by getting things up and running. I have succesfully built the tool template with Eclipse and the destructiveTool example. It works fine in the PDE. So I'm all set. Now I've been reading the Processing source code and javadocs for the Base, Editor, Sketch and SketchCode classes. Seems relevant. The tool I want to create is mainly related to the Sketch class. That class holds a SketchCode[] array of basically all the tabs you see in the PDE. When loading the files in the sketch directory, all the non pde/java files are discarded. What I want is to add these files as tabs in the PDE based on user-defined file extensions. The simplest route seemed to add them to the main SketchCode[] array, just like my hard-coded route 1 quickly facilitated. Now it's very easy to get the SketchCode's that are in the array or to get all the files in the sketch directory. But I don't want to only print the file names, I want to add them to the SketchCode[] array. However that is problematic. All the variables in this class are private (safe programming), but there are only getters and almost no setters. In short, I'm having a hard time realising my goal. I tried a couple of things, but in the end, met the above described wall.
So this leads me to my two questions:
Route 1 - Hard coding it in the source code
To test the feasibility of my idea I took a hard coded shortcut, by changing 1 single line in Processing's original source code and compiling it myself with ant. Et voilà! It worked. I was able to edit txt and other files directly inside the PDE. For completeness, the line to change is in the getExtensions() function in JavaMode.java.
- public String[] getExtensions() {
- return new String[] { "pde", "java" }; // hard code other file extensions here
- }
Of course, the above was just a test and not a long-term, flexible solution for multiple users. So I though this tiny tweak would be a perfect simple thing for a first entry in the world of tool development. Well, this is where my search starts...
Route 2 - An "add extensions" tool
I started by getting things up and running. I have succesfully built the tool template with Eclipse and the destructiveTool example. It works fine in the PDE. So I'm all set. Now I've been reading the Processing source code and javadocs for the Base, Editor, Sketch and SketchCode classes. Seems relevant. The tool I want to create is mainly related to the Sketch class. That class holds a SketchCode[] array of basically all the tabs you see in the PDE. When loading the files in the sketch directory, all the non pde/java files are discarded. What I want is to add these files as tabs in the PDE based on user-defined file extensions. The simplest route seemed to add them to the main SketchCode[] array, just like my hard-coded route 1 quickly facilitated. Now it's very easy to get the SketchCode's that are in the array or to get all the files in the sketch directory. But I don't want to only print the file names, I want to add them to the SketchCode[] array. However that is problematic. All the variables in this class are private (safe programming), but there are only getters and almost no setters. In short, I'm having a hard time realising my goal. I tried a couple of things, but in the end, met the above described wall.
So this leads me to my two questions:
- Are user-created tools allowed to tweak the PDE in areas usually handled by the original source code?
- If this is allowed, how would I be able to realise my intended tool given the restrictions described?
Let me know what you think guys.
1