PmPrefs.icl 20.1 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
implementation module PmPrefs

import StdArray, StdFunc, StdInt
import StdSystem, StdFile, StdMisc
import UtilStrictLists, PmPath
import EdMonad
import PmCompilerOptions
import PmFiles
import colourclip
import UtilOptions
import UtilNewlinesFile

PrefsFileName :== "IDEPrefs"

:: ErrPrefs =
	{ err_pos		:: !Vector2
	, err_siz		:: !Size
	, err_fname		:: !String
	, err_fsize		:: !Int
	, err_forc		:: !Colour
	, err_bacc		:: !Colour
	, err_err		:: !Bool
	, err_wrn		:: !Bool
	, err_inf		:: !Bool
	}

:: SrcPrefs =
	{ src_pos		:: !Vector2
	, src_siz		:: !Size
	, src_fname		:: !String
	, src_fsize		:: !Int
	, src_forc		:: !Colour
	, src_bacc		:: !Colour
	}	

:: TypPrefs =
	{ typewinfont	:: !FontDef
	, typewinpos	:: !Vector2
	, typewinsiz	:: !Size
	, typewinsync	:: !SyntaxColours
	}

:: ConPrefs =
	{ conswinfont	:: !FontDef
	, conswinpos	:: !Vector2
	, conswinsiz	:: !Size
	, conswinsync	:: !SyntaxColours
	}

:: PrjPrefs =
	{ proj_pos		:: !Vector2
	, proj_siz		:: !Size
	, proj_topc		:: !Colour
	, proj_forc		:: !Colour
	, proj_bacc		:: !Colour
	, proj_font		:: !FontDef
	, proj_shft		:: !Bool		// True: open dcl default; False: open icl default;
	}

:: Prefs =
	{ pmp_pth		:: !List Pathname
	, pmp_lnk		:: !List Pathname
	, pmp_obj		:: !List Pathname
	, typ_prefs		:: !TypPrefs
	, con_prefs		:: !ConPrefs
	, err_prefs		:: !ErrPrefs
	, src_prefs		:: !SrcPrefs
	, prj_prefs		:: !PrjPrefs

	, edwinfont		:: !FontDef
71
	// FIXME use a record for these options
Diederik van Arkel's avatar
Diederik van Arkel committed
72
	, edwintabs		:: !(Int,Bool,Bool,Bool,Bool)	// tabsize, autotab, showtabs, showlinenos, showsyncol
73 74
	, edwinmargin	:: !Int							// right margin (in #characters), 0: no margin

Diederik van Arkel's avatar
Diederik van Arkel committed
75 76 77 78 79 80 81 82 83 84 85 86
	, compopts		:: !CompilerOptions
	, cgenopts		:: !CodeGenOptions
	, linkopts		:: !LinkOptions
	, applopts		:: !ApplicationOptions
//	, pmanopts		:: !ProjectOptions
	, syncols		:: !SyntaxColours				// default syntax colours
	, defcols		:: !SyntaxColours				// .dcl syntax colours
	, impcols		:: !SyntaxColours				// .icl syntax colours
	, proj_hist		:: !List Pathname				// project history
	, file_hist		:: !List Pathname				// file history
	, switch_close	:: !Bool						// close associated editor windows on project switch
	, show_toolbar	:: !Bool						// enable toolbar
Diederik van Arkel's avatar
Diederik van Arkel committed
87
//	, enable_prover	:: !Bool						// enable theorem prover
Diederik van Arkel's avatar
Diederik van Arkel committed
88 89 90
	, be_verbose	:: !Bool						// give extended diagnostics
	, altgr_workaround :: !Bool						// temp fix to workaround french azerty keyboard menu shortcuts...
	, newline_handling	:: !NewlinePrefs
91 92 93 94 95
	
	, reg_prefs		:: !RegPrefs
	}

:: RegPrefs =
96
	{ rp_flags		:: ![(String,String)]
97 98 99 100 101 102 103 104
	, tp_name		:: !String
	, tp_path		:: !String
	, hp_name		:: !String
	, hp_path		:: !String
	, pr_name		:: !String
	, pr_path		:: !String
	, ve_name		:: !String
	, ve_path		:: !String
Diederik van Arkel's avatar
Diederik van Arkel committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
	}

