Preferences System:preference
From MDC
Contents |
[edit] Overview
<preference> is a representation of a preference, an element that is used as an intermediary between UI elements and items in user preferences.
It must be a direct child of <preferences>.
[edit] XUL Syntax
<preference id="pref_id" name="preference.name" type="int"/>
[edit] Attributes
-
id - The id of the element, it's used as a value of
preferenceattribute on UI elements. -
instantApply - You can set this attribute to
trueto make the preference apply instantly, even when the global setting is not to use instant apply. -
inverted - (Applies only to prefs with
type="bool".) When this is set totrue, the value on the associated UI element is a negation of the value stored in user preferences. -
name - The preference it controls (e.g. browser.preferences.instantApply).
-
readonly - When set to true, changing the value of associated UI elements doesn't affect the preference. Note that setting this attribute to
truedoesn't disable the UI element. -
type - The type of the preference. Possible values are:
int,bool,string(for non-unicode (ASCII) strings),wstring(likensIPrefLocalizedString),unichar(unicode string),file(nsIFile).
[edit] Properties
-
defaultValue(readonly) - Returns the default value of the preference. The type of the property depends on the value of the
typeproperty. -
disabled(boolean) - Gets/sets the value of
disabledattribute, also updatingdisabledproperty of associated UI elements. (but initial value of attribute doesn't seem to have any effect??) -
hasUserValue(readonly boolean) - Returns
trueif the preference has a user value set. -
instantApply(readonly boolean) - Whether to use instant apply for this preference. This is
trueif either the element has aninstantApplyattribute set totrue, or the<prefwindow>'sinstantApplyproperty istrue. (But note bug 293439.) -
inverted(boolean) - Gets and sets the value of the
invertedattribute. -
locked(readonly boolean) - Returns
trueif the preference is locked. -
name(string) - Gets and sets the value of the
nameattribute. -
preferences(readonly DOMElement) - Parent
<preferences>element. -
readonly(boolean) - Gets and sets the value of the
readonlyattribute. -
tabIndex(integer) - Gets/sets the value of
tabindexattribute, also updating tab index of associated UI elements. (?? same comment as fordisabled) -
type(string) - Gets and sets the value of the
typeattribute. -
value - The current value of the preference. If instantApply is on, this is always equal to
valueFromPreferences. Otherwise, it's the current value of associated UI elements, i.e. what user currently sees. -
valueFromPreferences - Gets and sets the value stored in the user preference, specified in
name.
[edit] Methods
-
type getElementValue(in DOMElement element); - Retrieves the value that should be written to preferences based on the current state of the supplied element. This function calls
onsynctopreference. -
boolean isElementEditable(in DOMElement element) - Returns
true, if the given element is "editable" (see below). -
void reset(); - Resets the preference to its default value.
- Note: this method throws an exception if the preference doesn't have a user value set yet.
-
void setElementValue(in DOMElement element); - Initializes the supplied element from the value stored in the preference. This function calls
onsyncfrompreference. -
void updateElements(); - Update all elements that observe this preference.
[edit] Events
-
change - When a preference value changes, an
onchange/changeevent is fired on the <preference> element. You can handle this if you wish to.
Preferences System documentation:
- Introduction: Getting Started | Examples | Troubleshooting
- Reference: <prefwindow> | <prefpane> | <preferences> | <preference> | New attributes