Jucer deletes MiscUserCode


#1

Jucer 1.12 deletes the code enclosed by
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here…
//[/MiscUserCode]

[code]//[MiscUserCode] You can add your own definitions of your custom methods or any other code here…

//================================================================================================
// MenuBarModel methods
//================================================================================================

const StringArray ContentComponent::getMenuBarNames()
{
if (LocalisedStrings::getCurrentMappings() != 0)
{
const tchar* const names[] = {TRANS(“File”), TRANS(“Help”), 0};
return StringArray ((const tchar**) names);
}
else
{
const tchar* const names[] = {T(“File”), T(“Help”), 0};
return StringArray ((const tchar**) names);
}
//StringArray stringArray;
}

const PopupMenu ContentComponent::getMenuForIndex (int menuIndex, const String& menuName)
{
ApplicationCommandManager* const commandManager = commandManager_;

PopupMenu menu;

if (menuIndex == 0)
{
	menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit);
}
else if (menuIndex == 1)
{
	menu.addCommandItem (commandManager, showAbout);
}

return menu;

}

void ContentComponent::menuItemSelected (int menuItemID, int topLevelMenuIndex)
{
// All our menu items are invoked automatically as commands, so no need to do
// anything in this callback.
}

//================================================================================================
// CommandManager methods
//================================================================================================

ApplicationCommandTarget* ContentComponent::getNextCommandTarget()
{
// This will return the next parent component that is an ApplicationCommandTarget (in this
// case, there probably isn’t one, but it’s best to use this method in your own apps).
return findFirstTargetParentComponent();
}

void ContentComponent::getAllCommands (Array & commands)
{
const CommandID ids[] =
{
showAbout
#if JUCE_MAC
, useNativeMenus
#endif
};
commands.addArray (ids, numElementsInArray (ids));
}

void ContentComponent::getCommandInfo (const CommandID commandId, ApplicationCommandInfo& result)
{
const String generalCategory (TRANS(“General”));
switch (commandId)
{
#if JUCE_MAC
case useNativeMenus:
result.setInfo (T(“Use the native OSX menu bar”), String::empty, generalCategory, 0);
result.setTicked (MenuBarModel::getMacMainMenu() != 0);
break;
#endif

		case showAbout:
			result.setInfo (TRANS("About") + T(" Virtual Filharmonia"), String::empty, generalCategory, 0);
			break;

		default:
			break;
};

}

bool ContentComponent::perform (const InvocationInfo& info)
{
switch (info.commandID)
{
#if JUCE_MAC
case useNativeMenus:
if (MenuBarModel::getMacMainMenu() != 0)
{
MenuBarModel::setMacMainMenu (0);
mainWindow_->setMenuBar ((ContentComponent*) mainWindow_->getContentComponent());
}
else
MenuBarModel::setMacMainMenu ((ContentComponent*) mainWindow_->getContentComponent());
mainWindow_->setMenuBar (0);
break;
#endif

		case showAbout:
			{
				AlertWindow aboutWindow (TRANS("Virtual Filharmonia"),
					TRANS("Version %VERS\n\n").replace ("%VERS", JUCEApplication::getInstance()->getApplicationVersion()) +
					TRANS("Written by") + T(" Nickie Fønshauge\n") +
					T("Copyright ©2010. ") + TRANS("All rights reserved"),
					AlertWindow::NoIcon);
				aboutWindow.addButton (TRANS("ok"), 1, KeyPress (KeyPress::returnKey), KeyPress (KeyPress::escapeKey));
				DBG (T("About"));
			}
			break;

		default:
			return false;
};

return true;

}

//=============================================================================================

int ContentComponent::getMinWidth()
{
int minWidth;
minWidth = getThisMinWidth();
minWidth = (minWidth < foyerComponent_->getMinWidth()) ? foyerComponent_->getMinWidth() : minWidth;
/minWidth = (minWidth < instrumentMakerComponent_->getMinWidth()) ? instrumentMakerComponent_->getMinWidth() : minWidth;
minWidth = (minWidth < janitorComponent_->getMinWidth()) ? janitorComponent_->getMinWidth() : minWidth;
minWidth = (minWidth < quickJumpComponent_->getMinWidth() +
mainCpuMeter_->getMinWidth()) ? quickJumpComponent_->getMinWidth() +
mainCpuMeter_->getMinWidth() : minWidth;
/
//DBG (T("Content Component: minWidth = ") + String(minWidth));
return minWidth;
}

