]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/prop_picker.cxx
Patch from Andy Ross to allow virtual panel to tilt with mouse view:
[flightgear.git] / src / GUI / prop_picker.cxx
index e38342fd74aaca393949777a0da3996d5c728d89..a7e5c6c07becb5ca0d6d5cfeb3d0d11cf1934117 100755 (executable)
@@ -470,20 +470,18 @@ void fgPropPicker::find_props ()
   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 ) {
-                iindex = child->getIndex();
-               sprintf(sindex, "%d", iindex);
                dflag[ pi ] = 1 ;
                 files[ pi ] = new char[ strlen(line.c_str())+strlen(sindex)+4 ] ;
                strcpy ( files [ pi ], line.c_str() ) ;
-               if ( node->getChild(name, 1) != 0 ) {
-                   strcat ( files [ pi ], "[" ) ;
-                    strcat ( files [ pi ], sindex ) ;
-                   strcat ( files [ pi ], "]" ) ;
-               }
                strcat ( files [ pi ], "/" ) ;
                values[ pi ] = new char[ 2 ] ;
            } else {
@@ -503,6 +501,26 @@ void fgPropPicker::find_props ()
 
   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;
+    }
+  }
+
   // printf("files pointer=%i/%i\n", files, num_files);
 
   proppath ->    setLabel          (startDir);
@@ -588,3 +606,5 @@ fgPropEdit::fgPropEdit ( char *name, char *value, char *proppath ) : puDialogBox
         
     FG_FINALIZE_PUI_DIALOG( this );
 }
+
+