Friday, March 10, 2006

Advanced WorldWind plugin file support

Recently I got the need for more ways to load files from a WorldWind plugin. Which is why I added both Drag&Drop and command line support for plugins. Note that you’ll need the latest version of WorldWind to get these features to work right. Command line support doesn’t work in 1.3.3 at all, but I’ll provide a compatible way that will at least allow the plugin to load in older versions. It’s possible to have 1.3.3 support Drag&Drop but the experience will likely be flaky.

So lets start off with some code to handle files that are passed in from the command line. This is useful if you want to make WorldWind the primary or alternative file handler for a specific type of file in windows explorer. This will automatically work if you’re using a version that has the correct property, and otherwise skip over the argument handling code. You’d generally use this code in the Load method of your plugin, though it could be used just about anywhere.

// Some magic to provide backward compatibility
Type typecontroller = typeof(MainApplication);
System.Reflection.PropertyInfo finfo = typecontroller.GetProperty("CmdArgs", BindingFlags.Static|BindingFlags.Public|BindingFlags.GetProperty);
string[] args = null;
(finfo != null)
args = (string[])finfo.GetValue(null, null);
if (args != null)
// use args here (args is a string array containing all command line arguments)

Drag&Drop support is slightly more complicated. I’ve made a simple demonstration plugin that handles dropping a .jpg file by showing a simple MessageBox for which the source code is available here. I also updated KMLImporter to go hand in hand with this great new functionality.

1 comment:

Anonymous said...

Hi, can you post the source for DnD in WorldWind? The link doesnt work.