int ContentComponent::getMinHeight()
{
int minHeight = 0;
minHeight = (minHeight < foyerComponent_->getMinHeight()) ? foyerComponent_->getMinHeight() : minHeight;
/minHeight = (minHeight < instrumentMakerComponent_->getMinHeight()) ? instrumentMakerComponent_->getMinHeight() : minHeight;
minHeight = (minHeight < janitorComponent_->getMinHeight()) ? janitorComponent_->getMinHeight() : minHeight;
minHeight = (minHeight < mainCpuMeter_->getMinHeight()) ? mainCpuMeter_->getMinHeight() : minHeight;
/
minHeight = (minHeight < getThisMinHeight()) ? getThisMinHeight() : minHeight;
//minHeight = getThisMinHeight();
//minHeight += quickJumpComponent_->getMinHeight();
return minHeight;
}

//[/MiscUserCode]
[/code]
Any idea why?


#2

I’m pretty sure that it doesn’t lose any code…

Does this thread help?
http://www.rawmaterialsoftware.com/viewtopic.php?f=7&t=5415&p=29501#p29501


#3

No, not really. I had already read that thread.
Let me refrase it then: It doesn’t delete the code, it just doesn’t salvage it, when saving.

Here’s what I did:
[list][]I created a component with Jucer and saved it, but kept the component open in Jucer[/]
[]I then opened the files in VS 2008 Express[/]
[]Added some extra code in the [][/] locations[/]
[
]Saved both the .h and the .cpp file in VS[/
]
[
]Edited the component in Jucer and resaved it[/
]
[]Reloaded both files in VS[/][/list]

and then the code I showed you was gone. It worked OK in other places of the same and other components, though. That’s what’s puzzling me.


#4

I’ve got dozens of jucer files that contain code in the miscusercode section and I’ve never lost any… Maybe you didn’t actually save it in VS?


#5

Hmmm, I was going to try again, but now it tells me that

[quote]Failed to open file…
This wasn’t a valid Jucer .cpp file…[/quote]
:?: :?: :?:

And before you ask: I did not touch the Jucer meta data.

But, I am sure I did save both files.

[color=#BF4000]Edit[/color]: If I remove the MiscUser code and save the .cpp file I can open it in Jucer. But if I put the code back in the .cpp file (VS) and save it (I actually closed the tab to make absolutely sure it was saved) and resave the Jucer component, next time I open the .cpp file the MiscUser code is gone again. Definitely something fishy going on here.

[color=#BF4040]Edit Edit[/color]Just for the fun of it: I created a new empty Jucer component, opened the .cpp file in VS and pasted the offending code into it. Same old story again.


#6

I should have guessed. It’s the Danish letter “ø” - again! :roll:

No Unicode support, I suppose.


#7

In America, there is a law that all software engineers must have ASCII-only names.

(I’m kidding - at least, today I’m kidding.)

I’m going to start a new thread about Unicode on the main forum. Stay tuned!


#8

…no, it definitely does support unicode - all juce strings are unicode, and it’ll treat the code file as utf8. Maybe you can give me a step-by-step guide to reproducing this?


#9

Sure. Create a new, empty Jucer component, save it (whithout closing it), open it in your code editor and insert

void NewJucerComponent::doSomething ()
{
	DBG(T("ø"));
}

in the [MiscUserCode][/MiscUserCode] section of the .cpp file. Save the .cpp file, save the Jucer component and finally reopen the .cpp file in the code editor. The [MiscUserCode][/MiscUserCode] section is now empty.


#10

Tried it on my mac and it worked just fine. Maybe your code editor is saving the file as wide unicode rather than utf8? If it did that, the jucer would probably fail to parse it correctly…


#11

Bingo! It was using “Western European (Windows) - Codepage 1252”. When I changed it to UTF-8 the code was retained. Thanks a bunch! :smiley:

Now, I am wondering if my other problem with translation files has a similarly simple solution.