Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 319337 - [Win32] WindowXP command "Close Group" can not close all the Eclipse window that in one group
Summary: [Win32] WindowXP command "Close Group" can not close all the Eclipse window t...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6.2   Edit
Assignee: Platform UI Triaged CLA
QA Contact: Eric Moffatt CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-08 22:14 EDT by wangpcdl CLA
Modified: 2011-01-20 10:56 EST (History)
9 users (show)

See Also:
Mike_Wilson: pmc_approved+
bokowski: review+


Attachments
SWT snippet demonstrating the issue (1.30 KB, text/x-java)
2010-09-08 13:42 EDT, Eric Moffatt CLA
no flags Details
Patch to the EditorManager to try to make the dialog PRIMARY_MODAL (2.28 KB, patch)
2010-09-09 09:49 EDT, Eric Moffatt CLA
no flags Details | Diff
Updated snippet using JFace to prompt (2.03 KB, text/x-java)
2010-12-14 10:52 EST, Eric Moffatt CLA
no flags Details
Patch for force the EditorManager's prompt to be PRIMARY_MODAL (1.66 KB, patch)
2010-12-14 10:53 EST, Eric Moffatt CLA
no flags Details | Diff
Hacks that make this *appear* to work (5.84 KB, patch)
2010-12-15 16:02 EST, Eric Moffatt CLA
no flags Details | Diff
A possible candidate...flushes existing events before proceeding with the first close (813 bytes, patch)
2010-12-16 11:03 EST, Eric Moffatt CLA
no flags Details | Diff
Spin the loop in 'handleShellCloseEvent' (947 bytes, patch)
2011-01-05 10:50 EST, Eric Moffatt CLA
no flags Details | Diff
Update patch against the maintenance stream (946 bytes, patch)
2011-01-05 11:10 EST, Eric Moffatt CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description wangpcdl CLA 2010-07-08 22:14:01 EDT
Build Identifier: M20090211-1700

On Windows XP, make sure the "Group similar taskbar buttons" item is checked in taskbar properties dialog. Launch eclipse and make sure there are documents in it so that you can edit them. Create some new eclipse window from eclipse main menu item "Window -> New Window", and modify one one document in every window but don't save, make sure those elipse windows are grouped in statusbar. right click it with mouse on taskbar and select "Close Group", you can see that there is a "Save Resource" dialog pops up to check whether you want to save the modified document, choose no, then only one window which pops up "Save Source" dialog is closed, but other windows are still here.

BTW: Win7 has this problem too. 
In Windows 7, the dialog which asking you save document or not, popped up once and then disappeared. Click any Eclipse window, above dialog appears again. If click "No" to do not save document, current window will be closed, but other eclipse window still there.

Reproducible: Always

Steps to Reproduce:
1.Launch Eclipse, and make sure there are some documents in it for editing.
2.Modify a document in the new eclipse window but don't save it, then create another new eclipse window from main menu "Window -> New Window"
3.Repeat step 2 until these eclipse applications are grouped on taskbar.
4.Right click the group with mouse on taskbar and then select "Close Group".
5."Save Resource" dialog will pop up, and choose "No", 

Bug: only the window which pops up "Save Resource" dialog is closed, left eclipse windows in the group are still there.
Comment 1 Raji Akella CLA 2010-07-09 11:52:29 EDT
Problem reported by Lotus Symphony.
Comment 2 Paul Webster CLA 2010-08-23 07:43:59 EDT
We need to investigate if we are receiving the SWT close events for all of the windows.

PW
Comment 3 Paul Webster CLA 2010-08-23 07:44:52 EDT
Eric, could you please have a look at this for 3.6.1
PW
Comment 4 Eric Moffatt CLA 2010-08-24 15:39:13 EDT
Hmmm, this appears to be how this feature works. I tried the same scenario using WordPad and get the same behavior (each 'dirty' instance has its own dialog that must be handled before that window will close).

