aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tut12_1.icl50
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
+