]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/new_gui.cxx
Melchior: Make line wrapping in textboxes configurable, and enable it by default
[flightgear.git] / src / GUI / new_gui.cxx
index 67edea6097ad7b1bcf6629bc44af4650f8a5c873..fce518055bbf85648093610d04729d5d3a5479e6 100644 (file)
@@ -5,12 +5,15 @@
 #include <plib/pu.h>
 #include <plib/ul.h>
 
-#include <simgear/misc/exception.hxx>
+#include <simgear/compiler.h>
+#include <simgear/structure/exception.hxx>
+
 #include <Main/fg_props.hxx>
 
 #include "menubar.hxx"
 #include "dialog.hxx"
 
+SG_USING_STD(map);
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -66,7 +69,9 @@ NewGUI::unbind ()
 void
 NewGUI::update (double delta_time_sec)
 {
-    // NO OP
+    map<string,FGDialog *>::iterator iter = _active_dialogs.begin();
+    for(/**/; iter != _active_dialogs.end(); iter++)
+        iter->second->update();
 }
 
 bool
@@ -76,7 +81,8 @@ NewGUI::showDialog (const string &name)
         SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
         return false;
     } else {
-        new FGDialog(_dialog_props[name]); // it will be deleted by a callback
+        if(!_active_dialogs[name])
+            _active_dialogs[name] = new FGDialog(_dialog_props[name]);
         return true;
     }
 }
@@ -84,13 +90,37 @@ NewGUI::showDialog (const string &name)
 bool
 NewGUI::closeActiveDialog ()
 {
-    if (_active_dialog == 0) {
+    if (_active_dialog == 0)
         return false;
-    } else {
-        delete _active_dialog;
-        _active_dialog = 0;
+
+    // Kill any entries in _active_dialogs...  Is there an STL
+    // algorithm to do (delete map entries by value, not key)?  I hate
+    // the STL :) -Andy
+    map<string,FGDialog *>::iterator iter = _active_dialogs.begin();
+    for(/**/; iter != _active_dialogs.end(); iter++) {
+        if(iter->second == _active_dialog) {
+            _active_dialogs.erase(iter);
+            // iter is no longer valid
+            break;
+        }
+    }
+
+    delete _active_dialog;
+    _active_dialog = 0;
+    return true;
+}
+
+bool
+NewGUI::closeDialog (const string& name)
+{
+    if(_active_dialogs.find(name) != _active_dialogs.end()) {
+        if(_active_dialog == _active_dialogs[name])
+            _active_dialog = 0;
+        delete _active_dialogs[name];
+        _active_dialogs.erase(name);
         return true;
     }
+    return false; // dialog wasn't open...
 }
 
 void
@@ -131,10 +161,6 @@ NewGUI::clear ()
 {
     delete _menubar;
     _menubar = 0;
-
-    map<string,SGPropertyNode *>::iterator it;
-    for (it = _dialog_props.begin(); it != _dialog_props.end(); it++)
-        delete it->second;
     _dialog_props.clear();
 }
 
@@ -151,6 +177,19 @@ test_extension (const char * path, const char * ext)
     return true;
 }
 
+void
+NewGUI::newDialog (SGPropertyNode* props)
+{
+    const char* cname = props->getStringValue("name");
+    if(!cname) {
+        SG_LOG(SG_GENERAL, SG_ALERT, "New dialog has no <name> property");
+        return;
+    }
+    string name = cname;
+    if(!_active_dialogs[name])
+        _dialog_props[name] = props;
+}
+
 void
 NewGUI::readDir (const char * path)
 {
@@ -174,22 +213,23 @@ NewGUI::readDir (const char * path)
             SGPropertyNode * props = new SGPropertyNode;
             try {
                 readProperties(subpath, props);
-            } catch (const sg_exception &ex) {
+            } catch (const sg_exception &) {
                 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
                        << subpath);
                 delete props;
                 continue;
             }
-            if (!props->hasValue("name")) {
+            SGPropertyNode *nameprop = props->getNode("name");
+            if (!nameprop) {
                 SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
                    << " has no name; skipping.");
                 delete props;
                 continue;
             }
-            string name = props->getStringValue("name");
-            SG_LOG(SG_INPUT, SG_BULK, "Saving dialog " << name);
-            if (_dialog_props[name] != 0)
-                delete _dialog_props[name];
+            string name = nameprop->getStringValue();
+            if (_dialog_props[name])
+                delete (SGPropertyNode *)_dialog_props[name];
+
             _dialog_props[name] = props;
         }
     }