Note that any instances that were not dirty close silently, I think this is 'by design'...they need to get you to answer discreetly in each instance of the window.
Comment 5 Paul Webster CLA 2010-08-25 08:22:48 EDT
(In reply to comment #4)
> Hmmm, this appears to be how this feature works. I tried the same scenario
> using WordPad and get the same behavior (each 'dirty' instance has its own
> dialog that must be handled before that window will close).

I think the original point is that for 5 eclipse windows in the close group, we only get one dialog and one window closed.

Is that correct, original opener?

PW
Comment 6 wangpcdl CLA 2010-08-25 21:14:15 EDT
Yes, only the window which pops up "Save Source" dialog is closed, but other windows are still here
Comment 7 Remy Suen CLA 2010-09-07 13:35:12 EDT
(In reply to comment #2)
> We need to investigate if we are receiving the SWT close events for all of the
> windows.

I have confirmed this on Windows XP with an SWT snippet. Multiple SWT.Close events are being fired.
Comment 8 Eric Moffatt CLA 2010-09-08 13:42:37 EDT
Created attachment 178426 [details]
SWT snippet demonstrating the issue


This is a hacked version of Snippet99. It creates two shells using the same display (this emulates the given scenario of using 'Window->New Window' in eclipse).

If you now select both the task bar items (a handy trick I learned while looking into this is that the task bar allows Ctrl-click for multi-select) and choose 'Close Group' then only the first shell gets prompted and the second doesn't.

Note that multiple discreet instances of eclipse behave as expected...
Comment 9 Eric Moffatt CLA 2010-09-08 13:45:56 EDT
Passing to SWT for further investigation...
Comment 10 Silenio Quarti CLA 2010-09-08 14:31:02 EDT
When the SWT.Close event comes for the first Shell, the snippet opens a SWT.APPLICATION_MODAL dialog which disables all other shells. Those shells will not get SWT.Close event because they are disabled.

All shells would get SWT.Close event if the dialog was SWT.PRIMARY_MODAL instead.
Comment 11 Eric Moffatt CLA 2010-09-09 09:49:19 EDT
Created attachment 178518 [details]
Patch to the EditorManager to try to make the dialog PRIMARY_MODAL


Thanks Silenio. The easy proof is to simply change the dialogs in the attached SWT snippet to PRIMARY_MODAL instead of APPLICATION_MODAL and observe that the Close Group now works.

The bad news is that I've tried to hack the 'Save Editor' dialog to be PRIMARY_MODAL in eclipse but if still fails the same way as it did. I'll attach a patch showing my attempt, perhaps someone more familiar with JFace can take a look...
Comment 12 Eric Moffatt CLA 2010-12-14 10:51:19 EST
This is deep. I've modified the snippet to use the JFace MessageDialog (with a hack to force PRIMARY_MODAL) and it works (indicating that it's not the JFace handling that's interferring).

I also thought that we may be having the same issue with the prompt for the last window closing so I turned off the prompt preference...still no dice.

Also, with the changes I can right-click on the taskbar and separately close each window. In this case I end up with both windows prompting to save and closing but the application does *not* shut down, it spins forever with *no* windows up...

I'll attach two patches; an updated SWT/JFace snippet and a patch for the EditorManager that forces the prompt dialog to be PRIMARY_MODAL.
Comment 13 Eric Moffatt CLA 2010-12-14 10:52:09 EST
Created attachment 185144 [details]
Updated snippet using JFace to prompt
Comment 14 Eric Moffatt CLA 2010-12-14 10:53:55 EST
Created attachment 185145 [details]
Patch for force the EditorManager's prompt to be PRIMARY_MODAL
Comment 15 Eric Moffatt CLA 2010-12-15 16:02:25 EST
Created attachment 185267 [details]
Hacks that make this *appear* to work


This is just an interim capture of some code that at least feeds the close event to all the shells.

I've produced a similar result by re-implementing Window#handleCloseEvent to make it asynchronous:

rotected void handleShellCloseEvent() {
   if (Display.getCurrent() != null) {
      Display.getCurrent().asyncExec(new Runnable() {
         public void run() {
         setReturnCode(CANCEL);
         close();
      }
     });
   }
}

With no other changes this does handle getting both shells to prompt and save but doesn't exit the workbench...
Comment 16 Eric Moffatt CLA 2010-12-16 11:03:25 EST
Created attachment 185338 [details]
A possible candidate...flushes existing events before proceeding with the first close


This has two advantages...it's localized to the WorkbenchWindow code (i.e. doesn't mess with JFace's modality.
Comment 17 Mike Wilson CLA 2010-12-16 13:06:33 EST
Silenio, does Eric's latest strategy seem workable? Are there potential pitfalls?
Comment 18 Silenio Quarti CLA 2010-12-16 16:58:19 EST
(In reply to comment #17)
> Silenio, does Eric's latest strategy seem workable? Are there potential
> pitfalls?

I cannot see any obvious problem with the strategy. Note that I think the event loop should not be in WorkbenchWindow.close(), it should only run as part of the SWT.Close event to minimize side effects (WorkbenchWindow..handleShellCloseEvent()?) .

Usually it is bad to flush events by spinning the event loop, but in this case there is going to an event loop a "couple of lines below" for the save/confirm dialog. So the biggest difference is that the events flushed by the fix will run before the shells are disabled. The user would be able to interact with those shells, but in practice there is no time for that. Unless of course, there is a ton of pending async exec runnables to run :-).
Comment 19 Eric Moffatt CLA 2011-01-05 10:50:11 EST
Created attachment 186091 [details]
Spin the loop in 'handleShellCloseEvent'


Thanks Silenio, this works fine and is a more logical place for the code...
Comment 20 Eric Moffatt CLA 2011-01-05 11:10:45 EST
Created attachment 186094 [details]
Update patch against the maintenance stream
Comment 21 Eric Moffatt CLA 2011-01-05 13:46:03 EST
I've just tested this on XP in situations where the various windows have either modal or modeless dialogs up when I use the Close Group. Everything appears to work ok; shells showing a modal dialog don't 'see' the close message since they're disabled and our modeless dialogs are already set up to handle cases where the user closes the shell while they're up.
Comment 22 Boris Bokowski CLA 2011-01-05 16:29:29 EST
Do we need a similar fix in 4.1?
Comment 23 Boris Bokowski CLA 2011-01-05 16:56:13 EST
Is it true that after the fix, "Close Group" will close shells one by one and thus in the next session, we will come back with just one workbench window? Wouldn't this be unexpected?

Another question: It seems to me that by spinning the event loop while handling the first close event, there will be a number of close events that are stacked, so that the following might happen:
1. User has three workbench windows (called A,B,C)
2. Selects "Close Group"
3. Close event will be sent to A
4. Event handling code spins the event loop
5. Close event will be sent to B
6. Event handling code spins the event loop
7. Close event will be sent to C
8. (For sake of argument, C has a dirty editor but A and B don't)
9. Dialog will pop up asking whether to save
10. User clicks cancel (window C will stay open)
11. Control returns to event handling code for B, window B will be closed
12. Control returns to event handling code for A, window A will be closed
Since the user clicked cancel in 10., wouldn't the expectation be to not close any workbench window?

How do other Windows apps behave, in similar circumstances?

I'd like to play with this on a Windows XP box a bit before I give my +1.
Comment 24 Paul Webster CLA 2011-01-10 11:48:30 EST
(In reply to comment #23)
> Is it true that after the fix, "Close Group" will close shells one by one and
> thus in the next session, we will come back with just one workbench window?
> Wouldn't this be unexpected?

It might be unexpected from a user point of view, but as it looks like windows simply fires close events at all windows in the group it seems that what windows intends.

Would word be an equivalent app to test?


> 
> How do other Windows apps behave, in similar circumstances?
> 
> I'd like to play with this on a Windows XP box a bit before I give my +1.

Just a reminder that tomorrow is probably our last chance to get this in 3.6.2.

PW
Comment 25 Eric Moffatt CLA 2011-01-10 14:57:30 EST
I've just tried a variety of mixed scenarios (same editor dirty in multiple windows and a mix if windows with some dirty, some not). The only oddity from a user's viewpoint is that even should they select 'Cancel' on the initial save dialog the other windows are still processed. This is different from selecting 'Exit' where we do special handling to only prompt once...
Comment 26 Boris Bokowski CLA 2011-01-10 15:24:31 EST
+1 for 3.6.2.
Comment 27 Mike Wilson CLA 2011-01-10 15:49:42 EST
Fix is definitely better than the current behavior. +1.
Comment 28 Eric Moffatt CLA 2011-01-10 16:10:50 EST
Committed in >20110110. Applied the patch, thanks folks !
Comment 29 Eric Moffatt CLA 2011-01-10 16:11:14 EST
Marking as fixed...
Comment 30 Eric Moffatt CLA 2011-01-20 10:56:05 EST
Verified in >20110119-0834.