nsIPromptService.confirmEx : buttons show up in the order 0,2,1 instead of 0,1,2

RESOLVED INVALID

Status

()

Core
Embedding: APIs
RESOLVED INVALID
7 years ago
7 years ago

People

(Reporter: Tyler Breisacher, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

7 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Build Identifier: Mozilla Firefox 3.6.13

Copied from a comment on bug 345067:

I used MDC example for confirmEx:

var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                        .getService(Components.interfaces.nsIPromptService);

var check = {value: false};                  // default the checkbox to false

var flags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_SAVE +
            prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_IS_STRING  +
            prompts.BUTTON_POS_2 * prompts.BUTTON_TITLE_CANCEL;
// This value of flags will create 3 buttons. The first will be "Save", the
// second will be the value of aButtonTitle1, and the third will be "Cancel"

var button = prompts.confirmEx(null, "Title of this Dialog", "What do you want
to do?",
                               flags, "", "Button 1", "", null, check);


This example tells I should get prompt with buttons:
  "Save", "Button 1", "Cancel"
But instead I get 
  "Save", "Cancel", "Button 1"

Tested on Thunderbird 3.0.4 and 3.1 beta 2, Windows XP. (End of copied comment)

I can also confirm that this happens in Firefox 3.6.13 and Firefox 4.0b8

Reproducible: Always

Steps to Reproduce:
Use nsIPromptService.confirmEx as described above
Actual Results:  
Buttons show up in order: "Save", "Cancel", "Button 1"

Expected Results:  
Buttons show up in order: "Save", "Button 1", "Cancel"

It seems unlikely that this happened by mistake, so maybe it was deliberately designed this way. If so, could someone describe why that choice was made?
The documentation clearly says:

230    * Buttons are numbered 0 - 2. The implementation can decide whether the
231    * sequence goes from right to left or left to right.  Button 0 is the
232    * default button unless one of the Button Default Flags is specified.

In particular, the positioning depends on the OS and on how dialogs usually behave on that OS when they have multiple buttons.  Can't tell you whether the behavior you see is right for WinXP, but I'd expect it is.
This is indeed intentional. This is because the order of buttons varies by platform convention.

For example, on OS X a dialog should have (left to right) [Cancel] [Ok], whereas on Windows a dialog should have [Ok] [Cancel]. Similarly, for 3 buttons OS X should be [Foo] [Cancel] [Ok], and Windows should be [Ok] [Foo] [Cancel].

So, your code should be:

var flags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_SAVE +
            prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_CANCEL  +
            prompts.BUTTON_POS_2 * prompts.BUTTON_TITLE_IS_STRING;

If you had some unusual reason for using custom strings on all 3 buttons and platform convention somehow doesn't apply [hint: this is a good sign you're going down the wrong path], then you'd need to adjust how you set up the prompt on a per-platform basis.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → INVALID
(Reporter)

Comment 3

7 years ago
(In reply to comment #1)
> The documentation clearly says:
> 
> 230    * Buttons are numbered 0 - 2. The implementation can decide whether the
> 231    * sequence goes from right to left or left to right.  Button 0 is the
> 232    * default button unless one of the Button Default Flags is specified.

I took that to mean that the order would be 0,1,2 on some platforms and 2,1,0 on others. But I guess it's Windows being weird in this case, not Firefox. Thanks for the responses.
You need to log in before you can comment on or make changes to this bug.