Prefs.jsm library
What is the User Preferences?
Remarks #1
Every preferences have a type. There are three simple types and some complex types.
- boolean
- integer
- string
- and some complex types.
Don't overlap your preference's name to others. Keep to use your original branch (ex. "extensions." or something like that) is a good manner.
Example #1: How to handle the "javascript.options.strict" preference.
- Construct a instance of Prefs Class.
//Specify a branch. Note: you must terminate it with a period.
var prefs = new Prefs("javascript.options.");
- Set the value of preference to true.
prefs.set("strict", true);
- Get the value of preference.
var v = prefs.get("strict");That's all. The library can infer a proper type for the preference automatically (and you can specify it manually if you want).
Reference Manual
function: Prefs aBranchName
Construct a new instance.
aBranchName A branch's name. String. You must terminate it with a period.
function: get aPrefName &optional aDefaultValue aType
Get the value of preference.
aPrefName A preference's name. String.
aDefaultValue A return value when the function failed to get.
aType A type of preference. String. Please see the table.1 below.
function: set aPrefName aValue &optional aType aRelFileRelativeToKey
Set the value of preference.
aPrefName A preference's name. String.
aValue A value to set.
aType A type of preference. String. Please see the table.2 below.
aRelFileRelativeToKey A keyword for the relative file path's root directory(ex. "ProfD", etc). String.
function: clear aPrefName
Clear the preference.
aPrefName A preference's name. String.
function: getChildList &optional aStartingAt
Get the array of preferences' name of below the branch.
aStartingAt A branch's name. String.
Table.1: aType for get
type | aType | calls internally |
boolean | "boolean" | getBoolPref(aPrefName) |
integer | "integer" | getIntPref(aPrefName) |
string | "string" | getComplexValue(aPrefName, Ci.nsISupportsString).data |
localized string | "localized" | getComplexValue(aPrefName, Ci.nsIPrefLocalizedString).data |
absolute file path | "file" | getComplexValue(aPrefName, Ci.nsILocalFile) |
relative file path | "relFile" | getComplexValue(aPrefName, Ci.nsIRelativeFilePref) |
Table.2: aType for set
type | aType | calls internally |
boolean | "boolean" | setBoolPref(aPrefName, !!aValue) |
integer | "integer" | setIntPref(aPrefName, +aValue) |
string | "string" | setComplexValue(aPrefName, Ci.nsISupportsString, nsISupportsString's instance) |
localized string | "localized" | setComplexValue(aPrefName, Ci.nsIPrefLocalizedString, nsIPrefLocalizedString's instance |
absolute file path | "file" | setComplexValue(aPrefName, Ci.nsILocalFile, aValue) |
relative file path | "relFile" | setComplexValue(aPrefName, Ci.nsIRelativeFilePref, nsIRelativeFilePref's instance) |
Please refer the File I/O - MDC about the relative file path.
No comments:
Post a Comment