Noob question - UserButtonCode


#1

hello everyone.

i just started to have a look at the jucer.
nice tool, but there is something i don’t get.

as i understand i should be able to alter the code between the “user” tags
and it shouldn’t be touched if i reedit the file inside the jucer.

but when i add some code like this

if (buttonThatWasClicked == mGenerateButton) { //[UserButtonCode_mGenerateButton] -- add your button handler code here.. int foo = 1; //[/UserButtonCode_mGenerateButton] }

the jucer just deletes my changes when i open the file and resave it (even without any changes made inside the jucer.)

same for

//[Headers] -- You can add your own extra header files here -- //#include "juce.h" #include "includes.h" #include "myHeader.h" //[/Headers]

am i missing something?

Cheers,
comboy


#2

It does work, I use it all the time. You did save your changes, right? You’re not just sitting there with a code editor open and not saved?

The only time it’ll remove the content is if you remove the item that the code refers to - e.g. the if you take away the button, it’ll delete the button’s callback code.


#3

hmmm - i even tried “save as” and used a new filename.

i create a new file with the jucer
save it as comp1.cpp
close the jucer
make a change as described above
save the changes
open the jucer again
open changed file comp1.cpp
click “save as” comp2.cpp

now i have 2 file.
freshly opened in an editor.
comp1.cpp contains the changes
my changes in comp 2 are gone.

maybe i’ll try a fresh rebuild

edit: just tried it again with another freshly build version - with the same results
i tried juce 1.47 and 1.5 both in debug version

running kubuntu 9.10 kde4

so long,
comboy


#4

using the prebuild win version with wine has the same results.
i think i’ll reboot to windows and try it there…

here is an excerpt of the source file i use and modified
maybe i did smth. wrong there?

[code]//==============================================================================
void NewJucerComponent::paint (Graphics& g)
{
//[UserPrePaint] Add your own custom painting code here…
//[/UserPrePaint]

g.fillAll (Colours::white);

//[UserPaint] Add your own custom painting code here..
//[/UserPaint]

}

void NewJucerComponent::resized()
{
//[UserResized] Add your own custom resize handling here…
int foo = 1;
//[/UserResized]
}
[/code]


#5

Ah, the way it works is:

  • when you save a jucer file over an existing one, it opens the existing one and merges your changes from that into the resulting file
  • when you “save as” to somewhere else, there’s nothing there to read, so it’ll just save a a default file.

That could probably be improved, but the logic behind it is trickier than it sounds. I’m going to re-think it all for Jucer v2 anyway.


#6

it seems it’s the save as function
when i just hit save it seems to work, but the save as function erases all my changes

edit: hehehe just figured it out :wink:
best regards,
comboy


#7

why not just remember the name of the original file and compare against that on save as?

anyways - thanks for the help :slight_smile: