Bug 284776 - Need support in dialog.xml for setting a default button. r=mconnor a=asa.

This commit is contained in:
mozilla.mano%sent.com 2005-06-18 10:21:49 +00:00
Родитель b063de55c4
Коммит dea4254a31
1 изменённых файлов: 46 добавлений и 7 удалений

Просмотреть файл

@ -59,6 +59,23 @@
onget="return this.getAttribute('buttons');"
onset="this._configureButtons(val); return val;"/>
<property name="defaultButton">
<getter>
<![CDATA[
if (this.hasAttribute("defaultButton"))
return this.getAttribute("defaultButton");
else // default to the accept button
return "accept";
]]>
</getter>
<setter>
<![CDATA[
this._setDefaultButton(val);
return val;
]]>
</setter>
</property>
<method name="acceptDialog">
<body>
<![CDATA[
@ -256,8 +273,8 @@
}
}
// ensure that hitting enter triggers ondialogaccept
buttons["accept"].setAttribute("default", "true");
// ensure that hitting enter triggers the default button command
this.defaultButton = this.defaultButton;
// if there is a special button configuration, use it
if (aButtons) {
@ -288,7 +305,30 @@
]]>
</body>
</method>
<method name="_setDefaultButton">
<parameter name="aNewDefault"/>
<body>
<![CDATA[
// remove the default attribute from the previous default button, if any
var oldDefaultButton = this.getButton(this.defaultButton);
if (oldDefaultButton)
oldDefaultButton.removeAttribute("default");
var newDefaultButton = this.getButton(aNewDefault);
if (newDefaultButton) {
this.setAttribute("defaultButton", aNewDefault);
newDefaultButton.setAttribute("default", "true");
}
else {
this.setAttribute("defaultButton", "none");
if (aNewDefault != "none")
dump("invalid new default button: " + aNewDefault + ", assuming: none\n");
}
]]>
</body>
</method>
<method name="_handleButtonCommand">
<parameter name="aEvent"/>
<body>
@ -364,10 +404,9 @@
if (!this.enterDefaultAlways && evt.getPreventDefault())
return;
// only accept dialog if accept button is the default
var btn = this.getButton("accept");
if (btn && btn.hasAttribute("default"))
this.acceptDialog();
var btn = this.getButton(this.defaultButton);
if (btn)
this._doButtonCommand(this.defaultButton);
]]>
</body>
</method>