EdMonad.dcl 4.88 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1
2
definition module EdMonad

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

5
6
7
8
9
10
11
from StdPicture		import :: Font, :: FontMetrics, :: Colour
from StdPSt			import :: PSt, :: IOSt
from StdId			import :: Id
from StdPicture		import :: Picture
from StdClipboard	import :: ClipboardItem
from StdOverloaded	import class ==, class toString
from StdMaybe		import :: Maybe
Diederik van Arkel's avatar
Diederik van Arkel committed
12
13

import StateMonad 
14
from UtilNewlinesFile import :: NewlineConvention
Diederik van Arkel's avatar
Diederik van Arkel committed
15

16
17
from EdText			import :: Text, :: StrictList, :: TextFragment
from EdSelection	import :: Selection, :: Position, :: ColumnNr, :: LineNr
Diederik van Arkel's avatar
Diederik van Arkel committed
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

:: TabSize :== Int

:: NewTabSize :== [TabSize]

:: EditState

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

:: FontInfo =
	{ thefont		:: !Font
	, lineHeight	:: !Int
	, metrics		:: !FontMetrics
	, tabSize		:: !TabSize			// logical in #chars
//	, tabWidth		:: !NewTabSize		// physical in #pixels
	, 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
	}

58
DefaultSyntaxColours :: SyntaxColours
Diederik van Arkel's avatar
Diederik van Arkel committed
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

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

:: UndoState = None | Undo | Redo

instance == UndoState

:: IRState

:: 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			// TextFragment should be enoughthere instead of entire edit state...
	| RemoveInfo !Bool !IRState			// TextFragment should be enough here instead of entire edit state...
	| ReplaceAllInfo !TextFragment !Selection !Selection ![(Selection,Selection,TextFragment,TextFragment)] !Bool	// newfrag oldsel newsel updatelist needsave
	| UndoneInfo !IRState !IRState		// TextFragment should be enough here instead of entire edit state...

instance toString ActionInfo
instance toString UndoState

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

Diederik van Arkel's avatar
Diederik van Arkel committed
88
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
89
90
91
92
93
94
95
96
appEnv			:: (.env -> .env)									->	EditMonad .env	nothing
accEnv			:: (.env -> (.a, .env))								->	EditMonad .env	.a
noResult		:: !(EditMonad .env a) *(EditState, .env)			->	(EditState, .env)
onlyEnv			:: !(EditMonad .env a) *(EditState, .env)			-> .env

// ACCESSORS & MODIFIERS

getMenuSelection		::										EditMonad .env (Maybe String)
Diederik van Arkel's avatar
Diederik van Arkel committed
97
setMenuSelection		:: (Maybe String)					->	EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
98
getUndoInfo				::										EditMonad .env			UndoInfo
Diederik van Arkel's avatar
Diederik van Arkel committed
99
setUndoInfo				:: UndoInfo							->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
100
getLineNumbers			::										EditMonad .env			Bool
Diederik van Arkel's avatar
Diederik van Arkel committed
101
setLineNumbers			:: !Bool							->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
102
getNewlineConvention	::										EditMonad .env			NewlineConvention
Diederik van Arkel's avatar
Diederik van Arkel committed
103
setNewlineConvention	:: NewlineConvention				->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
104
getReadOnly				::										EditMonad .env Bool
Diederik van Arkel's avatar
Diederik van Arkel committed
105
setReadOnly				:: Bool								->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
106
getText					::										EditMonad .env			Text
Diederik van Arkel's avatar
Diederik van Arkel committed
107
setText					:: !Text							->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
108
getVirtualX				::										EditMonad .env			Int
Diederik van Arkel's avatar
Diederik van Arkel committed
109
setVirtualX				:: Int								->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
110
getFontInfo				::										EditMonad .env			FontInfo
Diederik van Arkel's avatar
Diederik van Arkel committed
111
112
setFontInfo				:: FontInfo							->	EditMonad (PSt .l)	nothing
appFontInfo				:: (FontInfo -> FontInfo)			->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
113
114
getWindowId				::										EditMonad .env			Id
getCursorVisibility		::										EditMonad .env			Bool
Diederik van Arkel's avatar
Diederik van Arkel committed
115
setCursorVisibility		:: Bool								->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
116
getSelection			::										EditMonad .env			Selection
Diederik van Arkel's avatar
Diederik van Arkel committed
117
setSelection			:: Selection						->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
118
getSelectMode			:: 										EditMonad .env			SelectMode
Diederik van Arkel's avatar
Diederik van Arkel committed
119
setSelectMode			:: SelectMode						->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
120
getPathName				::										EditMonad .env			String
Diederik van Arkel's avatar
Diederik van Arkel committed
121
setPathName				:: String							->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
122
getNeedSave				::										EditMonad .env			Bool
Diederik van Arkel's avatar
Diederik van Arkel committed
123
setNeedSave				:: Bool								->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
124
getCursorHeight			::										EditMonad .env			Int
Diederik van Arkel's avatar
Diederik van Arkel committed
125
setFont					:: Font								->	EditMonad (PSt .l)	nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
126
127
128
129
130

pathNameToWindowTitle :: !String -> String
pathNameToWindowTitle` :: !String -> String

//-- P4
131
from StdIOBasic import :: Point2
Diederik van Arkel's avatar
Diederik van Arkel committed
132
133
134

getTimerId :: EditMonad .env Id
getToolPt :: EditMonad .env Point2
Diederik van Arkel's avatar
Diederik van Arkel committed
135
setToolPt :: Point2 -> EditMonad (PSt .l) nothing
Diederik van Arkel's avatar
Diederik van Arkel committed
136
137
138

//--

Diederik van Arkel's avatar
Diederik van Arkel committed
139
140
getState :: EditMonad (PSt .l) IRState
setState :: IRState -> EditMonad (PSt .l) nothing