blob: 3b591a3293576a905f6573d1ea76c5db14f2315a (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
module tut12_1
// ********************************************************************************
// Clean tutorial example program.
//
// This program creates a dialogue to display and change the current content
// of the clipboard.
// ********************************************************************************
import StdEnv, StdIO
Start :: *World -> *World
Start world
# (showId, world) = openId world
# (setId, world) = openId world
= startProcesses (Process NDI Void (initialise showId setId) []) world
initialise showId setId pst
# (error, pst) = openDialog Void clipView pst
| error <> NoError = closeProcess pst
| otherwise = pst
where
clipView = Dialog "Clipboard Editor" (showClip :+: setClip :+: quit) []
showClip = EditControl "" width nrlines [ControlId showId, ControlPos (Left, zero), ControlSelectState Unable] :+:
ButtonControl "Show" [ControlFunction (noLS show)]
setClip = EditControl "" width nrlines [ControlId setId, ControlPos (Left, zero)] :+:
ButtonControl "Set" [ControlFunction (noLS set)]
quit = ButtonControl "Quit" [ControlFunction (noLS closeProcess), ControlPos (Center, zero)]
width = PixelWidth (hmm 50.0)
nrlines = 4
show pst
# (cont, pst) = getClipboard pst
# text = getString cont
= appPIO (setControlText showId text) pst
set pst
# (wst, pst) = accPIO (getParentWindow showId) pst
# text = fromJust (snd (getControlText setId (fromJust wst)))
= setClipboard [toClipboard text] pst
getString :: [ClipboardItem] -> String
getString [] = ""
getString [clip:clips]
# item = fromClipboard clip
| isNothing item = getString clips
| otherwise = fromJust item
|