[Pharo-project] Fwd: [squeak-dev] [ANN] Preference pragmas

Cédrick Béler cdrick65 at gmail.com
Wed Mar 4 05:26:51 EST 2009

As some of us are unregistered, I thought it could be of interest ;)

---------- Forwarded message ----------
From: Andreas Raab <andreas.raab at gmx.de>
Date: 2009/3/4
Subject: [squeak-dev] [ANN] Preference pragmas
To: The general-purpose Squeak developers list
<squeak-dev at lists.squeakfoundation.org>

Folks -

I wanted to make the property whether to show individual processes in
MessageTally a preference and couldn't recall any of the three
gazillion methods to create one ;-) So I decided enough is enough and
added the ability to register a preference via Pragma. In other words,
you specify two class side accessors (using MessageTally as example):

       "Indicates whether to show each process separately or cumulatively."
       <preference: 'Show Processes in MessageTally'
               category: 'debug'
               balloonHelp: 'If enabled, each profiled process is
shown individually in MessageTally'
               type: #Boolean>

showProcesses: aBool
       "Indicates whether to show each process separately or cumulatively."
       ShowProcesses := aBool.

and then register the preference in the class initialization method via:

       "MessageTally initialize"
       "By default, show each process separately"
       ShowProcesses := true.
       "Register preferences"
       Preferences addPreferencesFor: self.

The nice thing about this scheme is that the preference is local to
the code where it's used and that there are no more generated
accessors which mess up Monticello packages etc. What could probably
be improved is the self-registration; I left it that way for now since
I don't know how expensive it would be to scan all classes for new
preferences when one opens a preference browser. There is also an
example class PreferenceExample that illustrates the different types
of preferences (textual, numeric, color, boolean) you can use.

To install, just execute the following from Squeak 3.10.2:

  Installer mantis fixBug: 7306.

 - Andreas


More information about the Pharo-dev mailing list