defaults/preferences
(if it has not been previously created) and place there a .js-file with settings. Here is an example of such a file.* This source code was highlighted with Source Code Highlighter .
- pref ( "extensions.sample.username" , "Joe" );
- pref ( "extensions.sample.sort" , 2);
- pref ( "extensions.sample.showAdvanced" , true );
about:config
page.* This source code was highlighted with Source Code Highlighter .
- init: function ()
- {
- this .prefs = Components.classes [ "@ mozilla.org / preferences-service; 1" ]
- .getService (Components.interfaces.nsIPrefService)
- .getBranch ( "extensions.sample." );
- this .prefs.QueryInterface (Components.interfaces.nsIPrefBranch2);
- this .prefs.addObserver ( "" , this , false );
- }
init
function indicates that all events related to changing settings should be sent to our object.this.prefs
refers to an object with the nsIPrefBranch interface. Read the values ββof any option as follows:* This source code was highlighted with Source Code Highlighter .
- this .prefs.getCharPref ( "username" );
extensions.sample.
as the namespace extensions.sample.
, then the option extensions.sample.username
we created earlier will be read.nsIPrefBranch
interface can be found here .options.xul
file in the chrome/content
directory and add the following content to it:* This source code was highlighted with Source Code Highlighter .
- <? xml version = "1.0" ? >
- <? xml-stylesheet href = "chrome: // global / skin /" type = "text / css" ? >
- < prefwindow id = "test-prefs"
- title = "Test options"
- xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
- < prefpane id = "test-pane" label = "Test Settings" >
- < preferences >
- < preference id = "pref_username" name = "extensions.sample.username" type = "string" />
- </ preferences >
- < hbox align = "center" >
- < label control = "username" value = "Username:" />
- < textbox preference = "pref_username" id = "username" maxlength = "24" />
- </ hbox >
- </ prefpane >
- </ prefwindow >
<prefpane>
is a container for dialog box controls, also this element contains links to component settings.<preferences>
- contains links to options of your component.<preference>
- link to the option. The name
parameter specifies the name of the option, the type
parameter specifies the type of this option ( string
, int
or boolean
), the id
parameter specifies the setting identifier inside the dialog box, by which the controls themselves will read and write the setting values ββ(look at the textbox
preference
attribute)* This source code was highlighted with Source Code Highlighter .
- observe: function (subject, topic, data)
- {
- if (topic! = "nsPref: changed" )
- {
- return ;
- }
- switch (data)
- {
- case "username" :
- alert ( this .getUserName ());
- break ;
- }
- }
subject
- a link to the changed object or event (more details here )topic
- indicates the type of event, in this case we are interested in "nsPref: changed"data
is the data transmitted along with the event, in our case it will be the name of the option that was changedSource: https://habr.com/ru/post/72117/
All Articles