NOTICE! This is a static HTML version of a legacy Fiji BugZilla bug.

The Fiji project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Bug 952 - Return value of IJ.showMessageWithCancel() is ignored in macros
Return value of IJ.showMessageWithCancel() is ignored in macros
Status: RESOLVED FIXED
Product: Fiji
Classification: Unclassified
Component: ImageJ1
unspecified
Macintosh Mac OS
: P5 enhancement
Assigned To: ImageJ Bugs Mailing List
Depends on:
Blocks:
 
Reported: 2014-11-04 09:51 CST by Tiago Ferreira
Modified: 2015-04-21 11:41 CDT
3 users (show)

See Also:

Description Tiago Ferreira 2014-11-04 09:51:21 CST
A (IJ1) macro calling showMessageWithCancel() is expected to terminate if the user chooses "Cancel"
(http://imagej.nih.gov/ij/developer/macro/functions.html#showMessageWithCancel).

In Fiji, however, macros continue to run after pressing "Cancel". Example:

showMessageWithCancel("In IJ1 a macro exits when the user clicks 'Cancel'");
showMessage("But not in Fiji (unless it runs from the IJ1 editor)");

Running the above in the buil-in editor (e.g., Plugins>New>Text Window) works as expected.

Probably not a major issue, but it will likely break some macros down the road.
Comment 1 Curtis Rueden 2014-11-17 16:02:13 CST
I debugged into it, but I have to admit I have no idea how this works.

Eventually, the ImageJ 1.x code resolves down to:

https://github.com/imagej/ImageJA/blob/v1.49k/src/main/java/ij/macro/Functions.java#L120
Which does:
https://github.com/imagej/ImageJA/blob/v1.49k/src/main/java/ij/macro/Functions.java#L1636
Which is this:
https://github.com/imagej/ImageJA/blob/v1.49k/src/main/java/ij/IJ.java#L639-L644

Maybe there is something clever in GenericDialog that cancels macros, but doesn't work with the ImageJ2-script-language version of the macro support...
Comment 2 Wayne Rasband 2014-11-17 20:34:08 CST
The showMessageWithCancel() macro function calls IJ.showMessageWithCancel(), which calls GenericDialog.wasCanceled(), which aborts the macro if the dialog was canceled. I do not know why this is not working in the Fiji Script Editor.
Comment 3 Curtis Rueden 2014-11-21 15:14:23 CST
Thank you for the information, Wayne!

The issue was that when a macro runs from the ImageJ2 Script Editor, the thread name does not end with "Macro$".

I committed a fix:
https://github.com/imagej/imagej-legacy/commit/b79d3010297e4185ad7510df2c0fc09dcc5ce85b

And also another related workaround:
https://github.com/imagej/imagej-legacy/commit/883e01c456fc6d7c1ca03557972e27f72ca77182

So this issue will be resolved once a new imagej-legacy JAR is released and uploaded to the ImageJ update site.