:: NewlinePrefs
	= LeaveAlone NewlineConvention	// leave alone existing files, use given convention for new files
	| AlwaysUse NewlineConvention	// always save with given newline convention

emptyPrefs =
	{ pmp_pth		= Nil
	, pmp_lnk		= Nil
	, pmp_obj		= Nil
	, typ_prefs		= emptyTypPrefs
	, con_prefs		= emptyConPrefs
	, err_prefs		= emptyErrPrefs
	, src_prefs		= emptySrcPrefs
	, prj_prefs		= emptyPrjPrefs
	, edwinfont		= NonProportionalFontDef
	, edwintabs		= (4,True,False,False,True)
122
	, edwinmargin	= 0
Diederik van Arkel's avatar
Diederik van Arkel committed
123 124 125 126 127 128 129 130 131 132 133
	, compopts		= DefaultCompilerOptions
	, cgenopts		= DefCodeGenOptions
	, linkopts		= DefaultLinkOptions
	, applopts		= DefApplicationOptions
	, syncols		= scSyntaxColours
	, defcols		= dmSyntaxColours
	, impcols		= imSyntaxColours
	, proj_hist		= Nil
	, file_hist		= Nil
	, switch_close	= False
	, show_toolbar	= True
Diederik van Arkel's avatar
Diederik van Arkel committed
134
//	, enable_prover	= False
Diederik van Arkel's avatar
Diederik van Arkel committed
135 136 137
	, be_verbose	= False
	, altgr_workaround = False
	, newline_handling = LeaveAlone NewlineConventionNone
138
	, reg_prefs		= emptyRegPrefs
Diederik van Arkel's avatar
Diederik van Arkel committed
139 140
	}

141 142 143
emptyRegPrefs =
	{ rp_flags		= []
	, tp_name		= "ShowTimeProfile.exe"
144
	, tp_path		= "{Application}\\Tools\\Time Profiler 2.0\\"
145
	, hp_name		= "ShowHeapProfile.exe"
146
	, hp_path		= "{Application}\\Tools\\Heap Profiler 2.0\\"
147
	, pr_name		= "Sparkle.exe"
Diederik van Arkel's avatar
Diederik van Arkel committed
148
	, pr_path		= "{Application}\\Tools\\Sparkle 0.0.3a\\"
149 150
	, ve_name		= "VisualEditor.exe"
	, ve_path		= "{Application}\\Tools\\Visual Editor\\"
151 152
	}
	
Diederik van Arkel's avatar
Diederik van Arkel committed
153 154 155 156 157 158 159 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
emptyTypPrefs =
	{ typewinfont	= NonProportionalFontDef
	, typewinpos	= {vx=30,vy=30}
	, typewinsiz	= {w=800,h=300}
	, typewinsync	= twSyntaxColours
	}
emptyConPrefs =
	{ conswinfont	= NonProportionalFontDef
	, conswinpos	= {vx=30,vy=30}
	, conswinsiz	= {w=800,h=300}
	, conswinsync	= cwSyntaxColours
	}
emptyErrPrefs =
	{ err_pos		= {vx=300,vy=300}
	, err_siz		= {w=500,h=300}
	, err_fname		= SansSerifFontDef.fName
	, err_fsize		= SansSerifFontDef.fSize
	, err_forc		= Black
	, err_bacc		= ewBack
	, err_err		= True
	, err_wrn		= True
	, err_inf		= True
	}

emptySrcPrefs =
	{ src_pos		= {vx=250,vy=250}
	, src_siz		= {w=300,h=200}
	, src_fname		= SansSerifFontDef.fName
	, src_fsize		= SansSerifFontDef.fSize
	, src_forc		= Black
	, src_bacc		= swBack
	}

emptyPrjPrefs =
	{ proj_pos		= {vx = 0, vy = 0}
	, proj_siz		= {w=200,h=400}
	, proj_topc		= pwTopc
	, proj_forc		= pwFore
	, proj_bacc		= pwBack
	, proj_font		= SansSerifFontDef
	, proj_shft		= True
	}

