Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

Mozilla Preferences helper library


var $Prefs = {
        _getBranch : Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch),
        _getService : Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService),
                
        set : function(pref_name, pref_value) {
                var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
                str.data = pref_value.replace(/^\s*|\s*$/g,'');
                (this._getBranch).setComplexValue(pref_name, Components.interfaces.nsISupportsString, str);
        },
        
        get : function(pref_name){
                try{
                        return (this._getBranch).getComplexValue(pref_name,Components.interfaces.nsISupportsString).data;
                }
                catch(e){ return false;}
        },

        remove : function(pref_name){
                try{
                        (this._getBranch).clearUserPref(pref_name)
                }
                catch(e){}
        },
                
        remove_all : function(pref_name){
                try{
                        (this._getBranch).deleteBranch(pref_name,'')
                }
                catch(e){}
        },
                        
        branch : function(pref_name){
                var serialBranch = (this._getService).getBranch(pref_name+'.');
                return serialBranch.getChildList("",{});
        }
}
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed