Avoid a crash when using the native menubar on Mac, due to non-static classes with identical names.
This commit is contained in:
parent
59253531bc
commit
4bde2451b0
2 changed files with 25 additions and 19 deletions
|
@ -109,23 +109,25 @@ static void setItemShortcutFromString(NSMenuItem* item, const string& s)
|
|||
[item setKeyEquivalentModifierMask:modifiers];
|
||||
}
|
||||
|
||||
class EnabledListener : public SGPropertyChangeListener
|
||||
{
|
||||
public:
|
||||
EnabledListener(NSMenuItem* i) :
|
||||
item(i)
|
||||
{}
|
||||
|
||||
|
||||
virtual void valueChanged(SGPropertyNode *node)
|
||||
namespace {
|
||||
class CocoaEnabledListener : public SGPropertyChangeListener
|
||||
{
|
||||
BOOL b = node->getBoolValue();
|
||||
[item setEnabled:b];
|
||||
}
|
||||
|
||||
private:
|
||||
NSMenuItem* item;
|
||||
};
|
||||
public:
|
||||
CocoaEnabledListener(NSMenuItem* i) :
|
||||
item(i)
|
||||
{}
|
||||
|
||||
|
||||
virtual void valueChanged(SGPropertyNode *node)
|
||||
{
|
||||
BOOL b = node->getBoolValue();
|
||||
[item setEnabled:b];
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -314,7 +314,9 @@ FGPUIMenuBar::make_object_map(SGPropertyNode * node)
|
|||
}
|
||||
}
|
||||
|
||||
struct EnabledListener : SGPropertyChangeListener {
|
||||
namespace {
|
||||
|
||||
struct EnabledListener : SGPropertyChangeListener {
|
||||
void valueChanged(SGPropertyNode *node) {
|
||||
NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
|
||||
if (!gui)
|
||||
|
@ -325,6 +327,8 @@ struct EnabledListener : SGPropertyChangeListener {
|
|||
}
|
||||
};
|
||||
|
||||
} // of anonymous namespace
|
||||
|
||||
void
|
||||
FGPUIMenuBar::add_enabled_listener(SGPropertyNode * node)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue