]> git.mxchange.org Git - flightgear.git/commitdiff
property_list.cxx: in verbose mode (toggle with Ctrl-'.'-entry) also
authormfranz <mfranz>
Mon, 7 May 2007 14:29:40 +0000 (14:29 +0000)
committermfranz <mfranz>
Mon, 7 May 2007 14:29:40 +0000 (14:29 +0000)
  show "secret" values, that is: values of nodes with children. These
  can be used like all normal (leaf) properties, but their values were
  until now only shown in writeProperties() dumps. Also show the
  number of attached listeners. Example:    foo = 'bar' (string, AU, L3).

dialog.cxx: add warning message for broken <format>s; cosmetics

src/GUI/dialog.cxx
src/GUI/property_list.cxx
src/GUI/property_list.hxx

index 650961279890c6100d7531c1cb8c5ccded42953c..3dba907c3220c735980349892ec7feed762ed7c1 100644 (file)
@@ -4,14 +4,11 @@
 #  include "config.h"
 #endif
 
-#include <stdlib.h>            // atof()
-
 #include <Input/input.hxx>
 #include <Scripting/NasalSys.hxx>
 
 #include "dialog.hxx"
 #include "new_gui.hxx"
-
 #include "AirportList.hxx"
 #include "property_list.hxx"
 #include "layout.hxx"
@@ -164,7 +161,7 @@ int fgPopup::checkKey(int key, int updown)
 puObject *fgPopup::getKeyObject(puObject *object, int key)
 {
     puObject *ret;
-    if(object->getType() & PUCLASS_GROUP)
+    if (object->getType() & PUCLASS_GROUP)
         for (puObject *obj = ((puGroup *)object)->getFirstChild();
                 obj; obj = obj->getNextObject())
             if ((ret = getKeyObject(obj, key)))
@@ -180,7 +177,7 @@ puObject *fgPopup::getKeyObject(puObject *object, int key)
 puObject *fgPopup::getActiveInputField(puObject *object)
 {
     puObject *ret;
-    if(object->getType() & PUCLASS_GROUP)
+    if (object->getType() & PUCLASS_GROUP)
         for (puObject *obj = ((puGroup *)object)->getFirstChild();
                 obj; obj = obj->getNextObject())
             if ((ret = getActiveInputField(obj)))
@@ -199,7 +196,7 @@ int fgPopup::checkHit(int button, int updown, int x, int y)
 {
     int result = puPopup::checkHit(button, updown, x, y);
 
-    if ( !_draggable)
+    if (!_draggable)
        return result;
 
     // This is annoying.  We would really want a true result from the
@@ -208,12 +205,12 @@ int fgPopup::checkHit(int button, int updown, int x, int y)
     // intersection test (again) to make sure we don't start a drag
     // when inside controls.
 
-    if(updown == PU_DOWN && !_dragging) {
-        if(!result)
+    if (updown == PU_DOWN && !_dragging) {
+        if (!result)
             return 0;
 
         int hit = getHitObjects(this, x, y);
-        if(hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT))
+        if (hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT))
             return result;
 
         int px, py;
@@ -221,7 +218,7 @@ int fgPopup::checkHit(int button, int updown, int x, int y)
         _dragging = true;
         _dX = px - x;
         _dY = py - y;
-    } else if(updown == PU_DRAG && _dragging) {
+    } else if (updown == PU_DRAG && _dragging) {
         setPosition(x + _dX, y + _dY);
     } else {
         _dragging = false;
@@ -235,7 +232,7 @@ int fgPopup::getHitObjects(puObject *object, int x, int y)
         return 0;
 
     int type = 0;
-    if(object->getType() & PUCLASS_GROUP)
+    if (object->getType() & PUCLASS_GROUP)
         for (puObject *obj = ((puGroup *)object)->getFirstChild();
                 obj; obj = obj->getNextObject())
             type |= getHitObjects(obj, x, y);
@@ -243,7 +240,7 @@ int fgPopup::getHitObjects(puObject *object, int x, int y)
     int cx, cy, cw, ch;
     object->getAbsolutePosition(&cx, &cy);
     object->getSize(&cw, &ch);
-    if(x >= cx && x < cx + cw && y >= cy && y < cy + ch)
+    if (x >= cx && x < cx + cw && y >= cy && y < cy + ch)
         type |= object->getType();
     return type;
 }
@@ -288,11 +285,10 @@ copy_to_pui (SGPropertyNode * node, puObject * object)
     // from properties.
     if (object->getType() & PUCLASS_TEXT) {
         GUIInfo *info = (GUIInfo *)object->getUserData();
-        if (info && info->fmt_string) {
+        if (info && info->fmt_string)
             object->setLabel(info->format(node));
-        } else {
+        else
             object->setLabel(node->getStringValue());
-        }
         return;
     }
 
@@ -738,7 +734,7 @@ FGDialog::setupObject (puObject * object, SGPropertyNode * props)
 
         PropertyObject* po = new PropertyObject(name, object, node);
         _propertyObjects.push_back(po);
-        if(props->getBoolValue("live"))
+        if (props->getBoolValue("live"))
             _liveObjects.push_back(po);
     }
 
@@ -777,6 +773,9 @@ FGDialog::setupObject (puObject * object, SGPropertyNode * props)
                     info->text = new char[FORMAT_BUFSIZE + 1];
                     info->fmt_string = new char[strlen(format) + 1];
                     strcpy(info->fmt_string, format);
+                } else {
+                    SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
+                            << format << '\'');
                 }
             }
         }
index fd90fa94d129f20f89d3435c8c5d6da1d2c4d88f..6fd2736333525f8c45db0d629fc109edf7b9f459 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <simgear/compiler.h>
 
+#include <sstream>
 #include STL_IOMANIP
 #include STL_STRING
 SG_USING_STD(string);
@@ -41,7 +42,6 @@ typedef string stdString;      // puObject has a "string" member
 static string getValueTypeString(const SGPropertyNode *node)
 {
     string result;
-    assert(node);
 
     SGPropertyNode::Type type = node->getType();
     if (type == SGPropertyNode::UNSPECIFIED)
@@ -67,7 +67,7 @@ static string getValueTypeString(const SGPropertyNode *node)
 
 static void dumpProperties(const SGPropertyNode *node)
 {
-    cout << node->getPath() << "/" << endl;
+    cout << node->getPath() << '/' << endl;
     for (int i = 0; i < node->nChildren(); i++) {
         const SGPropertyNode *c = node->getChild(i);
         SGPropertyNode::Type type = c->getType();
@@ -149,7 +149,7 @@ PropertyList::PropertyList(int minx, int miny, int maxx, int maxy, SGPropertyNod
     _return(0),
     _entries(0),
     _num_entries(0),
-    _flags(false)
+    _verbose(false)
 
 {
     _list_box->setUserData(this);
@@ -193,7 +193,7 @@ void PropertyList::handle_select(puObject *list_box)
         if (prop_list->_dot_files && (selected < 2)) {
             if (!strcmp(src, ".")) {
                 if (mod_ctrl)
-                    prop_list->toggleFlags();
+                    prop_list->toggleVerbosity();
                 else if (mod_shift)
                     dumpProperties(prop_list->_curr);
 
@@ -218,7 +218,6 @@ void PropertyList::handle_select(puObject *list_box)
             selected -= 2;
 
         SGPropertyNode_ptr child = prop_list->_children[selected].node;
-        assert(child);
 
         // check if it's a directory
         if (child->nChildren()) {
@@ -278,18 +277,10 @@ void PropertyList::update(bool restore_pos)
 
     // Make lists of the children's names, values, etc.
     for (i = 0; i < _num_children; i++, pi++) {
-        SGPropertyNode *child = _children[i].node;
-
-        if (child->nChildren() > 0) {
-            stdString name = stdString(child->getDisplayName(true)) + '/';
-            _entries[pi] = new char[name.size() + 1];
-            strcpy(_entries[pi], name.c_str());
-
-        } else {
-            _entries[pi] = 0;       // make it delete-able
-            updateTextForEntry(i);
-            _children[i].setListener(this);
-        }
+        _children[i].text = &_entries[pi];
+        _entries[pi] = 0;    // make it deletable
+        updateTextForEntry(_children[i]);
+        _children[i].setListener(this);
     }
 
     _entries[_num_entries] = 0;
@@ -301,52 +292,63 @@ void PropertyList::update(bool restore_pos)
 }
 
 
-void PropertyList::updateTextForEntry(int index)
+void PropertyList::updateTextForEntry(NodeData& data)
 {
-    assert((index >= 0) && (index < _num_children));
-    SGPropertyNode_ptr node = _children[index].node;
-
+    SGPropertyNode *node = data.node;
     stdString name = node->getDisplayName(true);
     stdString type = getValueTypeString(node);
     stdString value = node->getStringValue();
 
-    if (node->getType() == SGPropertyNode::STRING
-            || node->getType() == SGPropertyNode::UNSPECIFIED)
-        sanitize(value);
-
-    stdString line = name + " = '" + value + "' (" + type;
-
-    if (_flags) {
-        stdString ext;
-        if (!node->getAttribute(SGPropertyNode::READ))
-            ext += 'r';
-        if (!node->getAttribute(SGPropertyNode::WRITE))
-            ext += 'w';
-        if (node->getAttribute(SGPropertyNode::TRACE_READ))
-            ext += 'R';
-        if (node->getAttribute(SGPropertyNode::TRACE_WRITE))
-            ext += 'W';
-        if (node->getAttribute(SGPropertyNode::ARCHIVE))
-            ext += 'A';
-        if (node->getAttribute(SGPropertyNode::USERARCHIVE))
-            ext += 'U';
-        if (node->isTied())
-            ext += 'T';
-        if (ext.size())
-            line += ", " + ext;
+    std::ostringstream line;
+    line << name;
+
+    int children = node->nChildren();
+    if (children)
+        line << '/';
+
+    if (!children || (_verbose && node->hasValue())) {
+        if (node->getType() == SGPropertyNode::STRING
+                || node->getType() == SGPropertyNode::UNSPECIFIED)
+            sanitize(value);
+
+        line << " = '" << value << "' (" << type;
+
+        if (_verbose) {
+            stdString ext;
+            if (!node->getAttribute(SGPropertyNode::READ))
+                ext += 'r';
+            if (!node->getAttribute(SGPropertyNode::WRITE))
+                ext += 'w';
+            if (node->getAttribute(SGPropertyNode::TRACE_READ))
+                ext += 'R';
+            if (node->getAttribute(SGPropertyNode::TRACE_WRITE))
+                ext += 'W';
+            if (node->getAttribute(SGPropertyNode::ARCHIVE))
+                ext += 'A';
+            if (node->getAttribute(SGPropertyNode::USERARCHIVE))
+                ext += 'U';
+            if (node->isTied())
+                ext += 'T';
+
+            if (!ext.empty())
+                line << ", " << ext;
+
+            int num = node->nListeners();
+            if (data.listener)
+                num--;
+            if (lst)
+                line << ", L" << num;
+        }
+        line << ')';
     }
 
-    line += ')';
-
-    if (line.size() >= PUSTRING_MAX)
-        line.resize(PUSTRING_MAX - 1);
-
-    if (_dot_files)
-        index += 2;
+    stdString out = line.str();
+    if (out.size() >= PUSTRING_MAX)
+        out.resize(PUSTRING_MAX - 1);
 
-    delete[] _entries[index];
-    _entries[index] = new char[line.size() + 1];
-    strcpy(_entries[index], line.c_str());
+    delete[] *data.text;
+    *data.text = new char[out.size() + 1];
+    strcpy(*data.text, out.c_str());
 }
 
 
@@ -354,7 +356,7 @@ void PropertyList::valueChanged(SGPropertyNode *nd)
 {
     for (int i = 0; i < _num_children; i++)
         if (_children[i].node == nd) {
-            updateTextForEntry(i);
+            updateTextForEntry(_children[i]);
             return;
         }
 }
index b7b522debff33aedd10a86621745b19b46f9d380..73808a25dffa63275af94098c18baea2e878aa5f 100644 (file)
@@ -39,7 +39,7 @@ public:
     void setCurrent(SGPropertyNode *p);
     SGPropertyNode *getCurrent() const { return _curr; }
     void publish(SGPropertyNode *p) { _return = p; invokeCallback(); }
-    void toggleFlags() { _flags = !_flags; }
+    void toggleVerbosity() { _verbose = !_verbose; }
 
     // overridden plib pui methods
     virtual char *getListStringValue() { return (char *)(_return ? _return->getPath(true) : ""); }
@@ -50,21 +50,6 @@ public:
     virtual void valueChanged(SGPropertyNode *node);
 
 private:
-    // update the text string in the puList using the given node and
-    // updating the requested offset. The value of dotFiles is taken
-    // into account before the index is applied, i.e this should be
-    // an index into 'children'
-    void updateTextForEntry(int index);
-    void delete_arrays();
-    static void handle_select(puObject *b);
-    static int nodeNameCompare(const void *, const void *);
-
-    SGPropertyNode_ptr _curr;
-    SGPropertyNode_ptr _return;
-
-    char **_entries;
-    int _num_entries;
-
     struct NodeData {
         NodeData() : listener(0) {}
         ~NodeData() {
@@ -76,12 +61,27 @@ private:
         }
         SGPropertyNode_ptr node;
         SGPropertyChangeListener *listener;
+        char **text;
     };
+
+    // update the text string in the puList using the given node and
+    // updating the requested offset.
+    void updateTextForEntry(NodeData&);
+    void delete_arrays();
+    static void handle_select(puObject *b);
+    static int nodeNameCompare(const void *, const void *);
+
+    SGPropertyNode_ptr _curr;
+    SGPropertyNode_ptr _return;
+
+    char **_entries;
+    int _num_entries;
+
     NodeData *_children;
     int _num_children;
 
     bool _dot_files;      // . and .. pseudo-dirs currently shown?
-    bool _flags;          // show SGPropertyNode flags
+    bool _verbose;        // show SGPropertyNode flags
 };