Projucer - create my own user code zones


#1

Hi,

as we know Projucer allows to write custom code (headers, pre and post constructors…), in order to avoid this code to be erased when changes are made and file re-generated.
I would like to add custom code in other zones of the code, where tags were not originally put.

Is it possible?

Thanks

Nathaniel


#2

Yes, you can create your own template file - there’s an option for this in the GUI editor’s class settings page, IIRC.


#3

template file??
I am not sure I got you…

I only need to know if there is some kind of general

//[Headers] You can add your own extra header files here...
//[/Headers]

that would allow me to add custom code at other places in the files, with no risk to be overriden


#4

Yes, you can do that by creating your own version of the template file that the projucer uses for your component.

Have a look at the existing templates as an example, e.g. https://github.com/julianstorer/JUCE/blob/master/extras/Projucer/Source/BinaryData/jucer_ComponentTemplate.cpp


#5

ooook, got it

does it mean I need to compile projucer with this modified template?


#6

No - I think each GUI component can have its own template file specified in its settings.


#7

Ok indeed I see that in the class tab of the gui editor for given component, in General Class Settings, we have a field “Template File”, what is it expecting from me? Path for a cpp template file? or other format?


#8

The reason I sent you that link and told you to look at that file is because that’s the format it uses.


#9

ok so just to close this thread, I have investigated the projucer code, and got to the conclusion that we simply need to create 2 files myTemplate.cpp and myTemplate.h (same names required), and put them in the same directory as the concerned component file.

Then in the component settings (in the GUI editor) you simply input the myTemplate (with no extension)

save the whole, and the new field magically appears now in our auto-generated file

Great!!

thanks for help man!

Nathaniel


#10

Is there a way to change the template used by all components ?

I modified JUCE\extras\Projucer\Source\BinaryData\jucer_ComponentTemplate.cpp and jucer_ComponentTemplate…h but the ProJucer seems to ignore my changes …

Or if it’s not possible could you please add the old jucer back in the Juce repo ? Because that’s something it could do …


#11

Maybe for this, you need to recompile the Jucer, so your changes will be taken into account?