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

3
4
// the monad that keeps track of the local EditState and another state (mostly the program state)

Diederik van Arkel's avatar
Diederik van Arkel committed
5
6
7
import StdArray, StdBool, StdChar, StdClass, StdFunc, StdInt, StdMisc
import StdMenuElement, StdPSt, StdWindow, StdSystem
import UtilNewlinesFile, StateMonad
8
import StdId
Diederik van Arkel's avatar
Diederik van Arkel committed
9
10
import EdVisualText, EdSelection, EdLook
import EdAction
Diederik van Arkel's avatar
Diederik van Arkel committed
11
12
13
import Platform
//import dodebug
trace_n` _ s :== s
Diederik van Arkel's avatar
Diederik van Arkel committed
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

:: ActionInfo
	= NoInfo
	| CopyInfo ![ClipboardItem] ![ClipboardItem]
	| CutInfo ![ClipboardItem] ![ClipboardItem] !TextFragment !Position !Selection !Bool
	| ClearInfo !TextFragment !Position !Selection !Bool
	| PasteInfo !TextFragment !TextFragment !Selection !Position !Bool
	| InsertInfo !Bool !IRState
	| RemoveInfo !Bool !IRState
	| ReplaceAllInfo !TextFragment !Selection !Selection ![(Selection,Selection,TextFragment,TextFragment)] !Bool
	| UndoneInfo !IRState !IRState

:: UndoInfo =
	{ state		:: !UndoState		// undo or redo
	, action	:: !String			// string describing action to be undone/redone
	, uninfo	:: !ActionInfo
	}

:: TabSize :== Int

:: NewTabSize :== [TabSize]

:: UndoState = None | Undo | Redo

:: EditState
   = { text			:: !Text
	 , pathName		:: !String
	 , windowId		:: !Id
	 , timerId		:: !Id				// P4
	 , toolPt		:: !Point2			// P4
	 , fontInfo		:: !FontInfo	 
45
	 , cursorInfo	:: !CursorInfo`
Diederik van Arkel's avatar
Diederik van Arkel committed
46
47
48
49
50
51
52
53
54
55
	 , selectInfo	:: !SelectInfo
	 , undoInfo		:: !UndoInfo
	 , needSave		:: !Bool
	 , undoeId		:: !Id
	 , lineNumbers	:: !Bool
	 , newlineConv	:: !NewlineConvention
	 , menusel		:: !Maybe String
	 , readOnly		:: !Bool
	 }

