Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Howto:Extend the about dialog

From FlightGear wiki
Jump to: navigation, search
This article is a stub. You can help the wiki by expanding it.
About dialog 2.10.png

Some people have pointed out that the copy to clipbboard button in the help/about dialog does not copy all of the information to the clipboard that is shown in the dialog.

As a matter of fact, the button was specifically added to copy just graphics related information to the clipboard.

This little tutorial demonstrates how to extend the dialog to copy all, and arbitrary additional, information to the clipboard, without having to be an experienced programmer.

For strters, please navigate to $FG_ROOT/gui/dialogs/about.xml and open that file in a text editor.

Next, navigate to the button/line that reads "copy to clipboard" (as per the label shown in the dialog)

You should see something like this: https://sourceforge.net/p/flightgear/fgdata/ci/next/tree/gui/dialogs/about.xml#l264

    <button>
      <legend>Copy to Clipboard</legend>
      <equal>true</equal>
      <default>false</default>
      <binding>
        <command>nasal</command>
        <script><![CDATA[
   var properties = ["gl-vendor","gl-version","gl-renderer", "gl-shading-language-version"];
   var data = "";
   var path = "/sim/rendering/";
   foreach(var p; properties)
      data ~= p ~":"~getprop(path~p) ~"\n";
   clipboard.setText(data);
   gui.popupTip("Copied version information to clipboard!");
   ]]></script>
      </binding>
    </button>

You can basically ignore everything that's shown in green above, because that's just the XML markup used to create the button and assign a label and event handler to it. The interesting/relevant part is the script section, shown below, with some added annotations


   # a list of strings caled properties
   var properties = ["gl-vendor","gl-version","gl-renderer", "gl-shading-language-version"];
   # an empty string named data
   var data = "";
   # a path to be used for looking up the properties in the list above
   var path = "/sim/rendering/";
   # iterate over each property, refer to it as p
   foreach(var p; properties)
      # append to the data string using the property and the value of the getprop call using the path and the name of the property
      data ~= p ~":"~getprop(path~p) ~"\n";
   # finally, set the clipboard text to the value of the data string
   clipboard.setText(data);
   # and show a popup
   gui.popupTip("Copied version information to clipboard!");

The only thing you need to understand is that the foreach statement is a loop that iterates over the array/vector of properties. The body of that loop merely builds a string by appending to the data variable (string concatenation in Nasal is done using the tilde operator). Thus, what it will do in that loop body (for each properties in the list) is to append a string consisting of the property and the value of property.

In other words, to add other/additional information to this data variable, you merely need to modify it prior to it being passed to the clipboard.setText() call, either before or after the loop building that string - the only difference being whether those new properties show up before or after those rendering related properties.

However, instead of doing this, one of the easiest ways to extend this list is to simply move the path component of the property back into the properties hash, so that other properties can be just as easily added:

   var properties = ["/sim/rendering/gl-vendor","/sim/rendering/gl-version","/sim/rendering/gl-renderer", "/sim/rendering/gl-shading-language-version"];
   var data = "";
   foreach(var p; properties)
      data ~= p ~":"~getprop(p) ~"\n";
   clipboard.setText(data);
   gui.popupTip("Copied version information to clipboard!");

At this point, the path building stuff is redundant and can be safely removed, and you can now add other properties as you wish.

For that, it makes sense to refer to the top of the aout.xml file and look up the properties referenced there and add those to the properties array below: https://sourceforge.net/p/flightgear/fgdata/ci/next/tree/gui/dialogs/about.xml#l120

Specifically, look for <property></property> tags and the string inside, those can be used in the vector:

For example, here's a versionwith the properties vectors extended to also copy "/sim/version/flightgear".

   var properties = ["/sim/version/flightgear", "/sim/rendering/gl-vendor","/sim/rendering/gl-version","/sim/rendering/gl-renderer", "/sim/rendering/gl-shading-language-version"];

Depending on the type of the property, you may need to convert the value to a string first though (%s properties should be fine, besides it'd be possible to actually process/parse each property's format string and use that, as per the snippet used to conver the version property using the sprintf api [1])

Note, for debugging/development purposes you can make these changes with FG running, you only need to reload the UI subsystem to see them take effect