imagej/imagej-legacy — pull request #60 by dscho (2014-06-18 21:19:41+00:00)
Title: Ensure that *all* scripts see the macro options

Ah, the dreaded macro options.

Despite the name, they do not necessarily have anything to do with macros. That's just a historical wart, in a manner of speaking.

Whenever any code calls `IJ.run(command, options);`, the "macro options" are set. Even when the call originates from a plugin. And this is a problem. The reason is that ImageJ 1.x is essentially designed for one user/one machine/one GUI/*one thread*: Instead of passing the options directly to the command, and having the command pass the options directly to the `GenericDialog` instances (and the commands called from the command), ImageJ 1.x does something "clever": those options get stored in a thread-local hash map.

In fact, this hash map is *so* local that when the plugin spawns a new thread, the new thread does not see those options at all.

And we do essentially that in `imagej-legacy`, by using the `ThreadService` through the `ScriptService`.

Unfortunately, we cannot fix the design bug in ImageJ 1.x, but we still have to address the issue. So what we do is essentially force ImageJ 1.x to look through more than just one thread when asking for the current "macro" options, asking the ThreadService to help with enumerating the current thread's ancestors.

This PR relies on scijava/scijava-common#87, imagej/ij1-patcher#27 and scijava/scripting-java#1.