diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index 650961279..3dba907c3 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -4,14 +4,11 @@ # include "config.h" #endif -#include // atof() - #include #include #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 << '\''); } } } diff --git a/src/GUI/property_list.cxx b/src/GUI/property_list.cxx index fd90fa94d..6fd273633 100644 --- a/src/GUI/property_list.cxx +++ b/src/GUI/property_list.cxx @@ -27,6 +27,7 @@ #include +#include #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); + std::ostringstream line; + line << name; - stdString line = name + " = '" + value + "' (" + type; + int children = node->nChildren(); + if (children) + line << '/'; - 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; + 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 += ')'; + stdString out = line.str(); + if (out.size() >= PUSTRING_MAX) + out.resize(PUSTRING_MAX - 1); - if (line.size() >= PUSTRING_MAX) - line.resize(PUSTRING_MAX - 1); - - if (_dot_files) - index += 2; - - 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; } } diff --git a/src/GUI/property_list.hxx b/src/GUI/property_list.hxx index b7b522deb..73808a25d 100644 --- a/src/GUI/property_list.hxx +++ b/src/GUI/property_list.hxx @@ -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 };