]> git.mxchange.org Git - flightgear.git/commitdiff
Instead of reading $FG_ROOT/gui.xml, recursively read all files under
authordavid <david>
Fri, 8 Nov 2002 02:03:56 +0000 (02:03 +0000)
committerdavid <david>
Fri, 8 Nov 2002 02:03:56 +0000 (02:03 +0000)
the $FG_ROOT/gui/ directory; that way, each dialog can have a separate
configuration file, and management should be simpler.

src/GUI/new_gui.cxx
src/GUI/new_gui.hxx

index 656fc2a2aa2c806eca4b4a56f93bce988457cddc..cff4527ae92db75d576c6de8caef5ca5ae7e306d 100644 (file)
@@ -3,6 +3,7 @@
 #include "new_gui.hxx"
 
 #include <plib/pu.h>
+#include <plib/ul.h>
 
 #include <vector>
 SG_USING_STD(vector);
@@ -66,28 +67,11 @@ NewGUI::~NewGUI ()
 void
 NewGUI::init ()
 {
-    SGPropertyNode props;
-
-    try {
-        fgLoadProps("gui.xml", &props);
-    } catch (const sg_exception &ex) {
-        SG_LOG(SG_INPUT, SG_ALERT, "Error parsing gui.xml: "
-               << ex.getMessage());
-        return;
-    }
-
-    int nChildren = props.nChildren();
-    for (int i = 0; i < nChildren; i++) {
-        SGPropertyNode_ptr child = props.getChild(i);
-        if (!child->hasValue("name")) {
-            SG_LOG(SG_INPUT, SG_WARN, "GUI node " << child->getName()
-                   << " has no name; skipping.");
-        } else {
-            string name = child->getStringValue("name");
-            SG_LOG(SG_INPUT, SG_BULK, "Saving GUI node " << name);
-            _objects[name] = child;
-        }
-    }
+    char path[1024];
+    ulMakePath(path, getenv("FG_ROOT"), "gui");
+    std::cerr << "Reading from " << path << std::endl;
+    readDir(path);
+    std::cerr << "Done reading from " << path << std::endl;
 }
 
 void
@@ -148,6 +132,49 @@ NewGUI::closeActiveObject ()
     _propertyObjects.clear();
 }
 
+void
+NewGUI::readDir (const char * path)
+{
+    ulDir * dir = ulOpenDir(path);
+    std::cerr << "Directory opened successfully" << std::endl;
+
+    if (dir == 0) {
+        SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
+               << path);
+        return;
+    }
+
+    ulDirEnt * dirEnt = ulReadDir(dir);
+    while (dirEnt != 0) {
+        char subpath[1024];
+
+        ulMakePath(subpath, path, dirEnt->d_name);
+
+        std::cerr << "Subpath is " << subpath << std::endl;
+        if (dirEnt->d_isdir && dirEnt->d_name[0] != '.') {
+            readDir(subpath);
+        } else {
+            SGPropertyNode_ptr props = new SGPropertyNode;
+            try {
+                readProperties(subpath, props);
+            } catch (const sg_exception &ex) {
+                SG_LOG(SG_INPUT, SG_ALERT, "Error parsing GUI file "
+                       << subpath);
+            }
+            if (!props->hasValue("name")) {
+                SG_LOG(SG_INPUT, SG_WARN, "GUI file " << subpath
+                   << " has no name; skipping.");
+            } else {
+                string name = props->getStringValue("name");
+                SG_LOG(SG_INPUT, SG_BULK, "Saving GUI node " << name);
+                _objects[name] = props;
+            }
+        }
+        dirEnt = ulReadDir(dir);
+    }
+    ulCloseDir(dir);
+}
+
 puObject *
 NewGUI::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
 {
@@ -158,6 +185,12 @@ NewGUI::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
     int y = props->getIntValue("y", (parentHeight - height) / 2);
 
     string type = props->getName();
+    if (type == "")
+        type = props->getStringValue("type");
+    if (type == "") {
+        SG_LOG(SG_GENERAL, SG_ALERT, "No type specified for GUI object");
+        return 0;
+    }
 
     if (type == "dialog") {
         puPopup * dialog;
index 1c2f455af3ffefb530e3a622a52a51b19778b2cd..f950c0a66a14529eeaa3d4c7692639bd0bdee5b6 100644 (file)
@@ -36,6 +36,8 @@ public:
 
 private:
 
+    void readDir (const char * path);
+
     puObject * makeObject (SGPropertyNode * props,
                            int parentWidth, int parentHeight);