1
0
Fork 0

Avoid a crash when using the native menubar on Mac, due to non-static classes with identical names.

This commit is contained in:
James Turner 2012-03-26 17:38:09 +01:00
parent 59253531bc
commit 4bde2451b0
2 changed files with 25 additions and 19 deletions

View file

@ -109,10 +109,11 @@ static void setItemShortcutFromString(NSMenuItem* item, const string& s)
[item setKeyEquivalentModifierMask:modifiers];
}
class EnabledListener : public SGPropertyChangeListener
namespace {
class CocoaEnabledListener : public SGPropertyChangeListener
{
public:
EnabledListener(NSMenuItem* i) :
CocoaEnabledListener(NSMenuItem* i) :
item(i)
{}
@ -126,6 +127,7 @@ public:
private:
NSMenuItem* item;
};
} // of anonymous namespace
FGCocoaMenuBar::CocoaMenuBarPrivate::CocoaMenuBarPrivate()
{
@ -173,7 +175,7 @@ void FGCocoaMenuBar::CocoaMenuBarPrivate::menuFromProps(NSMenu* menu, SGProperty
setItemShortcutFromString(item, shortcut);
}
n->getNode("enabled")->addChangeListener(new EnabledListener(item));
n->getNode("enabled")->addChangeListener(new CocoaEnabledListener(item));
[item setTarget:delegate];
[item setAction:@selector(itemAction:)];
}
@ -263,7 +265,7 @@ void FGCocoaMenuBar::init()
n->setBoolValue("enabled", true);
}
n->getNode("enabled")->addChangeListener(new EnabledListener(item));
n->getNode("enabled")->addChangeListener(new CocoaEnabledListener(item));
}
}

View file

@ -314,6 +314,8 @@ FGPUIMenuBar::make_object_map(SGPropertyNode * node)
}
}
namespace {
struct EnabledListener : SGPropertyChangeListener {
void valueChanged(SGPropertyNode *node) {
NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
@ -325,6 +327,8 @@ struct EnabledListener : SGPropertyChangeListener {
}
};
} // of anonymous namespace
void
FGPUIMenuBar::add_enabled_listener(SGPropertyNode * node)
{