X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FGUI%2Fproperty_list.cxx;h=5bcb46a3542cbca9a729460102433b3fd0cfbfae;hb=da02c09ec08cc357926ce6f06b3c6fc5925986d8;hp=cce5415983579f0c68d1cbb07f8dcc39bdabbf4b;hpb=9e9d463a112d084bd93d0cf125c22f76c2341f5b;p=flightgear.git diff --git a/src/GUI/property_list.cxx b/src/GUI/property_list.cxx index cce541598..5bcb46a35 100644 --- a/src/GUI/property_list.cxx +++ b/src/GUI/property_list.cxx @@ -27,8 +27,13 @@ #include -#include STL_STRING -SG_USING_STD(string); +#include +#include +#include +#include +using std::string; +using std::cout; + typedef string stdString; // puObject has a "string" member #include
// fgGetKeyModifiers() @@ -39,31 +44,81 @@ typedef string stdString; // puObject has a "string" member static string getValueTypeString(const SGPropertyNode *node) { + using namespace simgear; string result; - assert(node); - SGPropertyNode::Type type = node->getType(); - if (type == SGPropertyNode::UNSPECIFIED) + props::Type type = node->getType(); + if (type == props::UNSPECIFIED) result = "unspecified"; - else if (type == SGPropertyNode::NONE) + else if (type == props::NONE) result = "none"; - else if (type == SGPropertyNode::BOOL) + else if (type == props::BOOL) result = "bool"; - else if (type == SGPropertyNode::INT) + else if (type == props::INT) result = "int"; - else if (type == SGPropertyNode::LONG) + else if (type == props::LONG) result = "long"; - else if (type == SGPropertyNode::FLOAT) + else if (type == props::FLOAT) result = "float"; - else if (type == SGPropertyNode::DOUBLE) + else if (type == props::DOUBLE) result = "double"; - else if (type == SGPropertyNode::STRING) + else if (type == props::STRING) result = "string"; + else if (type == props::VEC3D) + result = "vec3d"; + else if (type == props::VEC4D) + result = "vec4d"; return result; } +static void dumpProperties(const SGPropertyNode *node) +{ + using namespace simgear; + cout << node->getPath() << '/' << endl; + for (int i = 0; i < node->nChildren(); i++) { + const SGPropertyNode *c = node->getChild(i); + props::Type type = c->getType(); + if (type == props::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 props::DOUBLE: + case props::FLOAT: + case props::VEC3D: + case props::VEC4D: + { + streamsize precision = cout.precision(15); + c->printOn(cout); + cout.precision(precision); + } + break; + case props::LONG: + case props::INT: + case props::BOOL: + c->printOn(cout); + break; + case props::STRING: + cout << '"' << c->getStringValue() << '"'; + break; + case props::NONE: + break; + default: + cout << '\'' << c->getStringValue() << '\''; + } + cout << endl; + } + cout << endl; +} + + static void sanitize(stdString& s) { stdString r = s; @@ -101,13 +156,13 @@ static void sanitize(stdString& s) PropertyList::PropertyList(int minx, int miny, int maxx, int maxy, SGPropertyNode *start) : - puList(minx, miny, maxx, maxy, short(0), 20), + puaList(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); @@ -143,14 +198,19 @@ void PropertyList::handle_select(puObject *list_box) 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 (!strcmp(src, ".")) { - if (mod_ctrl) - prop_list->toggleFlags(); + if (prop_list->_dot_files && (selected < 2)) { + if (src[0] == '.' && (src[1] == '\0' || src[1] == ' ')) { + if (mod_ctrl && mod_shift) + prop_list->_curr->fireValueChanged(); + else if (mod_ctrl) + prop_list->toggleVerbosity(); + else if (mod_shift) + dumpProperties(prop_list->_curr); prop_list->update(); return; @@ -169,11 +229,10 @@ void PropertyList::handle_select(puObject *list_box) // 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()) { @@ -183,7 +242,7 @@ void PropertyList::handle_select(puObject *list_box) } // it is a regular property - if (child->getType() == SGPropertyNode::BOOL && mod_ctrl) { + if (child->getType() == simgear::props::BOOL && mod_ctrl) { child->setBoolValue(!child->getBoolValue()); prop_list->update(true); } else @@ -207,20 +266,20 @@ void PropertyList::update(bool restore_pos) if (!_curr->getParent()) { _entries = new char*[_num_entries + 1]; pi = 0; - dotFiles = false; + _dot_files = false; } else { _num_entries += 2; // for . and .. _entries = new char*[_num_entries + 1]; - _entries[0] = new char[2]; - strcpy(_entries[0], "."); + _entries[0] = new char[16]; + strcpy(_entries[0], _verbose ? ". [verbose]" : "."); _entries[1] = new char[3]; strcpy(_entries[1], ".."); pi = 2; - dotFiles = true; + _dot_files = true; } int i; @@ -233,18 +292,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; @@ -256,52 +307,64 @@ 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; - + using namespace simgear; + 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() == props::STRING + || node->getType() == props::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()); } @@ -309,7 +372,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; } }