Skip to main content
Engineering LibreTexts

4.7: Start-Up Actions Management

  • Page ID
    44002
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Even if many preferences have been removed from Pharo because they were obsolete, there are a still a large number of them. And even if the Settings Browser is easy to use, it may be tedious to set up your own preferences even for a subset, each time you start working with a new image. A solution is to implement a script to set all your preferred choices. The best way is to create a specific class for that purpose. You can then include it in a package that you can reload each time you want to setup a fresh image. We call this kind of class a Setting style.

    To manage Setting styles, the Settings Browser can be helpful in two ways. First, it can help you discover how to change a preference value, and second, it can create and update a particular style for you.

    Scripting settings

    Because preference variables are all accessible with accessor methods, it is naturally possible to initialize a set of preferences in a simple script. For the sake of simplicity, let’s implement it in a Setting style.

    As an example, a script can be implemented to change the background color and to set all fonts to a bigger one than the default. Let’s create a Setting style class for that. We can call it MyPreferredStyle. The script is defined by a method of MyPreferredStyle. We call this method loadStyle because this selector is the standard hook for settings related script evaluating.

    MyPreferredStyle>>loadStyle
        |fn|
        "Desktop color"
        PolymorphSystemSettings desktopColor: Color white.
        "Bigger font"
        n := StandardFonts defaultFont. "get the current default font"
        f := LogicalFontfamilyName: n familyName pointSize: 12. "font for my preferred size"
        StandardFonts setAllStandardFontsTo: f "reset all fonts"
    

    PolymorphSystemSettings is the class in which all settings related to PolyMorph are declared. StandardFonts is the class that is used to manage Pharo default fonts.

    Now, the question is if the desktop color setting is declared in PolymorphSystemSettings and that the DefaultFonts class allows fonts management? Where are all these settings declared and managed in general?

    The answer is quite simple: just use the Settings Browser! As explained in Section 5.2, cmd-b or double clicking on an item open a browser on the declaration of the current setting node. You can also use the contextual menu for that. Browsing the declaration will give you the target class (where the preference variable is stored) and the selector for the preference value.

    Now we would like MyPreferredStyle>>#loadStyle to be automatically evaluated when MyPreferredStyle is itself loaded in the system. For that purpose, the only thing to do is to implement an initialize method for the MyPreferredStyle class:

    MyPreferredStyle class>>initialize
        self new loadStyle
    

    Integrating a style in the Settings Browser

    Any script can be integrated in the Settings Browser so that it could be loaded, browsed or even removed from it. For that purpose you only have to declare a name for it and to make sure that the Settings Browser will discover it. Just implement a method named styleName on the class side of your style class. Concerning the example of previous section, it should be implemented as follows:

    MyPreferredStyle class>>styleName
        "The style name used by the SettingBrowser"
        <settingstyle>
        ^ 'My preferred style'
    

    MyPreferredStyle class>>styleName takes no argument and must return the name of your style as a String. The <settingstyle> pragma is used to let the Settings Browser know that MyPreferredStyle is a setting style class.

    Once this method is compiled, open the Setting Browser and popup the Style top menu. As shown by Figure \(\PageIndex{1}\), you should see a dialog with a list of style names comprising your own one.

    Load style dialog.
    Figure \(\PageIndex{1}\): The dialog for loading style with your own style.

    This page titled 4.7: Start-Up Actions Management is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Alexandre Bergel, Damien Cassou, Stéphane Ducasse, Jannik Laval (Square Bracket Associates) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.