MenuItemBindings itemBindings;
};
+// prior to the 10.6 SDK, NSMenuDelegate was an informal protocol
+#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1060
+@protocol NSMenuDelegate <NSObject>
+@end
+#endif
@interface CocoaMenuDelegate : NSObject <NSMenuDelegate> {
@private
[item setKeyEquivalentModifierMask:modifiers];
}
-class EnabledListener : public SGPropertyChangeListener
-{
-public:
- EnabledListener(NSMenuItem* i) :
- item(i)
- {}
-
-
- virtual void valueChanged(SGPropertyNode *node)
+namespace {
+ class CocoaAutoreleasePool
{
- BOOL b = node->getBoolValue();
- [item setEnabled:b];
- }
+ public:
+ CocoaAutoreleasePool()
+ {
+ pool = [[NSAutoreleasePool alloc] init];
+ }
+
+ ~CocoaAutoreleasePool()
+ {
+ [pool release];
+ }
+
+ private:
+ NSAutoreleasePool* pool;
+ };
-private:
- NSMenuItem* item;
-};
-
-
+ class CocoaEnabledListener : public SGPropertyChangeListener
+ {
+ public:
+ CocoaEnabledListener(NSMenuItem* i) :
+ item(i)
+ {}
+
+
+ virtual void valueChanged(SGPropertyNode *node)
+ {
+ CocoaAutoreleasePool pool;
+ BOOL b = node->getBoolValue();
+ [item setEnabled:b];
+ }
+
+ private:
+ NSMenuItem* item;
+ };
+} // of anonymous namespace
FGCocoaMenuBar::CocoaMenuBarPrivate::CocoaMenuBarPrivate()
{
FGCocoaMenuBar::CocoaMenuBarPrivate::~CocoaMenuBarPrivate()
{
+ CocoaAutoreleasePool pool;
[delegate release];
}
n->setBoolValue("enabled", true);
}
- string shortcut;
- string l = n->getStringValue("label");
- string::size_type pos = l.find("(");
- if (pos != string::npos) {
- string full(l);
- l = full.substr(0, pos);
- shortcut = full.substr(pos + 1, full.size() - (pos + 2));
- }
-
+ string l = getLocalizedLabel(n);
NSString* label = stdStringToCocoa(strutils::simplify(l));
+ string shortcut = n->getStringValue("key");
NSMenuItem* item;
if (index >= [menu numberOfItems]) {
setItemShortcutFromString(item, shortcut);
}
- n->getNode("enabled")->addChangeListener(new EnabledListener(item));
+ n->getNode("enabled")->addChangeListener(new CocoaEnabledListener(item));
[item setTarget:delegate];
[item setAction:@selector(itemAction:)];
}
void FGCocoaMenuBar::init()
{
+ CocoaAutoreleasePool pool;
+
NSMenu* mainBar = [[NSApplication sharedApplication] mainMenu];
SGPropertyNode_ptr props = fgGetNode("/sim/menubar/default",true);
}
BOOST_FOREACH(SGPropertyNode_ptr n, props->getChildren("menu")) {
- NSString* label = stdStringToCocoa(n->getStringValue("label"));
+ NSString* label = stdStringToCocoa(getLocalizedLabel(n));
NSMenuItem* item = [mainBar itemWithTitle:label];
NSMenu* menu;
p->menuFromProps(menu, n);
++index;
previousMenu = item;
+
+ // track menu enable/disable state
+ if (!n->hasValue("enabled")) {
+ n->setBoolValue("enabled", true);
+ }
+
+ n->getNode("enabled")->addChangeListener(new CocoaEnabledListener(item));
}
}
{
// no-op
}
+
+void cocoaOpenUrl(const std::string& url)
+{
+ CocoaAutoreleasePool pool;
+ NSURL* nsu = [NSURL URLWithString:stdStringToCocoa(url)];
+ [[NSWorkspace sharedWorkspace] openURL:nsu];
+}