messwin.icl 2.36 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1 2
implementation module messwin

3
import StdString, StdPSt, StdList, StdWindow, StdMisc, StdBool, StdFunc
Diederik van Arkel's avatar
Diederik van Arkel committed
4 5 6 7 8
import IdeState
import errwin

//--- message dialog

Diederik van Arkel's avatar
Diederik van Arkel committed
9
:: InfoMessage
Diederik van Arkel's avatar
Diederik van Arkel committed
10 11 12 13 14 15 16 17
	= Level1 String
	| Level2 String
	| Level3 [String]

checkDialogExistence id io
	# (st,io)	= getDialogsStack io
	= (isMember id st,io)

Diederik van Arkel's avatar
Diederik van Arkel committed
18
showInfo :: !.InfoMessage !*(PSt General) -> *PSt General
Diederik van Arkel's avatar
Diederik van Arkel committed
19
showInfo info ps
20 21 22 23 24 25 26 27 28
	# (interact, ps) = getInteract ps
	| not interact
		= case info of
			(Level1 s)	-> writeLog s ps
			(Level2 s)	-> writeLog s ps
			(Level3 s)	-> seq (map writeLog s) ps
	// interact
		=	showInfoInteractive info ps

Diederik van Arkel's avatar
Diederik van Arkel committed
29
showInfoInteractive :: !.InfoMessage !*(PSt General) -> *PSt General
30
showInfoInteractive info ps
Diederik van Arkel's avatar
Diederik van Arkel committed
31 32 33 34 35 36 37 38
	#!	((dlogId,_),ps)		= getInterrupt ps
	#!	((text1Id,text2Id,_),ps)
							= getInterText ps
	# (exist,ps)			= accPIO (checkDialogExistence dlogId) ps
	| not exist && not (level3 info)
		# (buttonId,ps)		= openId ps
		#!	ok				= ButtonControl "Cancel" [ControlId buttonId, ControlPos (Right,zero), ControlFunction (noLS (closeWindow dlogId))]
			content			= (texts text1Id text2Id) :+: ok
39
		#!	(err,ps)		= openDialog Void
Diederik van Arkel's avatar
Diederik van Arkel committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
									(Dialog "Messages" content
									[ WindowId dlogId
									, WindowPos (Fix,OffsetVector {vx = 200, vy = 200})
									, WindowClose (noLS (closeWindow dlogId))
									, WindowOk buttonId
									, WindowCancel buttonId
									])
									ps
		| err == NoError
			= ps
		= ps
	#! ps = case info of
					Level1 txt	-> appPIO (setControlTexts [(text1Id,txt),(text2Id,"")]) ps
								// Can improve this by remembering if text2 == ""
					Level2 txt	-> appPIO (setControlTexts [(text2Id,txt)]) ps
					Level3 l	-> l3fun l ps
	= ps
where
	level3 (Level3 _) = True
	level3 _ = False
	
	l3fun l ps
		= updateErrorWindow l ps		// use error window for level3 messages...
	texts text1Id text2Id
		# (txt1,txt2,info) = case info of
						Level1 s -> (s,"",[])
						Level2 s -> ("",s,[])
						Level3 l -> ("","",l)
		= LayoutControl
					( ListLS
						[ TextControl txt1 [ControlWidth (PixelWidth 250),ControlPos (Left,zero),ControlId text1Id]
						, TextControl txt2 [ControlWidth (PixelWidth 250),ControlPos (Left,zero),ControlId text2Id]:
						[]]
					)
					[ ControlHMargin 0 0
					, ControlVMargin 0 0
					, ControlItemSpace 3 3
					]

79
closeInfo :: !*(PSt General) -> *PSt General
Diederik van Arkel's avatar
Diederik van Arkel committed
80 81 82 83
closeInfo ps
	#	((pr_info,_),ps)	= getInterrupt ps
		ps					= closeWindow pr_info ps
	= ps