Visit Mozilla.org

XUL:prefwindow

From MDC

« XUL Reference home    [ Examples | Attributes | Properties | Methods | Related ]

A specialized window used for preference dialogs. This element should be used in place of the window tag and should contain one or more prefpane elements. A row of buttons appears across the preference dialog, one for each prefpane. Each pane will usually group together a set of related preferences. If there is only one prefpane, the navigation area will be hidden.

On platforms where the convention is to apply changes immediately, the preferences are adjusted as soon as the user interface element is changed. On other platforms, the preferences are not applied until the dialog is closed.

You can open a preference window using a window's openDialog method as with other dialogs. You can pass the id of a particular pane as the fourth argument to openDialog to open a specific pane by default. You can also set the lastSelected attribute on the prefwindow tag to the id of the pane to start with. Normally, you would not set this attribute as it will be set automatically such that the default pane is the same as the one showing when the preferences dialog was last closed.

More information is available in the Preferences System article.

Attributes
buttonalign, buttondir, buttonorient, buttonpack, buttons, defaultButton, lastSelected, onbeforeaccept, ondialogaccept, ondialogcancel, ondialogdisclosure, ondialoghelp, onpaneload, title, type
Properties
buttons, currentPane, defaultButton, lastSelected, preferencePanes, type
Methods
acceptDialog, addPane, cancelDialog, centerWindowOnScreen, getButton, openSubDialog, openWindow, showPane

[edit] Examples

   <prefwindow xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     <prefpane id="saveoptions" label="Backups">
       <preferences>
         <preference id="pref-backup" name="myapp.mybackups" type="bool"/>
         <preference id="pref-backupduration" name="myapp.mybackups.duration" type="int"/>
       </preferences>
       <checkbox label="Automatically Save Backups" preference="pref-backup"/>
       <textbox label="Duration:" preference="pref-backupduration"/>
     </prefpane>
   </prefwindow>

[edit] Attributes

Inherited from XUL element
align, allowevents, allownegativeassertions, class, coalesceduplicatearcs, collapsed, container, containment, context, contextmenu, datasources, dir, empty, equalsize, flags, flex, height, hidden, id, insertafter, insertbefore, left, maxheight, maxwidth, menu, minheight, minwidth, mousethrough, observes, ordinal, orient, pack, persist, popup, position, preference-editable, querytype, ref, removeelement, sortDirection, sortResource, sortResource2, statustext, style, template, tooltip, tooltiptext, top, uri, wait-cursor, width

buttonalign
Type: string
The value of the align attribute for the box containing the buttons.


buttondir
Type: string
The value of the dir attribute for the box containing the buttons.


buttonorient
Type: string
The value of the orient attribute for the box containing the buttons.


buttonpack
Type: string
The value of the pack attribute for the box containing the buttons.


buttons
Type: comma-separated list of the values below
A comma-separated list of buttons to appear on the dialog box. The buttons will be placed in suitable locations for the user's platform and basic event handling will be performed automatically. The following values can be used in the list:
  • accept: The OK button, which will accept the changes when pressed. This button will also be the default button.
  • cancel: The cancel button which will cancel the operation.
  • help: A help button for displaying help about the dialog.
  • disclosure: A button to show more information. This might be a button or a disclosure triangle.
  • extra1: An optional additional button. You can set its label with the buttonlabelextra1 attribute.
  • extra2: A second optional additional button. You can set its label with the buttonlabelextra2 attribute.

defaultButton
Type: string
Normally this attribute should not be set, but if it is, it specifies the default button in the dialog. Typically, this means that the button will be activated when the Enter key is pressed. This should be set to one of the same values as those for the buttons attribute.


lastSelected
Type: string
Set this to the id of the last selected pane. It will be opened by default the next time the preferences dialog is opened.


onbeforeaccept
Type: script code
The code in this attribute is called when the OK button is pressed or the acceptDialog method is called.

ondialogaccept
Type: script code
The code in this attribute is called when the accept button is pressed, or when the acceptDialog method is called. If the handler returns true, the dialog will indeed go away, but if it returns false it will not.

ondialogcancel
Type: script code
The code in this attribute is called when the "cancel" button is pressed or when the cancelDialog method is called. If the routine returns true, the dialog will indeed go away, but if it returns false it will not.

