Satimage Previous
Having a dialog prune Smile
Home Documentation Smile Custom GUI Developing your own custom dialog Making a dialog stand-alone Having a dialog prune Smile  
To have your dialog launch Smile in a minimal state, in order to reduce the user's interface to nothing more than what your dialog requires, you will want to handle 1 - the Worksheet, 2 - the menus, and you may want to handle 3 - the closing of your dialog in order for instance to have Smile quit when the user closes your dialog.
This pages includes a link to download a sample of such a "Smile-pruning" dialog.
  • Once Smile installed on their machine for the first time, when the user double-clicks the dialog and launches Smile for the first time, the Worksheet window will open with a welcome message. If this is not what you want, you have to close the Worksheet when your dialog opens. Furthermore, you may want to disable the automatic opening of the Worksheet, so that next time it will not show up at all. To have that done when the dialog opens, you program it in the prepare handler.
    We recommend to take these steps only if this is the first run of Smile on the user's machine. Otherwise, either the user is already familiar with the Worksheet or the Worksheet was already disactivated. The number of launches of Smile is stored in the permanent variable my nRuns.
    An excerpt of a script to take care of the Worksheet could be the following.
    on prepare theDlog
        [...]
        HandleFirstWorksheet()
        [...]
    end prepare

    on HandleFirstWorksheet()
        if (get my nRuns) is not 1 then return
        try
            delete window "Worksheet"
            set my gWantWorksheet to false
        end try
    end HandleFirstWorksheet
  • When your dialog launches Smile, all the menus of Smile are available, while you may want only those strictly necessary to your application. For instance, you may not want that the user be allowed to set your dialog into edit mode, or make a New Unicode window inadvertently. Use the visible property of menu items and of menus. To know which menu/menu item is which, use their name property. Even invisible menus have an index, and that index is permament. For instance in Smile 2.6.5 menu 7 is always menu "Dialog" even when not shown.
    We recommend to adapt the menus only if the user is not already using Smile. You can test whether another window is open as in the example below. Note that when Smile is executing the dialog's prepare handler, the dialog is still invisible so it has no index: the window which will be just behind once the dialog open (if there is one) is still window 1.
    The example below removes the menus File, Text, Scripting, Scripts and Dialog, and removes extra items from the Edit menu.
    on prepare theDlog
        [...]
        HideUselessMenusIfAlone()
        [...]
    end prepare

    on HideUselessMenusIfAlone()
        try
            set w to window 1
            return
        end try
        repeat with i in {2, 4, 5, 6, 7}
            set visible of menu i to false
        end repeat
        repeat with i from 9 to 17
            set visible of menu item i of menu 3 to false
        end repeat
    end HideUselessMenusIfAlone
    The menus Text, Scripting and Dialog will automatically show again automatically when the concerned kind of window comes to the front. Though it is your responsibility to show again the File and Scripts menu and the missing items of the Edit menu when the user closes the dialog.
  • When the user closes the dialog, you have to reset the menus if you have altered them, and if the user is not using Smile for something else you may choose to quit Smile. In order to have some action take place when the dialog is disposed of, program it in the delete handler.
    To reset the menus, simply use the same lines as to hide them, just setting the visible property to true.
    To quit, issue the quit command.
    You may test whether another window is visible and choose not to quit if there is one. Note that when Smile is executing the dialog's delete handler, the dialog is already invisible so it has no index: the window which will become active once the dialog closed (if there is one) is already window 1. See the example below.
    on delete theDialog
        [...]
        QuitIfAlone()
        [...]
        continue delete theDialog
    end delete

    on QuitIfAlone()
        try
            set w to window 1
            return
        end try
        quit
    end QuitIfAlone
    Note that you have to forward the delete event with the continue instruction to actually have Smile dispose of the dialog.
We provide below a link to download a sample. The sample is a basic timer dialog with Start/Stop and Reset. If you open it while you are already using Smile, it will affect neither your Worksheet nor your menus, and Smile will not quit when you close it. If a new user double-clicks the dialog on the other hand, the dialog will close the Worksheet and minimize Smile's menus, and when the user closes the dialog Smile will quit.
Version française
Copyright ©2013 Paris, Satimage