[Project_owners] Apply Options dialog changes

Chris Means cmeans at spatialpoint.com
Tue Nov 30 23:38:45 EST 2004


I have the preferences observer working.  (Thanks!)

However, I've run into one small issue.

If the user selects the OK button on my options dialog, although the changes
are applied, the observer is never fired.  If I stick a window.alert("")
inbetween the preferences being saved and the window.close(), then my
observer is called.

I also have an Apply button on my options dialog, it works fine.

So, is there's some sort of an issue with a the observer being called at the
same time a window is being closed?

Assuming I can't get around this problem (though I'm sure there's a simple
solution), is there someway I can programatically hold off the
window.close() until the other events have had a chance to fire?

TIA.

-Chris

> -----Original Message-----
> From: project_owners-bounces at mozdev.org 
> [mailto:project_owners-bounces at mozdev.org] On Behalf Of HJ
> Sent: Tuesday, November 30, 2004 2:31 AM
> To: project_owners at mozdev.org
> Subject: Re: [Project_owners] Apply Options dialog changes
> 
> Ben Bucksch wrote:
> > HJ wrote:
> > 
> >> Chris Means wrote:
> >>
> >>> I'm finishing up an extension that updates the status bar 
> with a users'
> >>> current SETI @ Home statistics.
> >>
> >>
> > Where's your project hosted (i.e. URL)?
> > 
> >> I'm not sure what you want/need, but this might help:
> >>
> >> // Setup observer
> >> observerService =
> >> 
> Components.classes["@mozilla.org/observer-service;1"].getService(Comp
> >> onents.interfaces.nsIObserverService);
> >>
> >> observerService.addObserver(setiObserver, "updateSETI", false);
> >>
> >> // Trigger update (should be used in Options dialog) 
> >> observerService.notifyObservers(null, "updateSETI", "update");
> > 
> > 
> > There's a special observer for pref changes (assuming your 
> options are 
> > stored in Mozilla's pref.js), see e.g. nsHttpHandler::Init() in 
> > netwerk/protocols/http/. Not sure why they use (the internal) 
> > nsIPrefBranchInternal, though.
> > 
> > Ben
> 
> Yes indeed, so this info might be useful:
> 
> Adding a pref observer can be done with: 
> addPrefListener(setiPrefListener);
> and removing with: removePrefListener(setiPrefListener);
> and the prefListener could be something like:
> 
> const setiPrefListener =
> {
>    domains: [ "seti.pref.string-1",
>               "seti.pref.string-2" ],
> 
>    observe: function(subject, topic, aPrefString) {
>      // Is this a pref change?
>      if (topic != "nsPref:changed")
>        return;
> 
>      var prefValue;
>      var prefType = pref.getPrefType(aPrefString);
>      var prefModified = prefHasUserValue(aPrefString);
> 
>      switch(prefType) {
>        case nsIPrefBranch.PREF_STRING: // 32
>             prefValue = pref.getComplexValue(aPrefString).data;
>             break;
>        case nsIPrefBranch.PREF_INT: // 64
>             prefValue = pref.getIntPref(aPrefString);
>             break;
>        case nsIPrefBranch.PREF_BOOL: // 128
>             prefValue = pref.getBoolPref(aPrefString);
>             break;
>        default: return; // PREF_INVALID; // 0
>      }
> 
>      if (aPrefString == this.domains[0]) {
>        // do whatever is needed here
>      }
>      else if (aPrefString == this.domains[1]) {
>        // do whatever is needed here
>      }
>    }
> };
> 
> and a possible replacement for function addPrefListener could 
> be something like:
> 
> function addPrefListener(observer)
> {
>    var domains = ("domains" in observer) ? observer.domains : 
> [observer.domain];
>    try {
>      var prefBranchInternal =
> pref.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
>      for (var i = 0; i < domains.length; i++)
>        prefBranchInternal.addObserver(domains[i], observer, false);
>    } catch(ex) {
>      dump("Failed to observe pref: " + domains[i] + "\n");
>    }
> }
> 
> because this function is capable of adding a set of observers 
> in one run.
> 
> See also: 
> http://lxr.mozilla.org/seamonkey/source/modules/libpref/public
> /nsIPrefBranchInternal.idl
> http://lxr.mozilla.org/seamonkey/source/modules/libpref/public
> /nsIPrefBranch.idl
> for more info.
> 
> /HJ
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 



More information about the Project_owners mailing list