56
:: CursorInfo`	// rename to avoid conflict with Object I/O
Diederik van Arkel's avatar
Diederik van Arkel committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
   = { position		:: !Position
	 , virtualX		:: !Int
	 , visible		:: !Bool
	 }

:: SelectInfo
	= { selection	:: !Selection
	  , selectMode	:: !SelectMode
	  }
	  
:: SelectMode
	= SelectWords Selection
	| SelectLines LineNr
	| SelectChars

:: FontInfo =
	{ thefont			:: !Font
	, lineHeight		:: !Int
	, metrics			:: !FontMetrics
	, tabSize			:: !TabSize			// logical tabsize
//	, tabWidth			:: !NewTabSize		// physical tabsize
	, charWidth			:: !Int				// physical in #pixels
	, autoTab			:: !Bool
	, showTabs			:: !Bool
	, showSyntax		:: !Bool
	, syntaxColours		:: !SyntaxColours
	}

:: SyntaxColours =
	{ textColour		:: !Colour
	, backgroundColour	:: !Colour
	, tabColour			:: !Colour
	, commentColour		:: !Colour
	, stringColour		:: !Colour
	, charColour		:: !Colour
	, keywordColour		:: !Colour
Diederik van Arkel's avatar
Diederik van Arkel committed
93
	, typedefColour		:: !Colour
94
	, typedeclColour	:: !Colour
Diederik van Arkel's avatar
Diederik van Arkel committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
	}
	
instance toString ActionInfo
where
	toString NoInfo	= "N"
	toString (CopyInfo oclip nclip) = "C "
	toString (CutInfo oclip nclip frag pos sel ns) = "X "
	toString (PasteInfo ofrag frag sel pos ns)
		= "V "+++stringsToString ofrag+++":::"+++stringsToString frag+++":::"+++toSelString sel+++":::"+++toPosString pos+++"]]]"
	toString _ = "? "

toSelString {start,end}
    = "{ start = " +++ toPosString start +++ ", end = " +++ toPosString end +++ "}"

toPosString {col,row}
    = "{ col = " +++ toString col +++ ", row = " +++ toString row +++ "}"

instance == UndoState
where
	(==) None None = True
	(==) Undo Undo = True
	(==) Redo Redo = True
	(==) _ _ = False

instance toString UndoState
where
	toString None	= "None"
	toString Undo	= "Undo"
	toString Redo	= "Redo"

::IRState=
	{ txt	:: !Text
	, sel	:: !Selection
	, mod	:: !SelectMode
	, vix	:: !Int
	, vis	:: !Bool
	, ns	:: !Bool
	}

emptyUndoInfo :: UndoInfo
emptyUndoInfo = {state = None, action = "", uninfo = NoInfo}

getLineNumbers :: EditMonad .env Bool
getLineNumbers =
	getEditState		>>>= \{lineNumbers} ->
	result lineNumbers

Diederik van Arkel's avatar
Diederik van Arkel committed
142
setLineNumbers :: !Bool -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
setLineNumbers linenumbers =
	updateEditState update	>>>
	getEditState			>>>= \{windowId} ->
	computeViewDomain		>>>= \viewDomain=:{corner1=c1=:{x}} ->
	let	maybemove = if linenumbers (moveWindowViewFrame windowId {zero & vx = x}) (id)
	in
	appEnv (appPIO (maybemove o setWindowViewDomain windowId viewDomain))
where
	update editState =
		{ editState & lineNumbers = linenumbers}

:: EditMonad env a
   :== StateM *(!EditState, env) a

/* EXPORTED FUNCTIONS */

Diederik van Arkel's avatar
Diederik van Arkel committed
159
initEditState :: !Id !Id !String !Font !(Int,Bool,Bool,Bool,Bool) !SyntaxColours !*(PSt .l) -> (EditState, *PSt .l)
Diederik van Arkel's avatar
Diederik van Arkel committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
initEditState windowId eUndoId pathName font tabs=:(_,_,_,linenos,showSynCol) syncols pstate
  # (tId,pstate) = openId pstate			// P4
  # (fontInfo, pstate) = computeFontInfo font tabs syncols pstate
  = (	{ text			= newText
		, pathName		= pathName
		, windowId		= windowId
		, timerId		= tId	// P4
		, toolPt		= zero	// P4
		, fontInfo		= fontInfo
		, selectInfo	= { selection	= emptySelection
						  , selectMode	= SelectChars 
						  }
		, cursorInfo	= { position	= {col=0, row=0}
						  , virtualX	= 0
						  , visible		= True
						  }
		, undoInfo		= emptyUndoInfo
		, needSave		= False
		, undoeId		= eUndoId
		, lineNumbers	= linenos
		, newlineConv	= NewlineConventionNone
		, menusel		= Nothing
		, readOnly		= False
		}
	, pstate
	)
		     	  
getEditState :: EditMonad .env EditState
getEditState
  = getEditState`
  where
    getEditState` (editState, env)
      = (editState, (editState, env))

appEnv :: (.env -> .env) -> EditMonad .env nothing
appEnv envFun
  = appEnv`
  where
	appEnv` (editState, env)
	  # env = envFun env
	  = (nothing, (editState, env))

accEnv :: (.env -> (.a, .env)) -> EditMonad .env .a
accEnv envFun
  = accEnv`
  where
	accEnv` (editState, env)
	  # (a, env) = envFun env
	  = (a, (editState, env))

noResult :: !(EditMonad .env a) *(EditState, .env) 
				-> (EditState, .env)
noResult ma state
  # (_, state) = ma state
  = state

onlyEnv :: !(EditMonad .env a) *(EditState, .env) -> .env
onlyEnv ma state
  # (_, (_, env)) = ma state
  = env

// SELECTORS & MODIFIERS

getMenuSelection :: EditMonad .env (Maybe String)
getMenuSelection =
	getEditState	>>>= \{menusel} ->
	result menusel

Diederik van Arkel's avatar
Diederik van Arkel committed
228
setMenuSelection :: (Maybe String) -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
229
230
231
232
233
234
235
236
237
238
setMenuSelection menusel =
	updateEditState update
where
	update editState = {editState & menusel = menusel}

getNewlineConvention :: EditMonad .env NewlineConvention
getNewlineConvention =
	getEditState	>>>= \{newlineConv} ->
	result newlineConv

Diederik van Arkel's avatar
Diederik van Arkel committed
239
setNewlineConvention :: NewlineConvention -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
240
241
242
243
244
245
246
247
248
249
setNewlineConvention newlineConv =
	updateEditState update
where
	update editState = {editState & newlineConv = newlineConv}

getReadOnly :: EditMonad .env Bool
getReadOnly =
	getEditState	>>>= \{readOnly} ->
	result readOnly

Diederik van Arkel's avatar
Diederik van Arkel committed
250
setReadOnly :: Bool -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
251
252
253
254
255
256
257
258
259
260
setReadOnly readOnly =
	updateEditState update
where
	update editState = {editState & readOnly = readOnly}

getText :: EditMonad .env Text
getText
  = getEditState	>>>= \{text} ->
	result text

Diederik van Arkel's avatar
Diederik van Arkel committed
261
setText :: !Text -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
262
263
264
265
266
267
268
269
270
271
272
273
setText text =
	updateEditState update	>>>
	updateLook
where
    update editState
      = {editState & text = text}

getFontInfo :: EditMonad .env FontInfo
getFontInfo
  = getEditState	>>>= \{fontInfo} ->
	result fontInfo
	
Diederik van Arkel's avatar
Diederik van Arkel committed
274
setFontInfo	:: FontInfo -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
275
276
277
278
279
280
setFontInfo fontInfo =
	updateEditState update
where
    update editState
      = {editState & fontInfo=fontInfo}

Diederik van Arkel's avatar
Diederik van Arkel committed
281
appFontInfo :: (FontInfo -> FontInfo) -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
282
283
284
285
286
287
288
289
290
291
292
appFontInfo fontFun =
	updateEditState update	>>>
	updateLook
where
	update editState = {editState & fontInfo = fontFun editState.fontInfo}

getCursorVisibility :: EditMonad .env Bool
getCursorVisibility
  = getEditState	>>>= \{cursorInfo} ->
	result cursorInfo.visible
	
Diederik van Arkel's avatar
Diederik van Arkel committed
293
setCursorVisibility :: Bool -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
294
295
296
297
298
299
300
301
302
303
304
305
setCursorVisibility visible =
	updateEditState update	>>>
	updateLook
where
    update editState=:{cursorInfo}
      = {editState & cursorInfo={cursorInfo & visible=visible}}

getSelection :: EditMonad .env Selection
getSelection
  = getEditState	>>>= \{selectInfo={selection}} ->
	result selection
	
Diederik van Arkel's avatar
Diederik van Arkel committed
306
setSelection :: Selection -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
307
308
309
310
311
312
313
314
315
316
317
318
setSelection selection =
	updateEditState update	>>>
	updateLook
where
    update editState=:{selectInfo}
      = {editState & selectInfo={selectInfo & selection=selection}}
      
getVirtualX	:: EditMonad .env Int
getVirtualX 
  = getEditState	>>>= \{cursorInfo={virtualX}} ->
	result virtualX
	
Diederik van Arkel's avatar
Diederik van Arkel committed
319
setVirtualX :: Int -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
320
321
322
323
324
325
326
327
328
329
330
setVirtualX virtualX
  = updateEditState update
where
    update editState=:{cursorInfo}
      = {editState & cursorInfo={cursorInfo & virtualX=virtualX}}
      
getSelectMode :: EditMonad .env SelectMode
getSelectMode
  = getEditState	>>>= \{selectInfo={selectMode}} ->
	result selectMode
	
Diederik van Arkel's avatar
Diederik van Arkel committed
331
setSelectMode :: SelectMode	-> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
setSelectMode selectMode
  = updateEditState update
where
    update editState=:{selectInfo}
      = {editState & selectInfo={selectInfo & selectMode=selectMode}}

getCursorHeight :: EditMonad .env Int
getCursorHeight
  = getEditState	>>>= \{fontInfo={lineHeight}} ->
	result lineHeight

getWindowId :: EditMonad .env Id
getWindowId
  = getEditState	>>>= \{windowId} ->
	result windowId

Diederik van Arkel's avatar
Diederik van Arkel committed
348
setFont :: Font -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
setFont font = monad
where
	monad (editState,pState)
		# ({tabSize,autoTab,showTabs,showSyntax,syntaxColours},(editState,pState))
			= getFontInfo (editState,pState)
		# (linenos,(editState,pState))
			= getLineNumbers (editState,pState)
    	# tabs
    		= (tabSize,autoTab,showTabs,linenos,showSyntax)
		# (fontInfo,(editState,pState))
			= accEnv (computeFontInfo font tabs syntaxColours) (editState,pState)
		# (_,(editState,pState))
			= updateEditState (update fontInfo)	(editState,pState)
		# (_,(editState,pState))
			= updateLook (editState,pState)
		# (_,(editState,pState))
			= vResetViewDomain (editState,pState)
		= (undef,(editState,pState))
	where
	    update fontInfo editState
	      = { editState & fontInfo = fontInfo }

Diederik van Arkel's avatar
Diederik van Arkel committed
371
updateEditState :: (EditState -> EditState) -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
372
373
374
375
376
377
378
379
380
381
382
updateEditState editStateFun
  = updateEditState`
