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

3
4
// opening and closing editor windows

Diederik van Arkel's avatar
Diederik van Arkel committed
5
6
7
8
9
10
11
import StdInt, StdClass, StdList
import StdWindow, StdControlReceiver, StdIOBasic
import EdMessage, EdMonad, EdLook, EdVisualText, EdState
import ioutil

//---

12
openEditWindow :: Id .Title String Text !Font (Int,Bool,Bool,Bool,Bool) SyntaxColours Id [.WindowAttribute *(EditState,*PSt *b)] !*(PSt *b) -> *PSt *b | Editor b
Diederik van Arkel's avatar
Diederik van Arkel committed
13
14
15
16
17
18
19
20
21
22
23
24
openEditWindow uId title pathName text font tabs syncols windowId atts ps
  # (editorState,ps)				= getEditorState ps
  // generate a receiver identifier and store it in the editor state
  # (editId, ps)					= openEditId ps
	editorState						= addReceiver windowId editId editorState
  // create the local state of the editor window
  # (editState, ps)					= initEditState windowId uId pathName font tabs syncols ps
	(_, (editState, ps))			= setText text (editState, ps)
	(fontInfo, (editState, ps))		= getFontInfo (editState, ps) 
  // compute the view domain of the visual text
	(viewDomain, (editState, ps))	= computeViewDomain (editState, ps)
  // setup the window attributes 
Diederik van Arkel's avatar
Diederik van Arkel committed
25
	editLook						= editWindowLook editState
Diederik van Arkel's avatar
Diederik van Arkel committed
26
27
28
29
30
31
	windowAttrs						= atts ++		// in this order so that new attributes override default atts
										  	[ WindowViewSize   { w = 800, h = fontInfo.FontInfo.lineHeight * 40 }
											, WindowHMargin	   0 0
											, WindowVMargin	   0 0
											, WindowId		   windowId
											, WindowViewDomain viewDomain
32
											, WindowLook	   True editLook
33
34
											, WindowHScroll	   (altScrollFunction Horizontal fontInfo.metrics.fMaxWidth)
											, WindowVScroll	   (alignScrollFunction Vertical fontInfo.FontInfo.lineHeight)
Diederik van Arkel's avatar
Diederik van Arkel committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
											, WindowPos		   (Fix, OffsetVector {vx=10, vy=10})
											, WindowCursor	   IBeamCursor
											]
	// create the receiver that will be part of the
	// editor window. The receiver can be used to change features
	// of the editor from the outside (features like font, text)
  # receiver	 					= openEditReceiver editId
	// create and open the window
  # window		 					= Window title receiver windowAttrs
  # (_,ps)	 						= openWindow editState window ps
  # ps		 						= setEditorState editorState ps
  = ps
  
closeEditWindow :: !Id !*(PSt *b) -> *PSt *b | Editor b;
closeEditWindow windowId pState
50
51
52
53
54
55
  # (editorState,pState) 		= getEditorState pState
  # (maybeEditId, editorState)	= findReceiver windowId editorState
  | isNothing maybeEditId
  	= setEditorState editorState pState
  #	editorState					= removeReceiver windowId editorState
	pState						= closeWindow windowId pState
Diederik van Arkel's avatar
Diederik van Arkel committed
56
  = setEditorState editorState pState