diff options
author | Camil Staps | 2015-08-21 21:42:06 +0200 |
---|---|---|
committer | Camil Staps | 2015-08-21 21:42:06 +0200 |
commit | 4937b1cedc6ff9723e9fecb2197a601c5b66fb03 (patch) | |
tree | 5f699ca152372a7268bcb3f893d8eade39cf8e5d | |
parent | Tut 11.3.1 Talk revisited (diff) |
Tut 12.1 Simple clipboard editor
-rw-r--r-- | tut12_1.icl | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tut12_1.icl b/tut12_1.icl new file mode 100644 index 0000000..3b591a3 --- /dev/null +++ b/tut12_1.icl @@ -0,0 +1,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 + |