where 
	updateEditState` (editState, pstate)
	  #! editState = editStateFun editState
	  = (nothing, (editState, pstate))
	  
// updateLook updates the look function of the window. This
// look function is not applied, so no visible update is
// caused by updateLook.

Diederik van Arkel's avatar
Diederik van Arkel committed
383
updateLook :: EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
384
385
386
updateLook 
  = getWindowId		>>>= \windowId ->
	getEditState	>>>= \editState ->
Diederik van Arkel's avatar
Diederik van Arkel committed
387
	appEnv (appPIO (setWindowLook windowId False (True,editWindowLook editState)))
Diederik van Arkel's avatar
Diederik van Arkel committed
388
389
390

// compute some properties of a font

Diederik van Arkel's avatar
Diederik van Arkel committed
391
computeFontInfo :: !Font !(Int,Bool,Bool,Bool,Bool) !SyntaxColours !(PSt .l) -> (FontInfo, PSt .l)
Diederik van Arkel's avatar
Diederik van Arkel committed
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
computeFontInfo font (tabSize,autoTab,showTabs,_,showSynCol) syncols pstate
  # (metrics, pstate)	= accPIO (accScreenPicture (getFontMetrics font)) pstate
	lineHeight			= metrics.fAscent + metrics.fDescent + metrics.fLeading
	(charWidth,pstate) = accPIO (accScreenPicture (getFontStringWidth font "M")) pstate
  = ( { thefont				= font
	  , lineHeight			= lineHeight
	  , metrics				= metrics
	  , tabSize				= tabSize
	  , autoTab				= autoTab
	  , charWidth			= charWidth
	  , showTabs			= showTabs
	  , showSyntax			= showSynCol
	  , syntaxColours		= syncols
	  }
	, pstate
	) 

409
DefaultSyntaxColours :: SyntaxColours
Diederik van Arkel's avatar
Diederik van Arkel committed
410
411
412
413
414
415
416
417
DefaultSyntaxColours =
	{ textColour		= Black
	, tabColour			= Red
	, backgroundColour	= White
	, commentColour		= Blue
	, stringColour		= Green
	, charColour		= Magenta
	, keywordColour		= Grey
Diederik van Arkel's avatar
Diederik van Arkel committed
418
	, typedefColour		= Black
419
	, typedeclColour	= Black
Diederik van Arkel's avatar
Diederik van Arkel committed
420
421
422
423
424
425
426
427
428
	}

//--

getPathName :: EditMonad .env String
getPathName =
	getEditState		>>>= \{pathName} ->
	result pathName

Diederik van Arkel's avatar
Diederik van Arkel committed
429
setPathName :: String -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
setPathName path =
	updateEditState update
where
	update editState	= {editState & pathName = path}

getNeedSave :: EditMonad .env Bool
getNeedSave =
	getEditState		>>>= \{needSave} ->
	result needSave

pathNameToWindowTitle :: !String -> String
pathNameToWindowTitle pathName
	= RemovePath pathName+++" - "+++pathName
where
	RemovePath	:: !String -> String;
	RemovePath path
		| found	= path % (inc position, last);
				= path;
		where 
			(found,position)= FindLastChar dirseparator path last;
			last			= dec (size path);
	
	FindLastChar :: !Char !String !Int -> (!Bool, !Int);
	FindLastChar c s i
		| i <= 0			= (False,0);
		| c ==  s.[i]		= (True, i);
							= FindLastChar c s (dec i);

pathNameToWindowTitle` :: !String -> String
pathNameToWindowTitle` pathName
	= "["+++RemovePath pathName+++"] - "+++pathName
where
	RemovePath	:: !String -> String;
	RemovePath path
		| found	= path % (inc position, last);
				= path;
		where 
			(found,position)= FindLastChar dirseparator path last;
			last			= dec (size path);
	
	FindLastChar :: !Char !String !Int -> (!Bool, !Int);
	FindLastChar c s i
		| i <= 0			= (False,0);
		| c ==  s.[i]		= (True, i);
							= FindLastChar c s (dec i);

Diederik van Arkel's avatar
Diederik van Arkel committed
476
setNeedSave :: Bool -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
477
478
479
480
481
setNeedSave need =
	getReadOnly												>>>= \readOnly ->
	getEditState											>>>= \{windowId,pathName} ->
	accEnv (accPIO (getWindowTitle windowId))				>>>= \oldTitle ->
	let
Diederik van Arkel's avatar
Diederik van Arkel committed
482
483
484
485
		windowName	= (if readOnly pathNameToWindowTitle` pathNameToWindowTitle) pathName
		windowTitle	= PlatformDependant
						/*Win*/	(if need ("*"+++windowName) windowName)
						/*Mac*/ windowName