//--

198
twSyntaxColours :: SyntaxColours
Diederik van Arkel's avatar
Diederik van Arkel committed
199 200 201 202
twSyntaxColours =
	{ textColour		= Black
	, tabColour			= twTabs
	, backgroundColour	= twBack
203
	, marginColour		= darkerColour twBack
Diederik van Arkel's avatar
Diederik van Arkel committed
204 205 206 207
	, commentColour		= twComm
	, stringColour		= twStri
	, charColour		= Magenta
	, keywordColour		= twChar
Diederik van Arkel's avatar
Diederik van Arkel committed
208
	, typedefColour		= Black
209
	, typedeclColour	= Black
Diederik van Arkel's avatar
Diederik van Arkel committed
210 211
	}

212
cwSyntaxColours :: SyntaxColours
Diederik van Arkel's avatar
Diederik van Arkel committed
213 214 215 216
cwSyntaxColours =
	{ textColour		= Black
	, tabColour			= twTabs
	, backgroundColour	= cwBack
217
	, marginColour		= darkerColour cwBack
Diederik van Arkel's avatar
Diederik van Arkel committed
218 219 220 221
	, commentColour		= cwComm
	, stringColour		= cwStri
	, charColour		= Magenta
	, keywordColour		= twChar
Diederik van Arkel's avatar
Diederik van Arkel committed
222
	, typedefColour		= Black
223
	, typedeclColour	= Black
Diederik van Arkel's avatar
Diederik van Arkel committed
224 225
	}

226
ewSyntaxColours :: SyntaxColours
Diederik van Arkel's avatar
Diederik van Arkel committed
227 228 229 230
ewSyntaxColours =
	{ textColour		= Black
	, tabColour			= twTabs
	, backgroundColour	= twBack
231
	, marginColour		= darkerColour twBack
Diederik van Arkel's avatar
Diederik van Arkel committed
232 233 234 235
	, commentColour		= twComm
	, stringColour		= twStri
	, charColour		= Magenta
	, keywordColour		= twChar
Diederik van Arkel's avatar
Diederik van Arkel committed
236
	, typedefColour		= Black
237
	, typedeclColour	= Black
Diederik van Arkel's avatar
Diederik van Arkel committed
238 239
	}

240
scSyntaxColours :: SyntaxColours
Diederik van Arkel's avatar
Diederik van Arkel committed
241 242 243 244
scSyntaxColours =
	{ textColour		= Black
	, tabColour			= scTabs
	, backgroundColour	= scBack
245
	, marginColour		= darkerColour scBack
Diederik van Arkel's avatar
Diederik van Arkel committed
246 247 248 249
	, commentColour		= scComm
	, stringColour		= scStri
	, charColour		= scChar
	, keywordColour		= scKeyw
Diederik van Arkel's avatar
Diederik van Arkel committed
250
	, typedefColour		= Black
251
	, typedeclColour	= Black
Diederik van Arkel's avatar
Diederik van Arkel committed
252 253
	}

254
dmSyntaxColours :: SyntaxColours
Diederik van Arkel's avatar
Diederik van Arkel committed
255 256 257 258
dmSyntaxColours =
	{ textColour		= Black
	, tabColour			= scTabs
	, backgroundColour	= dmBack
259
	, marginColour		= darkerColour dmBack
Diederik van Arkel's avatar
Diederik van Arkel committed
260 261 262 263
	, commentColour		= scComm
	, stringColour		= scStri
	, charColour		= scChar
	, keywordColour		= scKeyw
Diederik van Arkel's avatar
Diederik van Arkel committed
264
	, typedefColour		= dmType
265
	, typedeclColour	= dmDecl
Diederik van Arkel's avatar
Diederik van Arkel committed
266 267
	}

