aboutsummaryrefslogtreecommitdiff
path: root/tut11_3_2.icl
blob: a959b60735386e7103a0eacdf8f27dfa6650e9cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module tut11_3_2

// ********************************************************************************
// Clean tutorial example program.
//
// This program creates a simple program that uses the stopwatch process.
// The program only has a menu to open the stopwatch and control it.
// ********************************************************************************

import StdEnv, StdIO
import tut11_3_2_stopwatch

Start :: *World -> *World
Start world
# (stopwatchId, world)  = openRId world
= startIO SDI Void (initialise stopwatchId) [] world

initialise :: (RId StopwatchCommands) (PSt .l) -> PSt .l
initialise stopwatchId pst
# (error, pst)      = openMenu Void mdef pst
| error <> NoError  = closeProcess pst
| otherwise         = openProcesses (stopwatch stopwatchId) pst
where
    mdef = Menu "&Stopwatch" (MenuItem "&Reset"     [MenuFunction (noLS (send Reset))] :+:
                              MenuItem "&Pause"     [MenuFunction (noLS (send Pause))] :+:
                              MenuItem "C&ontinue"  [MenuFunction (noLS (send Continue))] :+:
                              MenuItem "&Close"     [MenuFunction (noLS (send Close))] :+:
                              MenuSeparator         [] :+:
                              MenuItem "&Quit"      [MenuFunction (noLS (closeProcess o (send Close)))]) []
    where
        send msg pst
        # (error, pst)      = syncSend stopwatchId msg pst
        | error <> SendOk   = appPIO beep pst
        | otherwise         = pst