Diederik van Arkel's avatar
Diederik van Arkel committed
486
	in
Diederik van Arkel's avatar
Diederik van Arkel committed
487

Diederik van Arkel's avatar
Diederik van Arkel committed
488
489
490
	IF (needsetwin oldTitle windowTitle)
	THEN
	(
Diederik van Arkel's avatar
Diederik van Arkel committed
491
492
493
494
495
496
497
498
499
500
501
502
503
		appEnv (appPIO (setWindowTitle windowId windowTitle))
	)
	ELSE
	(
		skip
	)	>>>

	accEnv (accPIO (getWindowModified windowId))			>>>= \wasModified ->
	IF (isJust wasModified && fromJust wasModified <> need)

	THEN
	(
	appEnv (appPIO (setWindowModified windowId windowName need))		>>>
Diederik van Arkel's avatar
Diederik van Arkel committed
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
	updateEditState update
	)
	ELSE
	(
	updateEditState update
	)														>>>
	IF needfixundo
	THEN
		(
		updateEditState undoupdate
		)
	ELSE
		skip
where
	update editState	= {editState & needSave = need}
	needsetwin Nothing _ = True
	needsetwin (Just oldtitle) newtitle = oldtitle <> newtitle
	needfixundo = not need
	undoupdate editState=:{undoInfo} = {editState & undoInfo = fix undoInfo}
	fix ui=:{uninfo,state}
		# info = case uninfo of		// fix to correct undo'd need save state after save
			(NoInfo)				-> NoInfo
			(CopyInfo x y)			-> CopyInfo x y
			(CutInfo a b c d e ns)	-> CutInfo a b c d e True
			(ClearInfo a b c ns)	-> ClearInfo a b c True
			(PasteInfo a b c d ns)	-> PasteInfo a b c d True
			(InsertInfo a ir)		-> InsertInfo a {ir & ns = True}
			(RemoveInfo a ir)		-> RemoveInfo a {ir & ns = True}
			(ReplaceAllInfo nfrag osel nsel ul ns) -> (ReplaceAllInfo nfrag osel nsel ul True)
			(UndoneInfo or nr)		-> UndoneInfo {or & ns = (state==Undo)} {nr & ns = (state==Redo)}
		= {ui & uninfo = info}

