1 var webdeveloper_preferencesService
= null;
3 // Deletes a preference
4 function webdeveloper_deletePreference(preference
)
6 // If the preference is set
9 // If a user preference is set
10 if(webdeveloper_isPreferenceSet(preference
))
12 webdeveloper_getPreferencesService().clearUserPref(preference
);
17 // Deletes a preference branch
18 function webdeveloper_deletePreferenceBranch(branch
)
20 // If the branch is set
23 webdeveloper_getPreferencesService().deleteBranch(branch
);
27 // Gets a boolean preference, returning false if the preference is not set
28 function webdeveloper_getBooleanPreference(preference
, userPreference
)
30 // If the preference is set
33 // If not a user preference or a user preference is set
34 if(!userPreference
|| webdeveloper_isPreferenceSet(preference
))
38 return webdeveloper_getPreferencesService().getBoolPref(preference
);
50 // Gets an integer preference, returning 0 if the preference is not set
51 function webdeveloper_getIntegerPreference(preference
, userPreference
)
53 // If the preference is set
56 // If not a user preference or a user preference is set
57 if(!userPreference
|| webdeveloper_isPreferenceSet(preference
))
61 return webdeveloper_getPreferencesService().getIntPref(preference
);
73 // Gets the preferences service
74 function webdeveloper_getPreferencesService()
76 // If the preferences service is not set
77 if(!webdeveloper_preferencesService
)
79 webdeveloper_preferencesService
= Components
.classes
["@mozilla.org/preferences-service;1"].getService(Components
.interfaces
.nsIPrefService
).getBranch("");
82 return webdeveloper_preferencesService
;
85 // Gets a string preference, returning null if the preference is not set
86 function webdeveloper_getStringPreference(preference
, userPreference
)
88 // If the preference is set
91 // If not a user preference or a user preference is set
92 if(!userPreference
|| webdeveloper_isPreferenceSet(preference
))
96 return webdeveloper_getPreferencesService().getComplexValue(preference
, Components
.interfaces
.nsISupportsString
).data
.trim();
108 // Is a preference set
109 function webdeveloper_isPreferenceSet(preference
)
111 // If the preference is set
114 return webdeveloper_getPreferencesService().prefHasUserValue(preference
);
120 // Sets a boolean preference
121 function webdeveloper_setBooleanPreference(preference
, value
)
123 // If the preference is set
126 webdeveloper_getPreferencesService().setBoolPref(preference
, value
);
130 // Sets a boolean preference if it is not already set
131 function webdeveloper_setBooleanPreferenceIfNotSet(preference
, value
)
133 // If the preference is not set
134 if(!webdeveloper_isPreferenceSet(preference
))
136 webdeveloper_getPreferencesService().setBoolPref(preference
, value
);
140 // Sets an integer preference
141 function webdeveloper_setIntegerPreference(preference
, value
)
143 // If the preference is set
146 webdeveloper_getPreferencesService().setIntPref(preference
, value
);
150 // Sets an integer preference if it is not already set
151 function webdeveloper_setIntegerPreferenceIfNotSet(preference
, value
)
153 // If the preference is not set
154 if(!webdeveloper_isPreferenceSet(preference
))
156 webdeveloper_setIntegerPreference(preference
, value
);
160 // Sets a string preference
161 function webdeveloper_setStringPreference(preference
, value
)
163 // If the preference is set
166 var supportsStringInterface
= Components
.interfaces
.nsISupportsString
;
167 var string
= Components
.classes
["@mozilla.org/supports-string;1"].createInstance(supportsStringInterface
);
171 webdeveloper_getPreferencesService().setComplexValue(preference
, supportsStringInterface
, string
);
175 // Sets a string preference if it is not already set
176 function webdeveloper_setStringPreferenceIfNotSet(preference
, value
)
178 // If the preference is not set
179 if(!webdeveloper_isPreferenceSet(preference
))
181 webdeveloper_setStringPreference(preference
, value
);