- for (i = 0; i < (int)node->nChildren(); i++) {
- SGPropertyNode * child = node->getChild(i);
- name = child->getName();
- if ( node->getChild(name, 1) != 0 ) {
- iindex = child->getIndex();
- sprintf(sindex, "[%d]", iindex);
- name += sindex;
- }
- line = name;
- names[ pi ] = new char[ strlen(line.c_str())+2 ] ;
- strcpy ( names [ pi ], line.c_str() ) ;
- if ( child->nChildren() > 0 ) {
- dflag[ pi ] = 1 ;
- files[ pi ] = new char[ strlen(line.c_str())+strlen(sindex)+4 ] ;
- strcpy ( files [ pi ], line.c_str() ) ;
- strcat ( files [ pi ], "/" ) ;
- values[ pi ] = new char[ 2 ] ;
- } else {
- dflag[ pi ] = 0 ;
- value = node->getStringValue ( name, "" );
- values[ pi ] = new char[ strlen(value.c_str())+2 ] ;
- strcpy ( values [pi], value.c_str() );
- line += " = '" + value + "' " + "(";
- line += getValueTypeString( node->getNode( name ) );
- line += ")";
- files[ pi ] = new char[ strlen(line.c_str())+2 ] ;
- strcpy ( files [ pi ], line.c_str() ) ;
- }
- // printf("files->%i of %i %s\n",pi, node->nChildren(), files [pi]);
- ++pi;
- }
-
- files [ num_files ] = NULL ;
-
- // leave the . and .. alone...
- int ii = ( strcmp(files [0], "." ) == 0 ) ? 2 : 0;
-
- // Sort the entries. This is a simple N^2 extraction sort. More
- // elaborate algorithms aren't necessary for the few dozen
- // properties we're going to sort.
- for(i=ii; i<num_files; i++) {
- int j, min = i;
- char df, *tmp;
- for(j=i+1; j<num_files; j++)
- if(strcmp(names[j], names[min]) < 0)
- min = j;
- if(i != min) {
- tmp = names[min]; names[min] = names[i]; names[i] = tmp;
- tmp = files[min]; files[min] = files[i]; files[i] = tmp;
- tmp = values[min]; values[min] = values[i]; values[i] = tmp;
- df = dflag[min]; dflag[min] = dflag[i]; dflag[i] = df;
+ if (node) {
+ // Get the list of children
+ num_children = node->nChildren();
+ children = new SGPropertyNode_ptr[num_children];
+ for (i = 0; i < num_children; i++) {
+ children[i] = node->getChild(i);
+ }
+
+ // Sort the children into display order
+ qsort(children, num_children, sizeof(children[0]), nodeNameCompare);
+
+ // Make lists of the children's names, values, etc.
+ for (i = 0; i < num_children; i++) {
+ SGPropertyNode * child = children[i];
+ stdString name = child->getDisplayName(true);
+
+ if ( child->nChildren() > 0 ) {
+ files[ pi ] = new char[ strlen(name.c_str())+2 ] ;
+ strcpy ( files [ pi ], name.c_str() ) ;
+ strcat ( files [ pi ], "/" ) ;
+ } else {
+ files[pi] = NULL; // ensure it's NULL before setting intial value
+ updateTextForEntry(i);
+ // observe it
+ child->addChangeListener(this);
+ }
+
+ ++pi;