getUndoInfo :: EditMonad .env UndoInfo
getUndoInfo
	=	getEditState		>>>= \{undoInfo} ->
		result undoInfo

Diederik van Arkel's avatar
Diederik van Arkel committed
541
setUndoInfo :: UndoInfo -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
542
setUndoInfo undoInfo
543
	=	getEditState				>>>= \{undoeId} ->
Diederik van Arkel's avatar
Diederik van Arkel committed
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
		appEnv (appPIO (mfun undoeId))	>>>
		updateEditState update
where
    update editState
      = {editState & undoInfo = undoInfo}
	mfun r		= case undoInfo.state of
					None	-> disableMenuElements [r] o setMenuElementTitles [(r,"Undo")]
					Undo	-> enableMenuElements [r] o setMenuElementTitles [(r,"Undo"+++undoInfo.action)]
					Redo	-> enableMenuElements [r] o setMenuElementTitles [(r,"Redo"+++undoInfo.action)]

//-- P4

getTimerId :: EditMonad .env Id
getTimerId
  = getEditState	>>>= \{timerId} ->
	result timerId

getToolPt :: EditMonad .env Point2
getToolPt
  = getEditState	>>>= \{toolPt} ->
	result toolPt

Diederik van Arkel's avatar
Diederik van Arkel committed
566
setToolPt :: Point2 -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
567
568
569
570
571
572
573
setToolPt toolPt =
	updateEditState update
where
	update editState	= {editState & toolPt = toolPt}

//--

Diederik van Arkel's avatar
Diederik van Arkel committed
574
getState :: EditMonad (PSt .l) IRState
Diederik van Arkel's avatar
Diederik van Arkel committed
575
576
577
578
getState =
	getEditState	>>>= \{text,selectInfo={selection,selectMode},cursorInfo={virtualX,visible},needSave} ->
	result {txt=text,sel=selection,mod=selectMode,vix=virtualX,vis=visible,ns=needSave}

Diederik van Arkel's avatar
Diederik van Arkel committed
579
setState :: IRState -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
setState state =
	updateEditState update		>>>
	updateLook					>>>
	setNeedSave     state.ns
where
	update editState=:{selectInfo,cursorInfo}
	  =	{ editState
		& text			= text
		, selectInfo	= {selectInfo & selection=selection, selectMode=selectMode}
		, cursorInfo	= {cursorInfo & virtualX = virtualX, visible = visible}
		}
	text		= state.txt
	selection	= state.sel
	selectMode	= state.mod
	virtualX	= state.vix
	visible		= state.vis
Diederik van Arkel's avatar
Diederik van Arkel committed
596