#include "FGCocoaMenuBar.hxx"
#endif
+#if defined(SG_WINDOWS)
+#include "FGWindowsMenuBar.hxx"
+#endif
+
#include "FGPUIDialog.hxx"
#include "FGFontCache.hxx"
#include "FGColor.hxx"
NewGUI::NewGUI () :
_active_dialog(0)
{
-#if defined(SG_MAC)
- if (fgGetBool("/sim/menubar/native", true)) {
- _menubar.reset(new FGCocoaMenuBar);
- return;
- }
-#endif
- _menubar.reset(new FGPUIMenuBar);
}
NewGUI::~NewGUI ()
{
- _dialog_props.clear();
for (_itt_t it = _colors.begin(); it != _colors.end(); ++it)
delete it->second;
}
void
NewGUI::init ()
{
+ createMenuBarImplementation();
+ fgTie("/sim/menubar/visibility", this,
+ &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible);
+
setStyle();
SGPath p(globals->get_fg_root(), "gui/dialogs");
readDir(p);
- const std::string aircraft_dir(fgGetString("/sim/aircraft-dir"));
- readDir( SGPath(aircraft_dir, "gui/dialogs") );
+
+ SGPath aircraftDialogDir(string(fgGetString("/sim/aircraft-dir")), "gui/dialogs");
+ if (aircraftDialogDir.exists()) {
+ readDir(aircraftDialogDir);
+ }
+
+ // Fix for http://code.google.com/p/flightgear-bugs/issues/detail?id=947
+ fgGetNode("sim/menubar")->setAttribute(SGPropertyNode::PRESERVE, true);
_menubar->init();
}
+void
+NewGUI::shutdown()
+{
+ DialogDict::iterator it = _active_dialogs.begin();
+ for (; it != _active_dialogs.end(); ++it) {
+ delete it->second;
+ }
+ _active_dialogs.clear();
+
+ fgUntie("/sim/menubar/visibility");
+ _menubar.reset();
+ _dialog_props.clear();
+}
+
void
NewGUI::reinit ()
{
reset(false);
}
+void
+NewGUI::createMenuBarImplementation()
+{
+#if defined(SG_MAC)
+ if (fgGetBool("/sim/menubar/native", true)) {
+ _menubar.reset(new FGCocoaMenuBar);
+ }
+#endif
+#if defined(SG_WINDOWS)
+ if (fgGetBool("/sim/menubar/native", true)) {
+ // Windows-native menubar disabled for the moment, fall-through
+ // to PUI version
+ // _menubar.reset(new FGWindowsMenuBar);
+ }
+#endif
+ if (!_menubar.get()) {
+ _menubar.reset(new FGPUIMenuBar);
+ }
+}
+
void
NewGUI::reset (bool reload)
{
- map<string,FGDialog *>::iterator iter;
+ DialogDict::iterator iter;
string_list openDialogs;
// close all open dialogs and remember them ...
for (iter = _active_dialogs.begin(); iter != _active_dialogs.end(); ++iter)
setStyle();
unbind();
-#if !defined(SG_MAC)
- _menubar.reset(new FGPUIMenuBar);
-#endif
if (reload) {
_dialog_props.clear();
_dialog_names.clear();
init();
} else {
+ createMenuBarImplementation();
_menubar->init();
}
void
NewGUI::bind ()
{
- fgTie("/sim/menubar/visibility", this,
- &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible);
}
void
NewGUI::unbind ()
{
- fgUntie("/sim/menubar/visibility");
}
void
NewGUI::update (double delta_time_sec)
{
+ SG_UNUSED(delta_time_sec);
map<string,FGDialog *>::iterator iter = _active_dialogs.begin();
for(/**/; iter != _active_dialogs.end(); iter++)
iter->second->update();
void
NewGUI::readDir (const SGPath& path)
{
+ simgear::Dir dir(path);
+ if( !dir.exists() )
+ {
+ SG_LOG(SG_INPUT, SG_INFO, "directory does not exist: " << path.str());
+ return;
+ }
+
flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
flightgear::NavDataCache::Transaction txn(cache);
- simgear::Dir dir(path);
simgear::PathList xmls = dir.children(simgear::Dir::TYPE_FILE, ".xml");
BOOST_FOREACH(SGPath xmlPath, xmls) {
string name = nameprop->getStringValue();
_dialog_names[name] = xmlPath;
// update cached values
- cache->stampCacheFile(xmlPath);
- cache->writeStringProperty(xmlPath.str(), name);
+ if (!cache->isReadOnly()) {
+ cache->stampCacheFile(xmlPath);
+ cache->writeStringProperty(xmlPath.str(), name);
+ }
} // of directory children iteration
txn.commit();
void
NewGUI::setupFont (SGPropertyNode *node)
{
- _font = globals->get_fontcache()->get(node);
+ _font = FGFontCache::instance()->get(node);
puSetDefaultFonts(*_font, *_font);
return;
}