]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/new_gui.cxx
Launcher: Maintain aircraft selection better
[flightgear.git] / src / GUI / new_gui.cxx
index 28e463bc6b259da81838e2cb86b3e326147727c0..bb8eb52dba624941d88c664b9c1f198935811ff4 100644 (file)
 #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<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)
@@ -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
@@ -327,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();
@@ -378,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;
 }