[Project_owners] Reset user preferences to default?

David Duong david.nqd at gmail.com
Sat Feb 11 14:07:41 EST 2006


Works like a charm.  Thanks!

On 2/10/06, GuruJ <GuruJ at mbox.com.au> wrote:
>
> Hi all,
>
> Must admit I haven't tested the 'delete' code in my Preferential project
> extensively (I'm mainly interested in adding and modifying values), but
> the code I use is:
>
>      var prefService =
> Components.classes["@mozilla.org/preferences-service;1"].getService(
> Components.interfaces.nsIPrefService);
>      var prefBranch = prefService.getBranch(null);
>
>      if (document.getElementById('deleteType').value == "reset") {
>          try {
>              prefBranch.clearUserPref(pref);
>              var msg = gBundle.getString("msgSuccessReset");
>          }
>          catch (e) {
>              var msg = gBundle.getString("msgErrorReset");
>          }
>      }
>      else {
>          try {
>              prefBranch.deleteBranch(pref);
>              var msg = gBundle.getString("msgSuccessDelete");
>          }
>          catch (e) {
>              var msg = gBundle.getString("msgErrorDelete");
>          }
>      }
>      // Reload source prefs window
>      reload(msg);
>      window.close();
>
> Regards,
>
> -- GuruJ.
>
> David Murray wrote:
> > What happens if you take the trailing dot off the branch? ie.
> > prefs.resetBranch('extensions.termblaster'); ?
> >
> > David Duong wrote:
> >> Thanks, but that was just a typo ;p.  I have 'nsIPrefBranch' which is
> >> returning the NS_ERROR_NOT_IMPLEMENTED
> >>
> >> I meant to write:
> >>   var prefs = Components.classes["@ mozilla.org/preferences-service;1
> >> <http://mozilla.org/preferences-service;1>"].
> >>       getService(Components.interfaces.nsIPrefBranch);
> >>   prefs.resetBranch('extensions.termblaster.');
> >>
> >> Is there a standard way to reset preferences?
> >>
> >> On 2/9/06, *HJ* <bugs4hj at netscape.net <mailto:bugs4hj at netscape.net>>
> >> wrote:
> >>
> >>     David Duong wrote:
> >>      > Hi,
> >>      >
> >>      > I'm trying to reset my extension's preferences to default
> >> values and
> >>      > came accross the function "resetBranch" of
> >> "preferences-service".  (
> >>      >
> >>
> >>
> http://www.xulplanet.com/references/xpcomref/comps/c_preferencesservice1.html
> )
> >>
> >>      >
> >>      > So something like:
> >>      >   var prefs =
> >>     Components.classes["@mozilla.org/preferences-service;1
> >>     <http://mozilla.org/preferences-service;1>
> >>      > <http://mozilla.org/preferences-service;1 >"].
> >>      >       getService(Components.interfaces.nsIPrefService);
> >>      >   prefs.resetBranch('extensions.myext.');
> >>      >
> >>      > Should work, but it only causes a not implemented error.  What
> >> is the
> >>      > best way to reset extension preferences?
> >>
> >>     Right, just replace 'nsIPrefService' with 'nsIPrefBranch' ;)
> >>
> >>     /HJ
> >>     _______________________________________________
> >>     Project_owners mailing list
> >>     Project_owners at mozdev.org <mailto:Project_owners at mozdev.org>
> >>     http://mozdev.org/mailman/listinfo/project_owners
> >>
> >>
> >>
> >>
> ------------------------------------------------------------------------
> >>
> >> _______________________________________________
> >> Project_owners mailing list
> >> Project_owners at mozdev.org
> >> http://mozdev.org/mailman/listinfo/project_owners
> >
> > _______________________________________________
> > Project_owners mailing list
> > Project_owners at mozdev.org
> > http://mozdev.org/mailman/listinfo/project_owners
> >
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mozdev.org/pipermail/project_owners/attachments/20060211/d94d829c/attachment.htm


More information about the Project_owners mailing list