#include <simgear/compiler.h>
+#include <sstream>
+#include STL_IOMANIP
#include STL_STRING
SG_USING_STD(string);
typedef string stdString; // puObject has a "string" member
{
string result;
- if (!node)
- return "unknown";
-
SGPropertyNode::Type type = node->getType();
if (type == SGPropertyNode::UNSPECIFIED)
result = "unspecified";
}
+static void dumpProperties(const SGPropertyNode *node)
+{
+ cout << node->getPath() << '/' << endl;
+ for (int i = 0; i < node->nChildren(); i++) {
+ const SGPropertyNode *c = node->getChild(i);
+ SGPropertyNode::Type type = c->getType();
+ if (type == SGPropertyNode::ALIAS || c->nChildren())
+ continue;
+
+ int index = c->getIndex();
+ cout << std::setw(11) << getValueTypeString(c) << " " << c->getName();
+ if (index > 0)
+ cout << '[' << index << ']';
+ cout << " = ";
+
+ switch (c->getType()) {
+ case SGPropertyNode::DOUBLE:
+ case SGPropertyNode::FLOAT:
+ cout << std::setprecision(15) << c->getDoubleValue();
+ break;
+ case SGPropertyNode::LONG:
+ case SGPropertyNode::INT:
+ cout << c->getLongValue();
+ break;
+ case SGPropertyNode::BOOL:
+ cout << (c->getBoolValue() ? "true" : "false");
+ break;
+ case SGPropertyNode::STRING:
+ cout << '"' << c->getStringValue() << '"';
+ break;
+ case SGPropertyNode::NONE:
+ break;
+ default:
+ cout << '\'' << c->getStringValue() << '\'';
+ }
+ cout << endl;
+ }
+ cout << endl;
+}
+
+
static void sanitize(stdString& s)
{
stdString r = s;
s += "\'";
else if (r[i] == '\\')
s += "\\";
- else if (isascii(r[i]))
+ else if (isprint(r[i]))
s += r[i];
else {
const char *hex = "0123456789abcdef";
puList(minx, miny, maxx, maxy, short(0), 20),
GUI_ID(FGCLASS_PROPERTYLIST),
_curr(start),
- _flags(fgGetNode("/sim/gui/dialogs/property-browser/show-flags", true)),
_return(0),
_entries(0),
- _num_entries(0)
+ _num_entries(0),
+ _verbose(false)
{
_list_box->setUserData(this);
PropertyList *prop_list = (PropertyList *)list_box->getUserData();
int selected = list_box->getIntegerValue();
int mod_ctrl = fgGetKeyModifiers() & KEYMOD_CTRL;
+ int mod_shift = fgGetKeyModifiers() & KEYMOD_SHIFT;
if (selected >= 0 && selected < prop_list->_num_entries) {
const char *src = prop_list->_entries[selected];
- if (prop_list->dotFiles && (selected < 2)) {
+ 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);
prop_list->update();
return;
// we know we're dealing with a regular entry, so convert
// it to an index into children[]
- if (prop_list->dotFiles)
+ if (prop_list->_dot_files)
selected -= 2;
SGPropertyNode_ptr child = prop_list->_children[selected].node;
- assert(child);
// check if it's a directory
if (child->nChildren()) {
+ prop_list->setTopItem(0);
prop_list->setCurrent(child);
return;
}
if (!_curr->getParent()) {
_entries = new char*[_num_entries + 1];
pi = 0;
- dotFiles = false;
+ _dot_files = false;
} else {
_num_entries += 2; // for . and ..
strcpy(_entries[1], "..");
pi = 2;
- dotFiles = true;
+ _dot_files = true;
}
int i;
// 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; // ensure it's 0 before setting intial value
- 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;
}
-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->getBoolValue()) {
- 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 (num)
+ line << ", L" << num;
+ }
+ line << ')';
}
- line += ')';
-
- if (line.size() >= PUSTRING_MAX)
- line.resize(PUSTRING_MAX - 1);
-
- if (dotFiles)
- 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());
}
{
for (int i = 0; i < _num_children; i++)
if (_children[i].node == nd) {
- updateTextForEntry(i);
+ updateTextForEntry(_children[i]);
return;
}
}
-int PropertyList::nodeNameCompare(const void *ppNode1, const void *ppNode2)
+int PropertyList::nodeNameCompare(const void *p1, const void *p2)
{
- const SGPropertyNode_ptr pNode1 = (*(const NodeData *)ppNode1).node;
- const SGPropertyNode_ptr pNode2 = (*(const NodeData *)ppNode2).node;
+ const SGPropertyNode *n1 = (*(const NodeData *)p1).node;
+ const SGPropertyNode *n2 = (*(const NodeData *)p2).node;
- int diff = strcmp(pNode1->getName(), pNode2->getName());
- return diff ? diff : pNode1->getIndex() - pNode2->getIndex();
+ int diff = strcmp(n1->getName(), n2->getName());
+ return diff ? diff : n1->getIndex() - n2->getIndex();
}