messwin.icl 2.33 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
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
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
79
80
implementation module messwin

import StdString, StdPSt, StdList, StdWindow, StdMisc, StdBool
import IdeState
import errwin

//--- message dialog

:: Info
	= Level1 String
	| Level2 String
	| Level3 [String]

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

showInfo :: !.Info !*(PSt General) -> !*PSt General
showInfo info ps
	#!	((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
//			(size,ps)		= controlSize content False Nothing Nothing Nothing ps
		#!	(err,ps)		= openDialog Void			// modal?
									(Dialog "Messages" content
									[ WindowId dlogId
									, WindowPos (Fix,OffsetVector {vx = 200, vy = 200})
/*									, WindowPos (Fix,OffsetFun 1
										(\(dm,ps)->
											{vx = (size.w + dm.corner2.x - dm.corner1.x) >> 1
											,vy = (size.Size.h + dm.corner2.y - dm.corner1.y) >> 1
											}
										))
*/
									, 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
					]

closeInfo :: !*(PSt General) -> !*PSt General
closeInfo ps
	#	((pr_info,_),ps)	= getInterrupt ps
		ps					= closeWindow pr_info ps
	= ps