ondialogdisclosure
Type: script code
The code in this attribute is called when the "disclosure" button is pressed.

ondialoghelp
Type: script code
The code in this attribute is called when the "help" button is pressed.

onpaneload
Type: script code
Code defined here is called when the pane has been loaded, much like the load event for a window.

title
Type: string
The text to appear in the title bar of the window.

type
Type: string
Set this attribute to child for preference dialogs that are child dialogs of a main preferences window. This ensures that the preferences are only saved when the main dialog is closed, if this is the appropriate behaviour for the platform.

[edit] Properties

Inherited from XUL element
align, allowEvents, boxObject, builder, className, collapsed, contextMenu, controllers, currentItem, database, datasources, dir, flex, height, hidden, id, left, listBoxObject, maxHeight, maxWidth, menu, minHeight, minWidth, observes, ordinal, orient, pack, persist, ref, resource, statusText, style, tooltip, tooltipText, top, value, width

Inherited from DOM element
attributes, childNodes, cloneNode, firstChild, lastChild, localName, namespaceURI, nextSibling, nodeName, nodeType, nodeValue, ownerDocument, parentNode, prefix, previousSibling, tagName

buttons
Type: comma-separated list of the values below
A comma-separated list of buttons to appear on the dialog box. The buttons will be placed in suitable locations for the user's platform and basic event handling will be performed automatically. The following values can be used in the list:
  • accept: The OK button, which will accept the changes when pressed. This button will also be the default button.
  • cancel: The cancel button which will cancel the operation.
  • help: A help button for displaying help about the dialog.
  • disclosure: A button to show more information. This might be a button or a disclosure triangle.
  • extra1: An optional additional button. You can set its label with the buttonlabelextra1 attribute.
  • extra2: A second optional additional button. You can set its label with the buttonlabelextra2 attribute.

currentPane
Type: prefpane element
Reference to the currently displayed pane. To change the current pane, use the showPane method.

defaultButton
Type: string
Normally this attribute should not be set, but if it is, it specifies the default button in the dialog. Typically, this means that the button will be activated when the Enter key is pressed. This should be set to one of the same values as those for the buttons attribute.

lastSelected
Type: string
Set this to the id of the last selected pane. It will be opened by default the next time the preferences dialog is opened.

preferencePanes
Type: DOM NodeList
Holds a list of all the prefpane elements in the window.

type
Type: string
Gets and sets the value of the type attribute.

[edit] Methods

Inherited from XUL element
blur, click, doCommand, focus, getElementsByAttribute

Inherited from DOM element
addEventListener, appendChild, dispatchEvent, getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getElementsByTagName, getElementsByTagNameNS, hasAttribute, hasAttributeNS, hasAttributes, hasChildNodes, insertBefore, isSupported, normalize, removeAttribute, removeAttributeNode, removeAttributeNS, removeChild, removeEventListener, replaceChild, setAttribute, setAttributeNode, setAttributeNodeNS, setAttributeNS

acceptDialog()
Return type: no return value
Accepts the dialog and closes it, similar to pressing the OK button.

addPane( prefpane )
Return type: no return value
Append a prefpane to a list of panes.

cancelDialog()
Return type: no return value
Cancels the dialog and closes it, similar to pressing the Cancel button.

centerWindowOnScreen()
Return type: no return value
Centers the dialog on the screen.

getButton( type )
Return type: button element
Returns the button element in the dialog corresponding to the given type.

openSubDialog( url, features, params )
Return type: window
Opens a child modal dialog. Usually this method would be used to allow the user to configure advanced options. The arguments are similar to the window's openDialog method except that the window name does not need to be supplied. The url should be a XUL file. If the child dialog is also a prefwindow, set its type attribute to child so that preferences will be saved properly when the main dialog is closed.

openWindow( windowtype, url, features, params )
Return type: window
Open a child window. The windowtype is a string specifying a window type. If a window with that type is already open, this method will just switch that window to the front and focus it instead of opening another window. If a window of the type is not open, a new one is opened displaying the supplied url.

showPane( prefpane )
Return type: no return value
Switch to a particular pane.

[edit] Related

TBD