268
imSyntaxColours :: SyntaxColours
Diederik van Arkel's avatar
Diederik van Arkel committed
269 270 271 272
imSyntaxColours =
	{ textColour		= Black
	, tabColour			= scTabs
	, backgroundColour	= imBack
273
	, marginColour		= darkerColour imBack
Diederik van Arkel's avatar
Diederik van Arkel committed
274 275 276 277
	, commentColour		= scComm
	, stringColour		= scStri
	, charColour		= scChar
	, keywordColour		= scKeyw
Diederik van Arkel's avatar
Diederik van Arkel committed
278
	, typedefColour		= imType
279
	, typedeclColour	= imDecl
Diederik van Arkel's avatar
Diederik van Arkel committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
	}

twBack	= RGB {r = 215, g = 255, b = 255}
twTabs	= RGB {r = 215, g =   0, b =   0}
twComm	= RGB {r =   0, g =   0, b = 215}
twStri	= RGB {r =   0, g = 175, b =   0}
twChar	= RGB {r = 185, g =   0, b = 255}
ewBack	= RGB {r = 255, g = 215, b = 255}
swBack	= RGB {r = 143, g = 219, b = 255}
pwTopc	= RGB {r = 215, g = 255, b = 229}
pwFore	= RGB {r = 109, g =   0, b =   0}
pwBack	= RGB {r = 210, g = 210, b = 179}
scBack	= RGB {r = 215, g = 255, b = 215}
scTabs	= RGB {r = 195, g =   0, b =   0}
scComm	= RGB {r =   0, g =   0, b = 195}
scStri	= RGB {r =   0, g = 155, b =   0}
scChar	= RGB {r = 155, g =   0, b = 155}
scKeyw	= RGB {r = 127, g =   0, b = 127}
dmBack	= RGB {r = 255, g = 215, b = 215}
imBack	= RGB {r = 255, g = 255, b = 215}
cwBack	= RGB {r = 244, g = 215, b = 244}
cwComm	= RGB {r =   0, g =   0, b = 215}
cwStri	= RGB {r =   0, g = 215, b =   0}
Diederik van Arkel's avatar
Diederik van Arkel committed
303 304
dmType	= RGB {r = 195, g =   0, b =   0}
imType	= RGB {r = 195, g =   0, b =   0}
305 306
dmDecl	= RGB {r = 195, g =   0, b =   0}
imDecl	= RGB {r = 195, g =   0, b =   0}
307 308 309 310 311 312 313 314 315

darkerColour :: Colour -> Colour
darkerColour (RGB rgb=:{r, g, b})
	=	RGB {rgb & r = darker r, g = darker g, b = darker b}
	where
		darker c
			=	c * 95 / 100
darkerColour colour
	=	colour
Diederik van Arkel's avatar
Diederik van Arkel committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
//--

openPrefs :: !String !*a -> *(!Prefs,!*a) | FileEnv a
openPrefs prefspath env
	# ((prefs,ok,err),env)	= accFiles (ReadPrefsFile prefspath) env
	| not ok
//		= abort ("Unable to read preferences: \n" +++ err)
		# env				=  savePrefs prefspath emptyPrefs env
		= (emptyPrefs,env)
	= (prefs,env)

savePrefs :: !String Prefs *a -> *a | FileEnv a
savePrefs prefspath prefs env
//	# prefspath		= applicationpath PrefsFileName
	# (ok,env)		= accFiles (SavePrefsFile prefspath prefs) env
	| not ok
//		= trace_n "Unable to write preferences" env
		= env
	= env

//-- OptionsFile Prefs

PrefsFileVersion :== "1.0"

