X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FGUI%2Fnew_gui.cxx;h=bb8eb52dba624941d88c664b9c1f198935811ff4;hb=4befe0e6ea6b5f21119364f1175a0b6c8e97395c;hp=eff8bbe2fb3379078c7d1531c4e33ce1dab0da30;hpb=f56fa936d942cf06a044177e597e5bd1dcbb0dbc;p=flightgear.git diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx index eff8bbe2f..bb8eb52db 100644 --- a/src/GUI/new_gui.cxx +++ b/src/GUI/new_gui.cxx @@ -33,6 +33,10 @@ #include "FGCocoaMenuBar.hxx" #endif +#if defined(SG_WINDOWS) +#include "FGWindowsMenuBar.hxx" +#endif + #include "FGPUIDialog.hxx" #include "FGFontCache.hxx" #include "FGColor.hxx" @@ -52,18 +56,10 @@ using std::string; 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; } @@ -71,14 +67,38 @@ NewGUI::~NewGUI () 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 () { @@ -92,10 +112,30 @@ NewGUI::redraw () 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::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) @@ -107,15 +147,13 @@ NewGUI::reset (bool reload) setStyle(); unbind(); -#if !defined(SG_MAC) - _menubar.reset(new FGPUIMenuBar); -#endif if (reload) { _dialog_props.clear(); _dialog_names.clear(); init(); } else { + createMenuBarImplementation(); _menubar->init(); } @@ -129,14 +167,11 @@ NewGUI::reset (bool reload) void NewGUI::bind () { - fgTie("/sim/menubar/visibility", this, - &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible); } void NewGUI::unbind () { - fgUntie("/sim/menubar/visibility"); } void @@ -290,9 +325,15 @@ NewGUI::newDialog (SGPropertyNode* props) 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) { @@ -321,8 +362,10 @@ NewGUI::readDir (const SGPath& path) 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(); @@ -372,7 +415,7 @@ NewGUI::setStyle (void) void NewGUI::setupFont (SGPropertyNode *node) { - _font = globals->get_fontcache()->get(node); + _font = FGFontCache::instance()->get(node); puSetDefaultFonts(*_font, *_font); return; }