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 282 - When quitting, Fiji does not prompt to save changes in non-image windows
When quitting, Fiji does not prompt to save changes in non-image windows
Status: RESOLVED REMIND
Product: Fiji
Classification: Unclassified
Component: ImageJ1
unspecified
All All
: P2 minor
Assigned To: ImageJ Bugs Mailing List
Depends on:
Blocks:
 
Reported: 2011-02-04 05:17 CST by Curtis Rueden
Modified: 2011-03-23 15:00 CDT
0 users

See Also:

Description Curtis Rueden 2011-02-04 05:17:04 CST
STEPS TO REPRODUCE

1) Start Fiji
2) Choose File > New > Script or File > New > Text Window
3) Type some text into the editor window that appears
4) Choose File > Quit (Fiji > Quit Fiji on Mac OS X works too)
5) Fiji will quit without prompting to save changes in the editor window

REASON FOR THE BEHAVIOR

1) Performing File > Quit calls IJ.quit().

2) IJ.quit() calls IJ.getInstance().quit(), which in turns spawns a new thread that invokes ij.ImageJ.run().

3) The run method does the following:
  * Sets a "quitting" flag
  * Prompts "Are you sure you want to quit?" in certain circumstances (but none generally relevant to this issue)
  * Calls WindowManager.closeAllWindows(), and aborts if it returns false
  * Otherwise, performs various cleanup, then calls System.exit(0)

4) The closeAllWindows method does the following:
  * For each *image* window, aborts if that window refuses to close
    - When asked to close, an ImageWindow prompts the user if it has unsaved changes
    - If the user cancels, the ImageWindow declines to close
  * Signals the OK to quit if the "quitting" flag is true (which at this point, it always is)
  * Additional logic past that point is ignored in this case

So, the problem is that when quitting, *non*-image windows are never queried to ensure they are OK with being shut down. This holds for both the Fiji Script Editor and ImageJ's built-in Text Editor.

Further, even if the closeAllWindows method is modified to ignore the "quitting" flag and continue onward, testing non-image windows, there is still a problem: only ij.plugin.frame.PlugInFrame and ij.text.TextWindow objects are closed with close(). Everything else is closed with setVisible(false) and dispose(), with no recourse. And the aforementioned classes' close() methods also have no recourse to cancel anyway, since close() returns void.
Comment 1 Johannes Schindelin 2011-02-04 16:00:52 CST
There must be some check somewhere for non-image windows... When I have no script editor or other window open, clicking on the little "x" in the window bar of the main window does not result in a question "Quit?", but when I have a script editor open, the question pops up.

This is the relevant part of the thread dump obtained via Ctrl+\ while the question is showing:

"Quit" prio=10 tid=0x09d5ac00 nid=0x6097 in Object.wait() [0x09a8e000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	at java.lang.Object.wait(Object.java:485)
	at java.awt.Dialog.show(Dialog.java:1109)
	- locked <0x8029f9c0> (a java.awt.Component$AWTTreeLock)
	at java.awt.Component.show(Component.java:1563)
	at java.awt.Component.setVisible(Component.java:1515)
	at java.awt.Window.setVisible(Window.java:842)
	at java.awt.Dialog.setVisible(Dialog.java:986)
	at ij.gui.GenericDialog.showDialog(GenericDialog.java:1021)
	at ij.ImageJ.run(ImageJ.java:707)
	at java.lang.Thread.run(Thread.java:662)

The funny thing is that for me, too, File>Quit does not bother to ask. From looking at the code, it also has another subtle bug: when there are modified images, the user does not get the "Are you sure you want to quit" question to indicate that there might be unsaved scripts/macros.

Further debugging indicates that the only difference in http://pacific.mpi-cbg.de/ImageJ.java:703 between clicking the little "X" and File>Quit is the value of windowClosed. When clicking the little "X", windowClosed is set to true, most likely through http://pacific.mpi-cbg.de/ImageJ.java:533 (it is a little confusing to see doCommand("Quit"); being called _before_ that assignment, but the reality is that doCommand() launches another thread that is not fast enough _not_ to catch the variable change).

I am sure there once was a good rationale for the differing behavior of the little "x" and File>Quit, but I failed at imagining one :-)
Comment 2 Wayne Rasband 2011-02-04 20:42:01 CST
This is fixed for text (Editor) windows in the ImageJ 1.45a6 daily build. It could also be fixed for Script Editor windows if there were a close() method that ImageJ could call using reflection.

-wayne
Comment 3 Johannes Schindelin 2011-02-04 21:01:45 CST
I'd rather not prefer to special case things here and there when the result is inconsistency. For example, I cannot think of a good reason why File>Quit and clicking the little 'x' should behave differently, because it violates the http://en.wikipedia.org/wiki/Principle_of_least_astonishment. But I'll keep on trying to think of one! :-)
Comment 4 Johannes Schindelin 2011-03-23 14:59:01 CDT
Maybe we should change ImageJA to make the click on the 'x' behave the same as File>Quit...
Comment 5 Albert Cardona 2011-03-23 15:00:43 CDT
(In reply to comment #4)
> Maybe we should change ImageJA to make the click on the 'x' behave the same as
> File>Quit...


I second that.