SavePrefsFile	:: !{#Char} !Prefs !*Files -> (!Bool, !*Files);
SavePrefsFile	prefsPath prefs files
	#! (opened, file, files)	=	fopen prefsPath FWriteText files
	| not opened
		=	(False, files)
	#! options					=	WriteTable prefs
	#! file						=	WriteOptionsFile PrefsFileVersion options file
	=	fclose file files
	
ReadPrefsFile	:: !{#Char} !*Files -> ((!Prefs, !Bool, !{#Char}),!*Files)
ReadPrefsFile prefsPath ps
	#	(opened, file, ps)		= fopen prefsPath FReadData ps
	| not opened
		= ((emptyPrefs,False,"The file \"" +++  prefsPath +++ "\" could not be opened."),ps)
	#	(version, file)			= ReadVersion file
	| version <> PrefsFileVersion
		#	(_, ps)				= fclose file ps
		= ((emptyPrefs,False,"The file \"" +++  prefsPath +++ "\" has the wrong version."+++version+++"<<<"),ps)
	#!	(options, file)			= ReadOptionsFile file
		prefs					= ReadTable options
		(closed, ps)			= fclose file ps
	| not closed
		// generate warning?
		=	((prefs, True,"The file \"" +++ prefsPath +++ "\" clould not be closed."), ps)
	=	((prefs, True,""), ps)
	
WriteTable :: !Prefs -> [Option]
WriteTable prefs
	= PutOptions (PrefsOptionsTable) prefs

ReadTable :: .[Option] -> Prefs
ReadTable options
	# prefs = GetOptions PrefsOptionsTable options emptyPrefs
	= prefs

375
PathOption = SimpleWithStringConversionOption convert_path_separators "Path" id const
Diederik van Arkel's avatar
Diederik van Arkel committed
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400

PrefsOptionsTable :: OptionsTable Prefs
PrefsOptionsTable =
	{ ListOption "PmpPaths" (PathOption) "" (\a->a.pmp_pth) (\v a->{a & pmp_pth=v})
	, ListOption "PmpLinks" (PathOption) "" (\a->a.pmp_lnk) (\v a->{a & pmp_lnk=v})
	, ListOption "PmpObjcs" (PathOption) "" (\a->a.pmp_obj) (\v a->{a & pmp_obj=v})
	, GroupedOption "TWFnt" FontOptionsTable (\a->a.typ_prefs.typewinfont) (\v a->{a & typ_prefs.typewinfont=v})
	, GroupedOption "TWPos" VectOptionsTable (\a->a.typ_prefs.typewinpos) (\v a->{a & typ_prefs.typewinpos=v})
	, GroupedOption "TWSiz" SizeOptionsTable (\a->a.typ_prefs.typewinsiz) (\v a->{a & typ_prefs.typewinsiz=v})
	, GroupedOption "TWSync" SyncOptionsTable (\a->a.typ_prefs.typewinsync) (\v a->{a & typ_prefs.typewinsync=v})
	, GroupedOption "CWFnt" FontOptionsTable (\a->a.con_prefs.conswinfont) (\v a->{a & con_prefs.conswinfont=v})
	, GroupedOption "CWPos" VectOptionsTable (\a->a.con_prefs.conswinpos) (\v a->{a & con_prefs.conswinpos=v})
	, GroupedOption "CWSiz" SizeOptionsTable (\a->a.con_prefs.conswinsiz) (\v a->{a & con_prefs.conswinsiz=v})
	, GroupedOption "CWSync" SyncOptionsTable (\a->a.con_prefs.conswinsync) (\v a->{a & con_prefs.conswinsync=v})
	, GroupedOption "EWPrefs" ErrPrefsOptionsTable (\a->a.err_prefs) (\v a->{a & err_prefs=v})
	, GroupedOption "SWPrefs" SrcPrefsOptionsTable (\a->a.src_prefs) (\v a->{a & src_prefs=v})
	, GroupedOption "PWPos" VectOptionsTable (\a->a.prj_prefs.proj_pos) (\v a->{a & prj_prefs.proj_pos=v})
	, GroupedOption "PWSiz" SizeOptionsTable (\a->a.prj_prefs.proj_siz) (\v a->{a & prj_prefs.proj_siz=v})
	, SimpleOption "PWTop" (\a->a.prj_prefs.proj_topc) (\v a->{a & prj_prefs.proj_topc=v})
	, SimpleOption "PWFor" (\a->a.prj_prefs.proj_forc) (\v a->{a & prj_prefs.proj_forc=v})
	, SimpleOption "PWBak" (\a->a.prj_prefs.proj_bacc) (\v a->{a & prj_prefs.proj_bacc=v})
	, GroupedOption "PWFnt" FontOptionsTable (\a->a.prj_prefs.proj_font) (\v a->{a & prj_prefs.proj_font=v})
	, SimpleOption "PWDcl" (\a->if a.prj_prefs.proj_shft "1" "0") (\v a->{a & prj_prefs.proj_shft=(if (v=="1") True False)})
	, GroupedOption "EdFnt" FontOptionsTable (\a->a.edwinfont) (\v a->{a & edwinfont=v})
	, SimpleOption "EdTab" (\a->a.edwintabs) (\v a->{a & edwintabs=v})
401
	, SimpleOption "EdMargin" (\a->a.edwinmargin) (\v a->{a & edwinmargin=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
402 403 404 405 406 407 408 409 410 411 412
	, GroupedOption "ComOp" CompilerOptionsTable (\a->a.compopts) (\v a->{a & compopts=v})
	, GroupedOption "GenOp" CodeGenOptionsTable (\a->a.cgenopts) (\v a->{a & cgenopts=v})
	, GroupedOption "LnkOp" LinkOptionsTable (\a->a.linkopts) (\v a->{a & linkopts=v})
	, GroupedOption "AppOp" ApplicationOptionsTable (\a->a.applopts) (\v a->{a & applopts=v})
	, GroupedOption "SynCl" SyncOptionsTable (\a->a.syncols) (\v a->{a & syncols=v})
	, GroupedOption "DefCl" SyncOptionsTable (\a->a.defcols) (\v a->{a & defcols=v})
	, GroupedOption "ImpCl" SyncOptionsTable (\a->a.impcols) (\v a->{a & impcols=v})
	, ListOption "ProjHist" (PathOption) "" (\a->a.proj_hist) (\v a->{a & proj_hist=v})
	, ListOption "FileHist" (PathOption) "" (\a->a.file_hist) (\v a->{a & file_hist=v})
	, SimpleOption "SwitchClose" (\a->if a.switch_close "1" "0") (\v a->{a & switch_close=(if (v=="1") True False)})
	, SimpleOption "ShowToolbar" (\a->if a.show_toolbar "1" "0") (\v a->{a & show_toolbar=(if (v=="1") True False)})
Diederik van Arkel's avatar
Diederik van Arkel committed
413
//	, SimpleOption "ProveTheorems" (\a->if a.enable_prover "1" "0") (\v a->{a & enable_prover=(if (v=="1") True False)})
Diederik van Arkel's avatar
Diederik van Arkel committed
414 415 416
	, SimpleOption "BeVerbose" (\a->if a.be_verbose "1" "0") (\v a->{a & be_verbose=(if (v=="1") True False)})
	, SimpleOption "AltGrWorkaround" (\a->if a.altgr_workaround "1" "0") (\v a->{a & altgr_workaround=(if (v=="1") True False)})
	, SimpleOption "NewlineHandling" writeNLH readNLH
417
	, GroupedOption "RegPrefs" RegPrefsOptionsTable (\a->a.reg_prefs) (\v a->{a & reg_prefs = v})
Diederik van Arkel's avatar
Diederik van Arkel committed
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
	}
where
	writeNLH {newline_handling}
		= case newline_handling of
			(LeaveAlone NewlineConventionNone)	-> "L0"
			(LeaveAlone NewlineConventionMac)	-> "L1"
			(LeaveAlone NewlineConventionUnix)	-> "L2"
			(LeaveAlone NewlineConventionDos)	-> "L3"
			(AlwaysUse NewlineConventionNone)	-> "A0"
			(AlwaysUse NewlineConventionMac)	-> "A1"
			(AlwaysUse NewlineConventionUnix)	-> "A2"
			(AlwaysUse NewlineConventionDos)	-> "A3"
	readNLH v a
		= case v of
			"L0"	-> {a & newline_handling = LeaveAlone NewlineConventionNone}
			"L1"	-> {a & newline_handling = LeaveAlone NewlineConventionMac}
			"L2"	-> {a & newline_handling = LeaveAlone NewlineConventionUnix}
			"L3"	-> {a & newline_handling = LeaveAlone NewlineConventionDos}
			"A0"	-> {a & newline_handling = AlwaysUse NewlineConventionNone}
			"A1"	-> {a & newline_handling = AlwaysUse NewlineConventionMac}
			"A2"	-> {a & newline_handling = AlwaysUse NewlineConventionUnix}
			"A3"	-> {a & newline_handling = AlwaysUse NewlineConventionDos}
			_		-> {a & newline_handling = LeaveAlone NewlineConventionNone}

442 443
RegPrefsOptionsTable :: OptionsTable RegPrefs
RegPrefsOptionsTable =
444
	{ ListOption "ClideFlags" FlagOption ("","") (\a->ListToStrictList a.rp_flags) (\v a->{a & rp_flags=StrictListToList v})
445 446 447 448 449 450 451 452 453 454 455 456
	, SimpleOption "TimepName" (\a->a.tp_name) (\v a->{a & tp_name=v})
	, SimpleOption "TimepPath" (\a->a.tp_path) (\v a->{a & tp_path=v})
	, SimpleOption "HeappName" (\a->a.hp_name) (\v a->{a & hp_name=v})
	, SimpleOption "HeappPath" (\a->a.hp_path) (\v a->{a & hp_path=v})
	, SimpleOption "ProofName" (\a->a.pr_name) (\v a->{a & pr_name=v})
	, SimpleOption "ProofPath" (\a->a.pr_path) (\v a->{a & pr_path=v})
	, SimpleOption "VisedName" (\a->a.ve_name) (\v a->{a & ve_name=v})
	, SimpleOption "VisedPath" (\a->a.ve_path) (\v a->{a & ve_path=v})
	}

FlagOption = GroupedOption "Flags" FlagsOptionsTable id const

457
FlagsOptionsTable :: OptionsTable (String,String)
458
FlagsOptionsTable =
459 460
	{ SimpleOption "fName" (\(a,_)->a) (\v (a,b)->(v,b))
	, SimpleOption "fPath" (\(_,a)->a) (\v (a,b)->(a,v))
461 462
	}

Diederik van Arkel's avatar
Diederik van Arkel committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 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 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
ErrPrefsOptionsTable :: OptionsTable ErrPrefs
ErrPrefsOptionsTable =
	{ GroupedOption "EWPos" VectOptionsTable (\a->a.err_pos) (\v a->{a & err_pos=v})
	, GroupedOption "EWSiz" SizeOptionsTable (\a->a.err_siz) (\v a->{a & err_siz=v})
	, SimpleOption "EWFNm" (\a->a.err_fname) (\v a->{a & err_fname=v})
	, SimpleOption "EWFSz" (\a->a.err_fsize) (\v a->{a & err_fsize=v})
	, SimpleOption "EWFor" (\a->a.err_forc) (\v a->{a & err_forc=v})
	, SimpleOption "EWBak" (\a->a.err_bacc) (\v a->{a & err_bacc=v})
	, SimpleOption "EWErr" (\a->if a.err_err "1" "0") (\v a->{a & err_err=(if (v=="1") True False)})
	, SimpleOption "EWWrn" (\a->if a.err_wrn "1" "0") (\v a->{a & err_wrn=(if (v=="1") True False)})
	, SimpleOption "EWInf" (\a->if a.err_inf "1" "0") (\v a->{a & err_inf=(if (v=="1") True False)})
	}

SrcPrefsOptionsTable :: OptionsTable SrcPrefs
SrcPrefsOptionsTable =
	{ GroupedOption "EWPos" VectOptionsTable (\a->a.src_pos) (\v a->{a & src_pos=v})
	, GroupedOption "EWSiz" SizeOptionsTable (\a->a.src_siz) (\v a->{a & src_siz=v})
	, SimpleOption "EWFNm" (\a->a.src_fname) (\v a->{a & src_fname=v})
	, SimpleOption "EWFSz" (\a->a.src_fsize) (\v a->{a & src_fsize=v})
	, SimpleOption "EWFor" (\a->a.src_forc) (\v a->{a & src_forc=v})
	, SimpleOption "EWBak" (\a->a.src_bacc) (\v a->{a & src_bacc=v})
	}

instance toString (Int,Bool,Bool,Bool,Bool)
where
	toString (i,a,b,c,d) = booltriple a b c d +++ toString i
	where
		booltriple True True True True = "0"
		booltriple True True True False = "1"
		booltriple True True False True = "2"
		booltriple True True False False = "3"
		booltriple True False True True = "4"
		booltriple True False True False = "5"
		booltriple True False False True = "6"
		booltriple True False False False = "7"
		booltriple False True True True = "8"
		booltriple False True True False = "9"
		booltriple False True False True = "A"
		booltriple False True False False = "B"
		booltriple False False True True = "C"
		booltriple False False True False = "D"
		booltriple False False False True = "E"
		booltriple False False False False = "F"

instance fromString (Int,Bool,Bool,Bool,Bool)
where
	fromString s
		| size s == 0 = (0,False,False,False,False)
		# (a,b,c,d) = booltriple s.[0]
		# i = toInt (s%(1,size s - 1))
		= (i,a,b,c,d)
	where
		booltriple '0' = (True,True,True,True)
		booltriple '1' = (True,True,True,False)
		booltriple '2' = (True,True,False,True)
		booltriple '3' = (True,True,False,False)
		booltriple '4' = (True,False,True,True)
		booltriple '5' = (True,False,True,False)
		booltriple '6' = (True,False,False,True)
		booltriple '7' = (True,False,False,False)
		booltriple '8' = (False,True,True,True)
		booltriple '9' = (False,True,True,False)
		booltriple 'A' = (False,True,False,True)
		booltriple 'B' = (False,True,False,False)
		booltriple 'C' = (False,False,True,True)
		booltriple 'D' = (False,False,True,False)
		booltriple 'E' = (False,False,False,True)
		booltriple  _  = (False,False,False,False)

instance fromString Int where fromString s = toInt s

FontOptionsTable :: OptionsTable FontDef
FontOptionsTable =
	{ SimpleOption "Name" (\a->a.fName) (\v a->{a & fName=v})
	, ListOption "Styles" StyleOption "" (\a->ListToStrictList a.fStyles) (\v a->{a & fStyles=StrictListToList v})
	, SimpleOption "Size" (\a->a.fSize) (\v a->{a & fSize=v})
	}
StyleOption =SimpleOption "Style" id const

VectOptionsTable :: OptionsTable Vector2
VectOptionsTable =
	{ SimpleOption "VX" (\a->a.vx) (\v a->{a & vx=v})
	, SimpleOption "VY" (\a->a.vy) (\v a->{a & vy=v})
	}

SizeOptionsTable :: OptionsTable Size
SizeOptionsTable =
	{ SimpleOption "W" (\a->a.w) (\v a->{a & w=v})
	, SimpleOption "H" (\a->a.Size.h) (\v a->{Size | a & h=v})
	}

SyncOptionsTable :: OptionsTable SyntaxColours
SyncOptionsTable =
	{ SimpleOption "col_text" (\a->a.textColour) (\v a->{a & textColour=v})
	, SimpleOption "col_back" (\a->a.backgroundColour) (\v a->{a & backgroundColour=v})
558
	, SimpleOption "col_margin" (\a->a.marginColour) (\v a->{a & marginColour=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
559 560 561 562 563
	, SimpleOption "col_tabs" (\a->a.tabColour) (\v a->{a & tabColour=v})
	, SimpleOption "col_comm" (\a->a.commentColour) (\v a->{a & commentColour=v})
	, SimpleOption "col_stri" (\a->a.stringColour) (\v a->{a & stringColour=v})
	, SimpleOption "col_char" (\a->a.charColour) (\v a->{a & charColour=v})
	, SimpleOption "col_keyw" (\a->a.keywordColour) (\v a->{a & keywordColour=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
564
	, SimpleOption "col_type" (\a->a.typedefColour) (\v a->{a & typedefColour=v})
565
	, SimpleOption "col_decl" (\a->a.typedeclColour) (\v a->{a & typedeclColour=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
566 567
	}