Re: PrefsListener API again

Jeff Hostetler (jeff@abisource.com)
Tue, 19 Oct 1999 15:38:45 -0500


Stephen Hack wrote:
> On Tue, Oct 19, 1999 at 01:05:36PM -0500, Stephen Hack wrote:
> > On Tue, Oct 19, 1999 at 11:04:38AM -0500, Jeff Hostetler wrote:
> ...
> > >
> > > w/r/t PrefsListener API, i'd vote for simplifying it some -- it's
> > > a very low frequency event (like when the user hits OK on the
> > > new dialog or toggles something from the menu), so i don't think
> > > we need the complicated pattern matching stuff.
> > > i'd suggest a simple "tell me when anything changes" listener
> > > and put the responsibility on the actual listener to query
> > > the values it cares about and do the right thing. that way, the
> > > pref code can just send one message to each listener. and each
> > > listener can be rather simple. [one could probably use the same
> > > words in the last 2 sentences to describe the proposed method :-)
> > > but my assertion is that simpler is better and each listener
> > > should have already internalized the value(s) of the pref keys
> > > that it's interested in and can quickly and easily re-fetch and
> > > compare them and quickly return if there's nothing for it to do.]
> > >
> > > we may need to have some kind of suspend-/resume-notifications
> > > method in the prefs, so that the options dialog can set a bunch
> > > of values in a batch and then have one notification go out --
> > > incase setting them individually after the dialog goes down
> > > causes too much flashing.... but we can wait on that.
> > >
> >
> > All add some of that to XAP_Prefs
> > addListener
> > removeListener
> > startBlockChange()
> > endBlockChange()
> >
>
> One problem that I just saw was that sometimes there is a need to know what
> the old value was and the new value will be.

the new value should be set *before* the listener is called.

> On a simular note, how should the listener find out what has changed? Should
> it remember itself the old value, or should the prefs be able to tell it
> somehow?

i think it'd be reasonable for the specific listener to remember
in some private/object storage the last value (or an internalized
form of the last value) for each keyword that it cares about.
for example, somewhere in the frame or tool bar code there should
be a "enum { text, icon, both } m_eToolbarAppearance" member variable
which records how the toolbars are currently being drawn and also
the last know value of the of the "ToolbarAppearance" preferences
value. when the frame or toolbar's pref listener is called, it can
do the right thing. [i suggest having one listener for the frame
or toolbar so that it can deal with all of the relevant keys (such
as toolbar on/off, toolbar language, toolbar appearance, etc) in
one call.]

for values with arbitrary strings, the listener should just keep
a copy of it.

> One possibility is a hash table of all the keys that have changed. That way,
> when each listener is called, it can lookup the key it's interested in in the
> hash table to see if it's changed.

we do notification typing and cacheing like this for changes to the
document -- but this code gets called on every keystroke and mouse
movement. here we're dealing with preferences which change very
seldom and aren't critical path. besides, the computational cost
of running thru this hash and testing for a "hasChanged" and then
doing the getValue() is just as expensive (more so in case of a
changed value) as calling getValue() (which is a hashed lookup) and
testing the actual value with the listeners internal copy...

hope this helps,
jeff



This archive was generated by hypermail 1.03b2.