Bug 375744 - [Workbench] Command-Q does not ask to confirm exit
Summary: [Workbench] Command-Q does not ask to confirm exit
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Mac OS X
: P2 normal with 3 votes (vote)
Target Milestone: 4.5 RC1   Edit
Assignee: Markus Keller CLA
QA Contact: Brian de Alwis CLA
URL:
Whiteboard: candidate43
Keywords:
Depends on:
Blocks: 512857
  Show dependency tree
 
Reported: 2012-03-30 12:49 EDT by Igor Fedorenko CLA
Modified: 2017-03-29 11:43 EDT (History)
10 users (show)

See Also:
emoffatt: review+
bsd: review+


Attachments
Alternative approach (4.69 KB, patch)
2012-04-27 16:36 EDT, Brian de Alwis CLA
no flags Details | Diff
Patch to add optional confirmation parameter (5.99 KB, patch)
2012-05-06 14:17 EDT, Brian de Alwis CLA
bsd: review?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Fedorenko CLA 2012-03-30 12:49:26 EDT
Pressing Command-Q on Mac OSX is expected to bring "Confirm Exit" dialog.
Comment 1 Paul Webster CLA 2012-04-02 08:35:02 EDT
We need the fix from Bug 283345 here.

PW
Comment 2 Oleg Besedin CLA 2012-04-12 11:29:15 EDT
(In reply to comment #1)
> We need the fix from Bug 283345 here.

It turns out that the code is in 4.x stream, but there was something else.

Suspense... Drumrolls... 

There was a line in CocoaUIEnhancer that redirects OS quit menu to use Eclipse quit command. Which seems to be logical on the surface except that QuitHandler calls Workbench.close() which does not prompt.

The code that does prompt is added to the Display's SWT.Close listener. However, because OS processing is redirected to the Eclipse command, the SWT.Close never gets generated (IDEWorkbenchWindowAdvisor#promptOnExit()).

Git reference:

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=2213493c9d2dfe6d0ae03b77e9d5c8c81a5eb1dd
Comment 3 Brian de Alwis CLA 2012-04-26 18:49:09 EDT
But as a result, E4 apps can't install their own quit handler.  Such as, say, to prompt the user as to confirm whether they want to quit!

Isn't the right answer here to change the IDE exit handlers to prompt before closing?
Comment 4 Oleg Besedin CLA 2012-04-27 09:49:55 EDT
(In reply to comment #3)
> But as a result, E4 apps can't install their own quit handler.  Such as, say,
> to prompt the user as to confirm whether they want to quit!
> 
> Isn't the right answer here to change the IDE exit handlers to prompt before
> closing?

Hmm.... I think that is what we are doing now - the "prompt" code is in IDEWorkbenchWindowAdvisor. Besides, if it is the general RCP behaviour we are talking about, the *Cocoa*UIEnhancer can't be the place.

I think it is a good idea to have a workbench "close" and/or "shutdown" handler for the RCP apps and it should be a part of our lifecycle story. I don't think we have that now so I opened bug 377911 to consider for 4.3.
Comment 5 Brian de Alwis CLA 2012-04-27 14:32:57 EDT
I was unclear in what I wrote: IMHO the right answer is to change the org.eclipse.ui.file.exit handler (org.eclipse.ui.internal.handlers.QuitHandler) to prompt before closing.  It doesn't do that right now.

To verify, invoke File > Exit on Eclipse (on a non-mac platform) or through the Quick Access bar.  This invokes the org.eclipse.ui.file.exit command.  Notice that it doesn't prompt for confirmation.  Fixing QuitHandler to prompt is the right fix for this bug, IMHO.

So I'm re-opening this again: regardless of my disagreement with this change, the change is incomplete as the CocoaUIHandler also hides all menu items that trigger org.eclipse.ui.file.exit (since they're remapped to the system menu).  If we're not remapping org.eclipse.ui.file.exit then those items shouldn't be remapped (see redirectHandledMenuItem()).  You'll see the Contacts demo has an Exit item that triggers org.eclipse.ui.file.exit, that should no longer be remapped.
Comment 6 Brian de Alwis CLA 2012-04-27 16:36:27 EDT
Created attachment 214739 [details]
Alternative approach

Here's an alternative approach that installs an org.eclipse.ui.ide.application-specific QuitHandler to prompt the user, using the same mechanism as the close listener.
Comment 7 Oleg Besedin CLA 2012-05-02 15:53:30 EDT
Sorry, I still don't get it.

As far as I can tell, the current I-build (0430) for 4.2 works the same as 3.8 on Mac and Windows while using Command+Q, "x" button, and Eclipse -> Quit Eclipse / File -> Quit menu.

The "Alternative approach" patch proposes Mac-specific code changes to achieve the same. 

1) If we are speaking about RCP apps in general, why code changes are Mac-specific? The patch diverts quit command to a special handler that does the same work as the normal handler. 

I suppose the point is that then Mac RCP app can override the handler; but what about other OSes? And if there is really a need to override it, the RCP app coudl use the same code to track quit event.

2) Why do we need two handlers if Mac handler does not add anything Mac-specific?

Brian, could you provide an example of something that you could do before this change and can't do now?
Comment 8 Markus Keller CLA 2012-05-03 11:52:54 EDT
(In reply to comment #5)
> I was unclear in what I wrote: IMHO the right answer is to change the
> org.eclipse.ui.file.exit handler (org.eclipse.ui.internal.handlers.QuitHandler)
> to prompt before closing.  It doesn't do that right now.

I disagree that this is the right answer. See e.g. bug 58762 comment 1:
"The dialog is only there to prevent you from accidentally exiting when you close the last window, not when you explicitly choose File > Exit."

Quit on the Mac is different from File > Exit, since it has a key binding and is also used via other OS gestures (e.g. Command+Tab, keep Command pressed, type Q to quit the selected app), so it also needs the "accident protection".

The prompt-less File > Exit should stay, but I see that the org.eclipse.ui.file.exit handler is problematic, since it can be invoked from Quick Access and it can be bound to a shortcut.

Proposal:
- Remove the categoryId from the org.eclipse.ui.file.exit command, so that it doesn't show up on the Keys page and in Quick Access. File > Exit continues to use that command.
- Add a new "Quit" command that just calls Display.close() and lets the existing infrastructure handle the showing of the prompt. This one can get a category, since it is safe to use and bind on all platforms.


I'm just commenting on the UI here -- I don't know enough about implementation details for E4 applications, so maybe there's more to this on that level.
Comment 9 Oleg Besedin CLA 2012-05-03 13:25:41 EDT
As the proposed patch does not seem to hurt anything and hopefully will help Brian, I released it into the master.
Comment 10 Dani Megert CLA 2012-05-04 03:13:21 EDT
(In reply to comment #9)
> As the proposed patch does not seem to hurt

It does hurt: Now, one also gets a dialog with File > Exit on Windows. This is unexpected and not good. Clicking the [x] can easily happen by mistake, hence a warning dialog. File > Exit does rarely happen by accident, no dialog there. That is the reason for having the separate behavior that we had for many years (since 2.1).

Also note, that the preference on General > Startup and Shutdown says:
Confirm exit when closing last window
             ************************

If we decide to change it in M7 or even RC1 now, then we must also add a second preference so that the original behavior can be preserved. I'd prefer not to go down that path and leave things as is.
Comment 11 Dani Megert CLA 2012-05-04 03:36:55 EDT
In addition, something is very fishy with the fix (4.2-I20120503-1800, Windows
7): sometimes File > Exit shows the dialog and sometimes it doesn't using these
steps.

1. start new workspace
2. File > Exit
==> no dialog! (sometimes)

1. start new workspace
2. click 'Link with Editor' in the Package Explorer
3. File > Exit
==> dialog (sometimes)
Comment 12 Markus Keller CLA 2012-05-04 06:09:07 EDT
(In reply to comment #11)
That's probably because the new handler illegally targets commandId "org.eclipse.ui.file.exit" without an activation expression.

The declaration of the command in org.eclipse.ui specifies a defaultHandler, and the spec clearly says "This handler will conflict with other handler definitions that specify no activeWhen conditions".

See bug 378457 for the missing conflict detection.
Comment 13 Paul Webster CLA 2012-05-04 08:56:05 EDT
(In reply to comment #10)
> (In reply to comment #9)
> > As the proposed patch does not seem to hurt
> 
> It does hurt: Now, one also gets a dialog with File > Exit on Windows. 

Hi Dani, do we back out the fix and ask for a respin, or do we live with this until RC1?

PW
Comment 14 Paul Webster CLA 2012-05-04 09:01:22 EDT
(In reply to comment #13)
> Hi Dani, do we back out the fix and ask for a respin, or do we live with this
> until RC1?

OK, my take on this is that we fix it in RC1.  If there's dissent, please comment on the bug.

PW
Comment 15 Brian de Alwis CLA 2012-05-04 11:06:49 EDT
I was surprised that Oleg committed my patch as I thought after yesterday's call that we were going to thrash this out on the bug and fix for RC1.

My concern is this: the original fix for this bug, removing the binding of the Quit menu to invoke the org.eclipse.ui.file.exit command, treats the immediate symptom but not the underlying problem.  Having multiple exit points complicates life for RCP developers (E4 and, from bug 283345, for E3 too).  I lost several hours in debugging to figure out why Cmd-Q wasn't triggering org.eclipse.ui.file.exit to invoke my  clean shutdown handler.  And although I've been developing Eclipse/SWT apps for years, I only recently became aware of the SWT.Close from this bug.

From an app developer's perspective, I don't see a Mac app's App Menu > Quit as being different File > Exit, other than the Mac has a default keybinding.  Note that WorkbenchActionBuilder omits File > Exit if on the Mac, implying it's equivalent to Cmd-Q.  Nor do I see a real difference between an SWT.Close event (sent if Cmd-Q isn't bound) and File > Exit.

Rather than have SWT.Close issue a prompt and org.eclipse.ui.file.exit not issue prompt, my take is that we should be triggering org.eclipse.ui.file.exit in all circumstances and instead provide a parameter to describe the triggering context to allow the handler to make the best decision.  This parameter would be: keybinding, menu item, tool item, or app close request.  I think that's a much easier-to-understand story.

Another alternative is to instead define two exit commands to encode different semantics.  I'm not a big fan of this approach though.

(In reply to comment #10)
> Also note, that the preference on General > Startup and Shutdown says:
> Confirm exit when closing last window
            ************************

So if we're going to debate semantics (and we should!), then this argues against removing the original behaviour in the first place as the SWT.Close guard triggers regardless of the number of windows being closed :-)

> If we decide to change it in M7 or even RC1 now, then we must also add a second
> preference so that the original behavior can be preserved. I'd prefer not to go
> down that path and leave things as is.

I guess I'd argue that this option is misnamed and should be "Confirm exit": it's just that exiting the last window causes the app to exit.   Supported in part by the fact that the method on IDEWorkbenchWindowAdvisor to check and issues the prompt is called promptOnExit().
Comment 16 Dani Megert CLA 2012-05-04 12:26:20 EDT
(In reply to comment #14)
> (In reply to comment #13)
> > Hi Dani, do we back out the fix and ask for a respin, or do we live with this
> > until RC1?
> 
> OK, my take on this is that we fix it in RC1.  If there's dissent, please
> comment on the bug.
> 
> PW

Yes, completely agree with RC1 (I already mentioned this in the "declare M7" bug).
Comment 17 Markus Keller CLA 2012-05-04 12:28:52 EDT
> From an app developer's perspective, I don't see a Mac app's App Menu > Quit as
> being different File > Exit, other than the Mac has a default keybinding.  Note
> that WorkbenchActionBuilder omits File > Exit if on the Mac, implying it's
> equivalent to Cmd-Q.  Nor do I see a real difference between an SWT.Close event
> (sent if Cmd-Q isn't bound) and File > Exit.

I agree that they look similar from an app developer's perspective, but there's quite a difference in common usage. The Mac's Quit command is a built-in OS command and easily accessible, so it needs the prompt. Basically, it's the usual Mac way to close all windows.

In contrast, Windows doesn't have such a pervasive Quit command/gesture. There, the usual way to quit an application is to close all windows (and we show the prompt when you close the last one). The reason for not prompting on File > Exit on Windows is that you wouldn't hit that menu item by accident, but usually in cases where you're already sure you want to exit (without closing all windows first).

That's all the history and UX input I have.

If we were in M1, I would say "let's regularize this and also prompt on File > Exit". But in RC0/1, I'm not so sure...

A point to consider when changing the "org.eclipse.ui.file.exit" handler is that this command never showed a dialog. It could e.g. be used by scripts. That problem would be mitigated with the proposal from comment 8 (add a new command that prompts) or by adding a parameter (promptOnExit, false by default).
Comment 18 Dani Megert CLA 2012-05-04 12:33:08 EDT
I can't say much about the behavior on Mac, but on Windows one thing is given:
1. File > Exit must not prompt if there's no dirty part
2. Closing last window must prompt with an option to never ask again.
Comment 19 Oleg Besedin CLA 2012-05-04 13:49:02 EDT
I think we need to rollback the "Alternative approach" patch in RC1, but I
don't think we should do anything else here for 4.2.

This will get us in a state where the actual issue reported (see comment 0) is
fixed and, as far as I can tell, we'll match 3.8 behavior.

I do agree that Eclipse exit handling could be simplified, but this does not
strike me as something that needs to be done in a Release Candidate phase.

For the impact on e4 RCP apps, it is easily mitigated. Using contacts demo as
an example, all that is needed is to add prompt to the ExitHandler - if RCP
author thinks that prompt is necessary.

In both 3.x and 4.x worlds prompting code resides at IDE levels. I don't see
moving that code to the JFace as a good task for the RCx.

So, I suggest that we roll back the last patch, close this bug as the original
defect will be fixed, open an enhancement request for streamlining Eclipse exit
handling.
Comment 20 Brian de Alwis CLA 2012-05-04 16:42:27 EDT
Just so I'm clear here, I'm not disputing that Cmd-Q shouldn't prompt.  All I'm disputing is that manner in which this is implemented because...

(In reply to comment #19 from Oleg)
> For the impact on e4 RCP apps, it is easily mitigated. Using contacts demo as
> an example, all that is needed is to add prompt to the ExitHandler - if RCP
> author thinks that prompt is necessary.

That *was* true.  It won't be true if we revert to your original patch, unhooking Cmd-Q.  They'll need to  either add an SWT.Close handler to the Display or add a listener to Display.getSystemMenu()'s SWT.ID_QUIT, either by providing an IApplication class that wraps E4Application or through a model processor/addon.  And then add a visibleWhen to their existing File > Exit menu item.  That's work that we can help them avoid.

> In both 3.x and 4.x worlds prompting code resides at IDE levels. I don't see
> moving that code to the JFace as a good task for the RCx.

Um, there's nothing proposed to move into JFace.

> So, I suggest that we roll back the last patch, close this bug as the original
> defect will be fixed, open an enhancement request for streamlining Eclipse exit
> handling.

As I pointed out in comment #5, this isn't sufficient as you have to disable the code that hides menu items referencing org.eclipse.ui.file.exit (CocoaUIHandler#redirectHandledMenuItem()).

My suggestion is:

  1. Fix the IDE quit handler definition as per comment #12
  2. Add a new command parameter ("neverConfirm" defaulting to false)
  3. Change File > Exit to pass that parameter

I think that keeps everybody happy, doesn't it?
Comment 21 Brian de Alwis CLA 2012-05-06 14:17:49 EDT
Created attachment 215145 [details]
Patch to add optional confirmation parameter

I've attached a patch that adds an optional command parameter to org.eclipse.ui.file.exit called "confirm" (actually, org.eclipse.ui.file.exit.confirm). If "never", indicates that the exit should never prompt the user to confirm.  This seemed better than a boolean if we wanted to encode other possibilities (e.g., "last" for if last-window).

We can specify a set of parameter values if anybody thinks that's helpful.
Comment 22 Brian de Alwis CLA 2012-05-06 14:19:26 EDT
(In reply to comment #21)
> We can specify a set of parameter values if anybody thinks that's helpful.

I wasn't sure of the language to use.  We could get away with just the first parameter value, I suppose.

+            <values
+                  class="org.eclipse.ui.commands.ExtensionParameterValues">
+               <parameter
+                     name="Never prompt for confirmation"
+                     value="never">
+               </parameter>
+               <parameter
+                     name="Prompt for confirmation based on workbench preference"
+                     value="preference">
+               </parameter>
+            </values>
Comment 23 Dani Megert CLA 2012-05-07 04:01:49 EDT
(In reply to comment #19)
> I think we need to rollback the "Alternative approach" patch in RC1, but I
> don't think we should do anything else here for 4.2.
> 
> This will get us in a state where the actual issue reported (see comment 0) is
> fixed and, as far as I can tell, we'll match 3.8 behavior.
> 
> I do agree that Eclipse exit handling could be simplified, but this does not
> strike me as something that needs to be done in a Release Candidate phase.
> 
> For the impact on e4 RCP apps, it is easily mitigated. Using contacts demo as
> an example, all that is needed is to add prompt to the ExitHandler - if RCP
> author thinks that prompt is necessary.
> 
> In both 3.x and 4.x worlds prompting code resides at IDE levels. I don't see
> moving that code to the JFace as a good task for the RCx.
> 
> So, I suggest that we roll back the last patch, close this bug as the original
> defect will be fixed, open an enhancement request for streamlining Eclipse exit
> handling.


Given RC1, that's also what I'd suggest.
Comment 24 Oleg Besedin CLA 2012-05-07 16:38:34 EDT
(In reply to comment #20)

> That *was* true.  It won't be true if we revert to your original patch,
> unhooking Cmd-Q.  They'll need to  either add an SWT.Close handler to the

Yes, you are correct.

(In reply to comment #21)
> Created attachment 215145 [details]
> Patch to add optional confirmation parameter
> 

I am not an expert on commands, so I am not sure of this is good:

+         <!-- Use count=* since we want this handler to always be active -->
+         <activeWhen>
+            <count
+                  value="*">
+            </count></activeWhen>

This looks like a workaround build on the workaround from the previous patch.

Even aside from being in RC, if we are to follow this line and RCP apps start to rely on it, we'll have to continue to support it in future. That in turn will complicate making a real solution and allowing E4 RCP apps hook into the shutdown sequence.
Comment 25 Brian de Alwis CLA 2012-05-08 10:16:43 EDT
(In reply to comment #24)
> I am not an expert on commands, so I am not sure of this is good:
> 
> +         <!-- Use count=* since we want this handler to always be active -->
> +         <activeWhen>
> +            <count
> +                  value="*">
> +            </count></activeWhen>
> 
> This looks like a workaround build on the workaround from the previous patch.

Good point.  Short of building an always-true property tester, I didn't see a different way to always override a defaut handler.  But perhaps I should just build the always-true propery tester.(In reply to comment #24)


I'm fine with backing out the patch to remove the quit-rebinding.  Just please remember to do the following:

> As I pointed out in comment #5, this isn't sufficient as you have to disable
> the code that hides menu items referencing org.eclipse.ui.file.exit
> (CocoaUIHandler#redirectHandledMenuItem()).
Comment 26 Oleg Besedin CLA 2012-05-08 11:41:54 EDT
Eric, McQ and I had a hallway discussion on what we want to do here.

We want to limit changes to the code at this point of the release cycle. This means that we won't be providing a "real" fix to the shutdown lifecycle for 4.2.

On the other hand, we don't want to break whatever works now.

So, I'll rollback both changes checked in for this bug and we'll get back to the original status quo (no exit prompt on Mac, but RCP apps can easily intercept exit).

This comes with a *disclaimer*: once we provide proper hooks into shutdown (4.3+), RCP apps might need to change their code. The current behavior is something that "just happened" and once the proper solution is in place it might have to be altered.

Brian, if you feel comfortable providing a small fix for 4.2, you are welcome. Re comment 25 - I am not sure what is the effect of removing "org.eclipse.ui.file.exit" overrides. The only visible effect seems to be the application name ("E4 contacts demo" vs. "Eclipse") that appears for the app menu and app exit submenu. It does not seem to help with prompting on exit.
Comment 28 Eric Moffatt CLA 2012-05-08 11:48:42 EDT
Oleg, I'll +1 this but still want to know if the current behavior ends up saving all the dirty elements...
Comment 29 Oleg Besedin CLA 2012-05-08 11:56:39 EDT
(In reply to comment #28)
> Oleg, I'll +1 this but still want to know if the current behavior ends up
> saving all the dirty elements...

Yes, it does.
Comment 30 Ray Case CLA 2014-05-21 12:07:10 EDT
How about just remove this Key Binding on the Mac?  

Having a keystroke that I can't change and I can accidentally hit isn't on my list of happy thoughts.  

On the PC, I used to use a resource editor to remove the keybinding.  Now on my Mac, I can't change it nor can I delete it.  

I occasionally hit Command-Q when I mean Control-Q and it makes me crazy!!! 

Still not fixed, btw.

Ray
Comment 31 Brian de Alwis CLA 2014-05-21 13:53:11 EDT
I forgot about this bug entirely.  Marking for Mars.
Comment 32 Thibault Le Ouay CLA 2015-02-10 15:39:22 EST
Hey, 

Any update on this one ? 

I accidentally close my eclipse :)

Thibault
Comment 33 Thibault Le Ouay CLA 2015-03-18 16:00:36 EDT
Hey, 

I have tested this behaviour on windows today and alt+F4 show the "confirm exit" dialog, also this command is not bind with the menu, 

IMO we should adopt the same behaviour on osX
Comment 34 Eclipse Genie CLA 2015-05-07 15:53:15 EDT
New Gerrit change created: https://git.eclipse.org/r/47490
Comment 35 Markus Keller CLA 2015-05-07 16:06:29 EDT
For the Mars release, I did some more testing on the Mac, and this bug was a major pain again. I've submitted a new fix on current master.

Brian, could you please approve/review/submit for RC1?
Comment 37 Brian de Alwis CLA 2015-05-07 16:32:19 EDT
Thanks Markus.
Comment 38 Markus Keller CLA 2015-05-11 11:28:33 EDT
Verified in 4.5.0.I20150510-2000 (Mac and Windows).
Comment 39 David Weiser CLA 2017-03-29 08:32:03 EDT
The fix seems scoped only for Mac. We should also consider the "Confirm exit when closing last window" on other platforms, if we select File -> Exit. This will be handled by Bug 512857. I hope that I can also remove the Mac specific coding with this bug.
Comment 40 Dani Megert CLA 2017-03-29 11:43:41 EDT
(In reply to David Weiser from comment #39)
> The fix seems scoped only for Mac. We should also consider the "Confirm exit
> when closing last window" on other platforms, if we select File -> Exit.
> This will be handled by Bug 512857. I hope that I can also remove the Mac
> specific coding with this bug.

Eclipse follows the principle to honor OS behavior and not to make them all work/look the same.