Mercurial > gui
comparison waitbox.ur @ 0:37eefd0a2ed4
Import code from elsewhere
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Tue, 14 Dec 2010 10:55:22 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:37eefd0a2ed4 |
---|---|
1 type t = {Milliseconds : int, | |
2 Action : source (string -> transaction {}), | |
3 Timer : source (option Timer.t), | |
4 Text : source string} | |
5 | |
6 fun create n = | |
7 s <- source ""; | |
8 tmO <- source None; | |
9 f <- source (fn _ => return ()); | |
10 | |
11 return {Milliseconds = n, Action = f, Timer = tmO, Text = s} | |
12 | |
13 fun setAction r v = set r.Action v | |
14 | |
15 fun tickle r = | |
16 last <- get r.Timer; | |
17 (case last of | |
18 None => return () | |
19 | Some tm => Timer.cancel tm); | |
20 tm <- Timer.create {Milliseconds = r.Milliseconds, | |
21 Action = (set r.Timer None; | |
22 s <- get r.Text; | |
23 f <- get r.Action; | |
24 f s)}; | |
25 set r.Timer (Some tm) | |
26 | |
27 fun render r = <xml> | |
28 <ctextbox source={r.Text} | |
29 onkeyup={fn _ => tickle r}/> | |
30 </xml> | |
31 | |
32 fun clear r = (set r.Text ""; | |
33 tm <- get r.Timer; | |
34 (case tm of | |
35 None => return () | |
36 | Some tm => Timer.cancel tm); | |
37 set r.Timer None) | |
38 | |
39 fun trigger r = | |
40 last <- get r.Timer; | |
41 (case last of | |
42 None => return () | |
43 | Some tm => Timer.cancel tm); | |
44 set r.Timer None; | |
45 s <- get r.Text; | |
46 f <- get r.Action; | |
47 f s |