search.icl 32.4 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
implementation module search

import StdArray, StdEnum, StdFunc, StdMisc, StdTuple
import StdClipboard,StdControlReceiver,StdMenuElement,StdPStClass,StdWindow
import UtilStrictLists, StrictList
import EdClient
import fbi
import IDE
import UtilInterrupt
import PmParse, PmPath
import ioutil
import PmPrefs
from EdText import textToStrings
14
from PmDirCache import SearchDisk,FindHModule
Diederik van Arkel's avatar
Diederik van Arkel committed
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
import morecontrols,colorpickcontrol,colourclip

initFindBoxInfo :: !Prefs !*a -> *(.(FindBoxInfo *(PSt General)),*a) | Ids, accScreenPicture a
initFindBoxInfo prefs pstate
	# (dlogId,pstate)	= openId pstate
	# (intrId,pstate)	= openId pstate
	# (msgId,pstate)	= openId pstate
	# (findId,pstate)	= openId pstate
	# (closeId,pstate)	= openId pstate
	# (stringId,pstate)	= openId pstate
	# (windId,pstate)	= openId pstate
	# (recvId,pstate)	= openRId pstate
	# (windlbId,pstate)	= openExtListBoxId pstate
	# fdef				=	{ fName = prefs.src_prefs.src_fname
							, fSize = prefs.src_prefs.src_fsize
							, fStyles = []
							}
	# (fnt,pstate)	= accScreenPicture (safeOpenFixedFont fdef) pstate	// use proper font...
	# fbi				=	{ dlogId		= dlogId
							, intrId		= intrId
							, msgId			= msgId
							, findId		= findId
							, closeId		= closeId
							, stringId		= stringId
							, kind			= Implementation
							, type			= SearchImports
							, is_searching	= False
							, cleanid		= []
							, verb			= True
							, export_		= False
							, windId		= windId
							, windlbId		= windlbId
							, src_offset	= prefs.src_prefs.src_pos
							, src_font		= fnt
							, src_forg		= prefs.src_prefs.src_forc
							, src_back		= prefs.src_prefs.src_bacc
							, src_size		= prefs.src_prefs.src_siz
							, pathname		= ""
							, recvId		= recvId
							}
	= (fbi,pstate)
	
sr_find_idi :: !Bool !*(PSt General) -> *PSt General
sr_find_idi always_dialog pstate		// Find Definition & Implementation & Identifier
	# (fbi,pstate)			= getFBI pstate
	# fbi					= {fbi & kind = Identifier, type = SearchProject}
  	# (maybepath,pstate)	= sendToActiveWindow (msgGetPathName) pstate
 	| isNothing maybepath
 		# fbi				= {fbi & pathname = ""}
 		# pstate			= setFBI fbi pstate
 		= fi_dialog fbi pstate
 	# pathname				= fromJust maybepath
   	# (maybesel,pstate)		= sendToActiveWindow (msgGetSelection) pstate
 	| isNothing maybesel || always_dialog || fst (fromJust maybesel) == "" || not (CleanModId (fst (fromJust maybesel)))
 		# fbi				= {fbi & pathname = pathname}
 		# pstate			= setFBI fbi pstate
		= fi_dialog fbi pstate
 	# (selection,_)			= fromJust maybesel
	# fbi					= {fbi & cleanid = removeDup [selection:fbi.cleanid], pathname = pathname}
	# pstate				= setFBI fbi pstate
75
	= fi_messagebox fbi pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

sr_find_def :: !Bool !*(PSt General) -> *PSt General
sr_find_def always_dialog pstate
	#	(fbi,pstate)	= getFBI pstate
	#	fbi				= {fbi & kind = Definition, type = SearchImports}
	= sr_find_def_imp always_dialog fbi pstate

sr_find_imp :: !Bool !*(PSt General) -> *PSt General
sr_find_imp always_dialog pstate
	#	(fbi,pstate)	= getFBI pstate
	#	fbi				= {fbi & kind = Implementation, type = SearchImports}
	= sr_find_def_imp always_dialog fbi pstate

sr_find_def_imp :: !Bool !.(FindBoxInfo *(PSt *General)) !*(PSt General) -> *PSt General
sr_find_def_imp always_dialog info pstate
  	#	(maybesel,pstate)	= sendToActiveWindow (msgGetSelection) pstate
  	#	(maybepath,pstate)	= sendToActiveWindow (msgGetPathName) pstate
 	| isNothing maybepath
		= sr_find_def_imp_sel always_dialog "" "" {info & type = SearchProject} pstate
 	| isNothing maybesel
		= sr_find_def_imp_sel always_dialog "" "" info pstate
 	#	pathname			= fromJust maybepath
 	#	(selection,_)		= fromJust maybesel
 	// filter multiline strings...
 	#	hasnewline			= or [c == '\xd' || c == '\xa' \\ c <-: selection]
 	#	string				= case hasnewline of
 								True	-> ""
 								False	-> selection
 	= sr_find_def_imp_sel always_dialog string pathname info pstate

sr_find_def_imp_sel :: !Bool !{#.Char} !.Pathname !.(FindBoxInfo *(PSt *General)) !*(PSt *General) -> *(PSt *General)
sr_find_def_imp_sel always_dialog selection pathname info=:{cleanid} pstate
 	#	info			= {info & cleanid = removeDup [selection:cleanid], pathname = pathname}
 	#	pstate			= setFBI info pstate
 	| size selection == 0 || not (CleanModId selection) || always_dialog
 		= fi_dialog info pstate
112
 	= fi_messagebox info pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
113

114
fi_messagebox info=:{cleanid,dlogId,stringId,msgId,kind,closeId} pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
115 116 117 118 119 120 121
	| isEmpty cleanid
		= pstate
	#	pstate			= closeWindow dlogId pstate
		(_,pstate)		= openModalDialog info dialog pstate
	= pstate
where
	dialog = Dialog
122
				( case kind of
Diederik van Arkel's avatar
Diederik van Arkel committed
123 124 125 126 127
					Definition			-> "Find Definition"
					Implementation		-> "Find Implementation"
					Identifier			-> "Find Identifier"
				)
				(	TextControl ""
128
						[ ControlId msgId
Diederik van Arkel's avatar
Diederik van Arkel committed
129 130 131 132 133
						, ControlWidth (PixelWidth 300)
						]	// area to show messages
				:+:	TextControl "Find:"
						[ ControlPos (Left,zero)
						]
134
				:+:	EditControl (hd cleanid) (PixelWidth 300) 1
Diederik van Arkel's avatar
Diederik van Arkel committed
135
						[ ControlPos (Left,zero)
136
						, ControlId stringId
137
						, ControlActivate (noLS (appPIO (setEditControlSelection stringId 1 0)))
Diederik van Arkel's avatar
Diederik van Arkel committed
138 139 140 141
						]
				:+: ButtonControl "Close"
						[ ControlFunction closefun
						, ControlPos (Left,zero)
142
						, ControlId closeId
Diederik van Arkel's avatar
Diederik van Arkel committed
143 144
						]
				)
145 146 147
				[ WindowId dlogId
				, WindowCancel closeId
				, WindowOk closeId
Diederik van Arkel's avatar
Diederik van Arkel committed
148
				, WindowClose closefun
149
				, WindowInit sr_find_worker
Diederik van Arkel's avatar
Diederik van Arkel committed
150 151
				]
	closefun (ls,ps)
152
		#	ps		= closeWindow dlogId ps
Diederik van Arkel's avatar
Diederik van Arkel committed
153 154
		= (ls, ps)

155
fi_dialog info=:{dlogId,msgId,stringId,cleanid,kind,type,verb,export_,closeId,findId,recvId} pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
156 157 158 159 160 161 162
	#	pstate			= closeWindow dlogId pstate
		(_,pstate)		= openModalDialog info dialog pstate
	= pstate
where
	dialog =
		Dialog "Find..."
		(	TextControl ""
163
				[ ControlId msgId
Diederik van Arkel's avatar
Diederik van Arkel committed
164 165 166 167 168
				, ControlWidth (PixelWidth 300)
				]	// area to show messages
		:+:	TextControl "Find:"
				[ ControlPos (Left,zero)
				]
169
		:+:	PopUpControl [(ci,id) \\ ci <- cleanid] 0
Diederik van Arkel's avatar
Diederik van Arkel committed
170
				[ ControlPos (Left,zero)
171
				, ControlId stringId
Diederik van Arkel's avatar
Diederik van Arkel committed
172 173 174 175 176 177 178 179 180
				, ControlKeyboard		filterReturnKeys Able (noLS1 (\_->stringKey))
				, ControlDeactivate	(noLS stringKey)
				, ControlWidth (PixelWidth 300)
				]
		:+: RadioControl
				[("Find Definition"		,Nothing,noPS (\l->{l & kind = Definition}))
				,("Find Implementation"	,Nothing,noPS (\l->{l & kind = Implementation}))
				,("Find Identifiers"	,Nothing,noPS (\l->{l & kind = Identifier}))
				] (Columns 1)
181
				( case kind of
Diederik van Arkel's avatar
Diederik van Arkel committed
182 183 184 185 186 187 188 189 190 191 192
					Definition -> 1
					Implementation -> 2
					Identifier -> 3
				)
				[ ControlPos (Left,zero)
				]
		:+:	RadioControl
				[("Search in Imported Files"	,Nothing,noPS (\l->{l & type = SearchImports}))
				,("Search in Paths"				,Nothing,noPS (\l->{l & type = SearchPaths}))
				,("Search in Project"			,Nothing,noPS (\l->{l & type = SearchProject}))
				] (Columns 1)
193
				( case type of
Diederik van Arkel's avatar
Diederik van Arkel committed
194 195 196 197 198 199 200
					SearchImports	-> 1
					SearchPaths		-> 2
					SearchProject	-> 3
				)
				[
				]
		:+:	CheckControl
201 202
				[("Be Verbose"					,Nothing,toMark	verb	,noPS (\l->{l & verb = not l.verb}))
				,("Exported Identifiers Only"	,Nothing,toMark	export_	,noPS (\l->{l & export_ = not l.export_}))
Diederik van Arkel's avatar
Diederik van Arkel committed
203 204 205 206 207 208
				] (Columns 1)
				[ ControlPos (Left,zero)
				]
		:+: ButtonControl "Close"
				[ ControlFunction closefun
				, ControlPos (Left,zero)
209
				, ControlId closeId
Diederik van Arkel's avatar
Diederik van Arkel committed
210 211
				]
		:+: ButtonControl "Find"
212
				[ ControlId findId
Diederik van Arkel's avatar
Diederik van Arkel committed
213 214
				, ControlFunction findfun
				]
215
		:+: Receiver recvId recvfun
Diederik van Arkel's avatar
Diederik van Arkel committed
216 217
				[ ]
		)
218 219 220
		[ WindowId dlogId
		, WindowOk findId
		, WindowCancel closeId
Diederik van Arkel's avatar
Diederik van Arkel committed
221 222 223 224
		, WindowClose closefun
		]
	
	stringKey ps=:{io}
225 226 227 228
		# (wst,io)	= getWindow dlogId io
		  title		= fromJust (snd (hd (getControlTexts [stringId] (fromJust wst))))
		# io		= openPopUpControlItems stringId 0 [(title,id)] io
		# io		= selectPopUpControlItem stringId 0 io
Diederik van Arkel's avatar
Diederik van Arkel committed
229 230
		= {ps & io=io}

231
savefun (ls=:{dlogId,stringId,cleanid},ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
232 233 234 235 236 237 238 239 240 241 242 243 244
	# (wdef,ps)		= accPIO (getWindow dlogId) ps
	| isNothing wdef
//		= trace_n "Fatal error in Find Identifier Dialog: 1" (ls,ps)
		= (ls,ps)
	# wdef			= fromJust wdef
	# [(ok,ss):_]	= getControlTexts [stringId] wdef
	| not ok
//		= trace_n "Fatal error in Find Identifier Dialog: 2" (ls,ps)
		= (ls,ps)
	| (isNothing ss)
//		= trace_n "Fatal error in Find Identifier Dialog: 3" (ls,ps)
		= (ls,ps)
	# ss			= fromJust ss
245
	# ls			= {ls & cleanid = removeDup [ss:cleanid]}
Diederik van Arkel's avatar
Diederik van Arkel committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
	# ps			= setFBI ls ps
	= (ls,ps)
closefun (ls=:{dlogId},ps)
	# (ls,ps)	= savefun (ls,ps)
	# ps		= closeWindow dlogId ps
	= (ls, ps)
findfun (ls=:{is_searching,dlogId,intrId,findId},ps)
	# (ls,ps)	= savefun (ls,ps)
	| is_searching
		# ls	= {ls & is_searching = False}
		# ps	= StopIntr (dlogId,intrId) ps
		# ps	= appPIO (setControlText findId "Find") ps
		= (ls,ps)
	# ls	= {ls & is_searching = True}
	# ps	= appPIO (setControlText findId "Stop") ps
261
	# (ls, ps)	= sr_find_worker (ls, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275
	= (ls, ps)
recvfun _ (ls=:{is_searching,findId},ps)
	| is_searching
		# ls	= {ls & is_searching = False}
		# ps	= appPIO (setControlText findId "Find") ps
		= (ls,ps)
	# ls	= {ls & is_searching = True}
	# ps	= appPIO (setControlText findId "Stop") ps
	= (ls, ps)

import StdPathname, Directory

getModulesInPaths ps
	# (ep,ps) = getCurrentPaths ps
276
	# (pp,ps) = getFromProject PR_GetPaths ps
277
	= accFiles (findmods (Concat pp ep)) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
278 279 280 281 282
where
	findmods Nil files
		= ([],files)
	findmods (path:!paths) files
		# ((ok,path`),files) = pd_StringToPath path files
283 284
		| not ok
			= findmods paths files
Diederik van Arkel's avatar
Diederik van Arkel committed
285
		# ((err,dir),files)		= getDirectoryContents path` files
286 287
		| err <> NoDirError
			= findmods paths files
Diederik van Arkel's avatar
Diederik van Arkel committed
288 289 290 291 292 293 294 295 296 297 298 299 300 301
		# dir					= map getinfo dir		// only need common fileinfo...
		# dir					= filter (\(b,n)-> (not b)) dir
		# dir					= map (\(_,n)->n) dir
		// apply extra filter to only search .icl's and .dcl's
		# dir					= filter is_interesting dir
		# dir					= map (\n->MakeFullPathname path n) dir
		# (mods,files)			= findmods paths files
		# mods					= dir ++ mods
		= (mods,files)

	getinfo {fileName,fileInfo=fi=:{pi_fileInfo=dummyname=:{isDirectory}}}
		= (isDirectory,fileName)

	is_interesting string
302 303 304 305 306 307
		# s = size string
		  suffix_4 = string % (s-4,s-1)
		  suffix_3 = string % (s-3,s-1)
		= (s >= 4 && (suffix_4==".icl" || suffix_4==".dcl")) || (s>=3 && suffix_3==".hs")

sr_find_worker :: !(FindBoxInfo *(PSt *General),!*(PSt *General)) -> (!FindBoxInfo *(PSt *General),!*PSt *General)
308
sr_find_worker (info=:{kind,type,dlogId=fId,intrId=tId, pathname}, pstate)
Diederik van Arkel's avatar
Diederik van Arkel committed
309
	// close search window... so that it can be opened later with the search results
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
	# pstate = sw_safe_close pstate
	= case type of
		SearchPaths
			# (modpaths, pstate) = getModulesInPaths pstate
			  (paths,pstate) = get_paths pstate
			  pstate = StartIntr (fId,tId) (search fId tId pathname (pathname :! (ListToStrictList modpaths)) kind paths) pstate
			-> (info,pstate)
		SearchProject	// Wrong: searches imports visible from main instead of project :-(
			# (prj,pstate)		= getProject pstate
			  ({mdn_dir,mdn_name},prj) = PR_GetRootModuleDirAndName prj
			  (paths,pstate) = get_paths pstate
			  pstate = StartIntr (fId,tId) (search fId tId (mdn_dir+++mdn_name) (mdn_name :! Nil) kind paths) pstate
			-> (info,pstate)
		SearchImports
			# (paths,pstate) = get_paths pstate
			  ({mdn_dir,mdn_name},module_path) = determine_dir_and_filename pathname paths
			  pstate = StartIntr (fId,tId) (search fId tId module_path (mdn_name :! Nil) kind paths) pstate
			-> (info,pstate)
Diederik van Arkel's avatar
Diederik van Arkel committed
328
where
329 330 331 332 333 334 335 336 337
	get_paths pstate
		# (syspaths,pstate) = getCurrentPaths pstate
		  (prjpaths,pstate) = getFromProject PR_GetPaths pstate
		= (AppendLists prjpaths syspaths, pstate)

	search dId iId pathname modpaths Identifier paths intr pstate
		= SearchIdentifiersInFiles dId iId (IsDefPathname pathname) info Nil modpaths paths intr pstate
	search dId iId pathname modpaths search_kind paths intr pstate
		= SearchDefinitionInFiles dId iId (IsDefPathname pathname) info Nil modpaths paths intr pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
338 339 340

//--- Definition Search

341 342 343
SearchDefinitionInFiles :: !Id !Id !Bool !(FindBoxInfo *(PSt *General)) !(List String) !(List Pathname) !(List Pathname) !Bool !*(PSt *General)
						-> *PSt *General
SearchDefinitionInFiles dId iId is_dcl_file info=:{type} done modnames paths intr ps
Diederik van Arkel's avatar
Diederik van Arkel committed
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 375 376
	= SearchDefinitionInFiles True False is_dcl_file info done modnames intr ps
where
	imports = (type == SearchImports) || (type == SearchProject)
	
	SearchDefinitionInFiles first found is_dcl_file info done modnames True ps
		// INTERRUPT
		#	ps = StopIntr (dId,iId) ps
		= ResetButtonString ps
	SearchDefinitionInFiles first False is_dcl_file info done Nil intr ps
		// NO MORE FILES && NOT FOUND
		#	ps = StopIntr (dId,iId) ps
		#	ps = ResetButtonString ps
		=	ChangeMsgString True "Not Found" ps
	SearchDefinitionInFiles first True is_dcl_file info done Nil intr ps
		// NO MORE FILES && FOUND
		# ps = StopIntr (dId,iId) ps
		# ps = closeWindow dId ps	// close the find... info box
		# ((_,itms),ps) = getExtListBoxItems info.windlbId ps
		| length itms == 1
			= execExtListBoxItem info.windlbId 1 ps	
		= ps
	SearchDefinitionInFiles first found is_dcl_file info done ("":!rest) intr ps
		// BLANK FILENAME ???
		=	SearchDefinitionInFiles False found is_dcl_file info done rest intr ps
	SearchDefinitionInFiles first found is_dcl_file info=:{kind=search_kind,verb=verbose,cleanid,export_} done (modname:!rest) intr ps
		// ACTUAL SEARCH
		| isEmpty cleanid
			= ps
		# cleanid = hd cleanid
		| is_dcl_file && StringOccurs modname done
			// if already done move onto next...
			// slightly tricky phrasing is to make sure that if search starts in mod.icl then mod.dcl is also done...
			= SearchDefinitionInFiles False found is_dcl_file info done rest intr ps
377 378 379 380
		#	modname` = add_suffix is_dcl_file modname
			ps								= ChangeMsgString verbose ("Searching '" +++ RemovePath modname` +++ "'") ps
			(impsa,found_positions,modname`,ps)
				= SearchDefinitionInFile imports rest cleanid modname` paths ps
Diederik van Arkel's avatar
Diederik van Arkel committed
381 382 383 384 385 386 387 388 389
			found_in_file					= case found_positions of
												Pos _ _ _	-> True
												Cls _ _ _	-> True
												Ins _ _ _	-> True
												_			-> False
			find_definition					= case search_kind of
												Definition	-> True
												_			-> False
			search_icl_file_next			= found_in_file && is_dcl_file && (not find_definition)
390
			rest`							= if search_icl_file_next
Diederik van Arkel's avatar
Diederik van Arkel committed
391
												(modname :! impsa)
392
												(if is_dcl_file impsa (modname :! impsa))
Diederik van Arkel's avatar
Diederik van Arkel committed
393 394 395 396 397 398 399 400 401 402
			next_file_is_dcl_file			= not search_icl_file_next
			found_here						= found_in_file && (find_definition == is_dcl_file)
			found							= found || found_here
			first = first && (not is_dcl_file)
		| found_here
			# ps							= WriteFoundPositionsInSearchWindow info search_kind modname` found_positions cleanid ps
			= ContIntr (dId,iId) (SearchDefinitionInFiles first found next_file_is_dcl_file info done` rest`) ps
		= ContIntr (dId,iId) (SearchDefinitionInFiles first found next_file_is_dcl_file info done` rest`) ps
	where
		done`
403 404 405 406 407
			| is_dcl_file
				= (modname :! done)
				= done

		SearchDefinitionInFile imp rest cleanid modname paths ps
Diederik van Arkel's avatar
Diederik van Arkel committed
408
			| IsFullPathname modname
409 410 411
				# ((impsa,found_positions),ps) = seach_definition_in_file modname imp rest cleanid ps
				= (impsa,found_positions,modname,ps)
			# ((ok,path),ps) = accFiles (search_disk modname paths) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
412
			| ok
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
				# ((impsa,found_positions),ps) = seach_definition_in_file path imp rest cleanid ps
				= (impsa,found_positions,modname,ps)
			= (rest,PosNil,modname,ps)

		seach_definition_in_file path imp rest cleanid ps
			# (win,ps) = IsOpen path ps
			| isJust win
				# (text,ps) = message (fromJust win) msgGetText ps
				= case text of
					Nothing
						-> accFiles (FindDefinitionInFile imp rest cleanid path) ps
					Just text
						# text = textToStrings text
						# text = slToList text
						# text = {t \\ t <- text}
						-> accFiles (FindDefinitionInText imp rest cleanid text) ps
			= accFiles (FindDefinitionInFile imp rest cleanid path) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
430 431 432

//--- Identifier Search

433 434 435
SearchIdentifiersInFiles :: !Id !Id !Bool !(FindBoxInfo *(PSt *General)) !(List String) !(List Pathname) !(List Pathname) !Bool !*(PSt *General)
							-> *PSt *General
SearchIdentifiersInFiles dId iId is_dcl_file info done modnames paths True ps
Diederik van Arkel's avatar
Diederik van Arkel committed
436 437 438 439
	// INTERRUPT
	#	ps = StopIntr (dId,iId) ps
	#	ps = ResetButtonString ps
	=	ps
440
SearchIdentifiersInFiles dId iId is_dcl_file info done Nil paths intr ps
Diederik van Arkel's avatar
Diederik van Arkel committed
441 442 443 444 445 446 447 448 449 450
	// NO MORE TO DO
	#	ps = StopIntr (dId,iId) ps
	#	ps = ResetButtonString ps
	# ((_,itms),ps) = getExtListBoxItems info.windlbId ps
	| length itms == 0
		= ChangeMsgString True "Not Found" ps
	# ps = closeWindow dId ps
	| length itms == 1
		= execExtListBoxItem info.windlbId 1 ps	
	= ps
451
SearchIdentifiersInFiles dId iId is_dcl_file info done ("":!rest) paths intr ps
Diederik van Arkel's avatar
Diederik van Arkel committed
452
	// BLANK FILENAME
453 454
	=	SearchIdentifiersInFiles dId iId is_dcl_file info done rest paths intr ps
SearchIdentifiersInFiles dId iId is_dcl_file info=:{kind=search_kind,verb=verbose,type=imp,cleanid,export_} done (modname:!rest) paths intr ps
Diederik van Arkel's avatar
Diederik van Arkel committed
455 456 457
	| isEmpty cleanid = ps
	# cleanid = hd cleanid
	| not is_dcl_file && StringOccurs modname done
458 459
		= SearchIdentifiersInFiles dId iId False info done rest paths intr ps
	#	modname` = add_suffix is_dcl_file modname
Diederik van Arkel's avatar
Diederik van Arkel committed
460
	#	ps					= ChangeMsgString verbose ("Searching '" +++ RemovePath modname` +++ "'") ps
461 462
	# (impsa,found_positions,modname`,ps)
		= SearchIdentifiersInFile True rest cleanid modname` paths ps
Diederik van Arkel's avatar
Diederik van Arkel committed
463 464 465
	#	found_in_file					= case found_positions of
											PosNil	-> False
											_		-> True
466
	#	ps = write_found_positions found_in_file modname` found_positions cleanid ps
Diederik van Arkel's avatar
Diederik van Arkel committed
467
	| not is_dcl_file
468 469
		= ContIntr (dId,iId) (SearchIdentifiersInFiles dId iId True info done (modname:!impsa) paths) ps
		= ContIntr (dId,iId) (SearchIdentifiersInFiles dId iId False info (modname:!done) impsa paths) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
470
where
471
	write_found_positions found_in_file modname` found_positions cleanid pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
472 473 474
		| found_in_file
			= WriteFoundPositionsInSearchWindow info search_kind modname` found_positions cleanid pstate
		= pstate
475 476 477 478

	SearchIdentifiersInFile :: !Bool !(List Pathname) !String !Pathname !(List Pathname) !*(PSt *General)
								-> *(!List Modulename,IdentifierPositionList,!Pathname,!*(PSt *General))
	SearchIdentifiersInFile imp rest cleanid modname paths pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
479
		| IsFullPathname modname
480 481 482
			# ((impsa,found_positions),ps) = search_identifiers_in_file modname imp rest cleanid pstate
			= (impsa,found_positions,modname,ps)
		# ((ok,path), pstate) = accFiles (search_disk modname paths) pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
483
		| ok
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
			# ((impsa,found_positions),ps) = search_identifiers_in_file path imp rest cleanid pstate
			= (impsa,found_positions,modname,ps)
		= (rest,PosNil,modname,pstate)

	search_identifiers_in_file :: !Pathname !Bool !(List Pathname) !String !*(PSt *General) -> *(!(List Modulename,IdentifierPositionList),!*(PSt *General))
	search_identifiers_in_file path imp rest cleanid pstate
		# (win,pstate) = IsOpen path pstate
		| isJust win
			# (text,pstate) = message (fromJust win) msgGetText pstate
			= case text of
				Nothing
					-> accFiles (FindIdentifiersInFile imp rest cleanid path) pstate
				Just text
					# text = textToStrings text
					# text = slToList text
					# text = {t \\ t <- text}
					-> accFiles (FindIdentifiersInText imp rest cleanid text) pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
501
			= accFiles (FindIdentifiersInFile imp rest cleanid path) pstate
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

add_suffix :: !Bool !Pathname -> Pathname
add_suffix is_dcl_file modname
	| is_dcl_file
		= MakeDefPathname modname
		= MakeImpPathname modname

search_disk :: !Modulename !(List Pathname) !*Files -> (!(!Bool,!Pathname),!*Files)
search_disk module_name paths files
	# n=n_chars_of_file_ext module_name
	| n==0
		= SearchDisk module_name paths files
		# (module_name,file_ext) = split_string n module_name
		= FindHModule module_name file_ext paths files
  where
	n_chars_of_file_ext s
		# n=size s
		| n>3 && is_3_char_file_ext (s % (n-4,n-1))
			= 4
		| n>2 && is_2_char_file_ext (s % (n-3,n-1))
			= 3
			= 0
	where
		is_3_char_file_ext ".icl" = True
		is_3_char_file_ext ".dcl" = True
		is_3_char_file_ext ".lhs" = True
		is_3_char_file_ext _ = False
Diederik van Arkel's avatar
Diederik van Arkel committed
529
		
530 531 532 533 534 535 536 537
		is_2_char_file_ext ".hs" = True
		is_2_char_file_ext _ = False
	
	split_string :: !Int !{#Char} -> (!{#Char},!{#Char})
	split_string i s
		# n=size s
		# i=n-i
		= (s % (0,i-1),s % (i,n-1))
Diederik van Arkel's avatar
Diederik van Arkel committed
538 539 540 541 542

IsOpen modname ps
	# (windows,ps)	= accPIO getWindowsStack ps
	= doall windows ps
where
543
	doall :: ![Id] !*(PSt *General) -> *(!.Maybe Id,!*PSt *General)
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 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
	doall [] ps = (Nothing,ps)
	doall [win:res] ps
		#	(mr,ps)		= message win msgGetPathName ps
		| isNothing mr
			= doall res ps
		#	pathname`	= fromJust mr
		| modname == pathname`
			= (Just win,ps)
		= doall res ps

//--- Search message handling

ChangeMsgString :: !.Bool !.{#Char} !*(PSt *General) -> *PSt *General
ChangeMsgString verbose message pstate
	| verbose
		#	(fbi,pstate)	= getFBI pstate
			pstate			= appPIO (setControlTexts [(fbi.msgId,message)]) pstate
		= pstate
	= pstate // change string in find message dialog

ResetButtonString pst
	# ({recvId},pst)	= getFBI pst
	# (_,pst)			= asyncSend recvId True pst
	= pst

//--- Search window handling

//WriteFoundPositionsInSearchWindow :: !SearchKind !Modulename !IdentifierPositionList !String !*(PSt General) -> *PSt General
WriteFoundPositionsInSearchWindow info search_kind modname list id pstate
	# msgtext	= WriteFoundPositionsInSearchWindow info search_kind modname list id
	= updateSearchWindow info msgtext pstate
where
	WriteFoundPositionsInSearchWindow info search_kind modname PosNil id
		= Nil
	WriteFoundPositionsInSearchWindow info search_kind modname (Pos line_n _ positions) id
		#	msgtxt	= MakeFoundPosMsg search_kind modname (inc line_n) id
		=	msgtxt :! WriteFoundPositionsInSearchWindow info search_kind modname positions id
	where
		MakeFoundPosMsg Definition mod linenr id
			# path = MakeDefPathname (RemovePath mod)
			= ("Definition found in [" +++ path +++ "," +++ toString linenr +++ "]: " +++ id, path, linenr)
		MakeFoundPosMsg Implementation mod linenr id
586
			# path = make_implementation_file_name mod
Diederik van Arkel's avatar
Diederik van Arkel committed
587 588 589 590 591 592 593 594 595 596 597 598
			= ("Implementation found in [" +++ path +++ "," +++ toString linenr +++ "]: " +++ id, path, linenr)
		MakeFoundPosMsg Identifier mod linenr id
			# path = RemovePath mod
			= ("Identifier found in [" +++ path +++ "," +++ toString linenr +++ "]: " +++ id,path,linenr)
	WriteFoundPositionsInSearchWindow info search_kind modname (Ins line_n _ positions) id
		#	msgtxt	= MakeFoundInsMsg search_kind modname (inc line_n) id
		=	msgtxt :! WriteFoundPositionsInSearchWindow info search_kind modname positions id
	where
		MakeFoundInsMsg Definition mod linenr id
			# path = MakeDefPathname (RemovePath mod)
			= ("Instance Definition found in [" +++ path +++ "," +++ toString linenr +++ "]: " +++ id,path,linenr)
		MakeFoundInsMsg Implementation mod linenr id
599
			# path = make_implementation_file_name mod
Diederik van Arkel's avatar
Diederik van Arkel committed
600 601 602 603 604 605 606 607 608 609 610 611
			= ("Instance Implementation found in [" +++ path +++ "," +++ toString linenr +++ "]: " +++ id,path,linenr)
		MakeFoundInsMsg Identifier mod linenr id
			# path = RemovePath mod
			= ("Identifier found in [" +++ path +++ "," +++ toString linenr +++ "]: " +++ id,path,linenr)
	WriteFoundPositionsInSearchWindow info search_kind modname (Cls line_n _ positions) id
		#	msgtxt	= MakeFoundClsMsg search_kind modname (inc line_n) id
		=	msgtxt :! WriteFoundPositionsInSearchWindow info search_kind modname positions id
	where
		MakeFoundClsMsg Definition mod linenr id
			# path = MakeDefPathname (RemovePath mod)
			= ("Class Definition found in [" +++ path +++ "," +++ toString linenr +++ "]: " +++ id,path,linenr)
		MakeFoundClsMsg Implementation mod linenr id
612
			# path = make_implementation_file_name mod
Diederik van Arkel's avatar
Diederik van Arkel committed
613 614 615 616 617
			= ("Class Implementation found in [" +++ path +++ "," +++ toString linenr +++ "]: " +++ id,path,linenr)
		MakeFoundClsMsg Identifier mod linenr id
			# path = RemovePath mod
			= ("Identifier found in [" +++ path +++ "," +++ toString linenr +++ "]: " +++ id,path,linenr)

618 619 620 621 622 623
	make_implementation_file_name mod
		# file_name = RemovePath mod
		| IsImpPathname file_name
			= file_name
			= MakeImpPathname file_name

Diederik van Arkel's avatar
Diederik van Arkel committed
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
//-- Search Results Window...

updateSearchWindow info=:{windlbId} text ps	// fun to update error info in error window, text :: !Text
	# ({searchIds},ps)	= getMenuIds ps
	# ps		= wind_open info (searchIds.nextIds!!0) ps
	# ps		= appendExtListBoxItems windlbId [(msg,fifi path lnr,id) \\ (msg,path,lnr) <- (StrictListToList text)] ps
	= ps
where
	fifi path lnr ps
		| not_empty = OpenModule path (lineSelection lnr) ps
		= ps
	where
		not_empty	= path <> EmptyPathname

wind_open info=:{windlbId,windId,src_offset,src_font,src_size,src_forg,src_back} menu_elem_id ps
	#	elb				= ExtListBoxControl [] [] (\_ ps -> ps) windlbId
							[ ControlViewSize src_size
							, ControlResize win_resize
							, ControlPen [PenColour src_forg,PenBack src_back,PenFont src_font]
							]
		(win_size,ps)	= controlSize elb True Nothing Nothing Nothing ps
		(_,ps)			= openWindow undef (searchwin elb win_size) ps
	= ps
where
	win_resize oc ow nw = {w = oc.w + nw.w - ow.w, h = oc.Size.h + nw.Size.h - ow.Size.h}
	searchwin elb win_size = Window "Search Results"
					( elb
					)
					[ WindowId windId
653
					, WindowClose (noLS (sw_close windId o wind_deac))
654
					, WindowInit (noLS (sw_init)) 
Diederik van Arkel's avatar
Diederik van Arkel committed
655
					, WindowDeactivate (noLS wind_deac)
Diederik van Arkel's avatar
Diederik van Arkel committed
656 657
					, WindowInitActive windlbId.controlId
					, WindowActivate (noLS (wind_act windlbId.controlId))
Diederik van Arkel's avatar
Diederik van Arkel committed
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
					, WindowViewSize win_size
					, WindowPos (Fix, OffsetVector src_offset)
					]
wind_deac ps
	# (inf=:{windId},ps)	= getFBI ps
	# (pos,ps)	= accPIO (getWindowPos windId) ps
	| isNothing pos
		= ps
	# pos		= fromJust pos
	# (siz,ps)	= accPIO (getWindowViewSize windId) ps
	# inf		= {inf & src_offset = pos, src_size = siz}
	# ps		= setFBI inf ps
	# ({mn_cut,mn_cpy,mn_pst,mn_clr,mg_edt,searchIds},ps=:{io})
			= getMenuIds ps
	// enable Edit menu stuff
	# io = enableMenuElements [mn_cut,mn_cpy,mn_pst,mn_clr:mg_edt] io
	// enable Search menu stuff
	# io = enableMenuElements searchIds.findIds io
	# io = enableMenuElements searchIds.gotoIds io
	= {ps & io = io}

Diederik van Arkel's avatar
Diederik van Arkel committed
679
wind_act cId ps
Diederik van Arkel's avatar
Diederik van Arkel committed
680 681 682 683 684 685 686
	# ({mn_cut,mn_cpy,mn_pst,mn_clr,mg_edt,searchIds},ps=:{io})
			= getMenuIds ps
	// disable Edit menu stuff
	# io = disableMenuElements [mn_cut,mn_cpy,mn_pst,mn_clr:mg_edt] io
	// disable Search menu stuff
	# io = disableMenuElements searchIds.findIds io
	# io = disableMenuElements searchIds.gotoIds io
Diederik van Arkel's avatar
Diederik van Arkel committed
687 688 689
	# ps = {ps & io = io}
//	# ps = setActiveControl cId ps
	= ps
Diederik van Arkel's avatar
Diederik van Arkel committed
690

691 692 693 694
sw_init ps
	# ({searchIds},ps) = getMenuIds ps
	= appPIO (enableMenuElements [searchIds.nextIds!!0]) ps

695
sw_close windId ps
Diederik van Arkel's avatar
Diederik van Arkel committed
696 697 698 699 700 701
	# ({searchIds},ps) = getMenuIds ps
	# ps = appPIO (disableMenuElements [searchIds.nextIds!!0]) ps
	= closeWindow windId ps
	
sw_safe_close :: !*(PSt *General) -> *PSt *General
sw_safe_close ps
702
	# ({windId},ps) = getFBI ps
Diederik van Arkel's avatar
Diederik van Arkel committed
703 704
	# (win,ps)	= accPIO getActiveWindow ps
	| isNothing win
705
		= sw_close windId ps
Diederik van Arkel's avatar
Diederik van Arkel committed
706
	# win = fromJust win
707
	| win == windId
Diederik van Arkel's avatar
Diederik van Arkel committed
708
		# ps = wind_deac ps
709 710
		= sw_close windId ps
	= sw_close windId ps
Diederik van Arkel's avatar
Diederik van Arkel committed
711 712 713

sw_maybe_close :: !Id !*(PSt *General) -> (Bool,*(PSt *General))
sw_maybe_close win ps
714 715
	# ({windId},ps) = getFBI ps
	| win == windId
Diederik van Arkel's avatar
Diederik van Arkel committed
716
		# ps = wind_deac ps
717
		= (True,sw_close windId ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
	= (False,ps)

:: SWO =
	{ fn	:: !String		// font name
	, fs	:: !Int			// font size
	, fc	:: !Colour		// foreground colour
	, bc	:: !Colour		// background colour
	, cur	:: !SWO_LS
	}

:: SWO_LS = TXT | BCK
instance == SWO_LS
where
	(==) TXT TXT = True
	(==) BCK BCK = True
	(==) _ _ = False

src_options :: !*(PSt *General) -> *PSt *General;
src_options ps
    # (dialogId,ps)	= openId ps
    # (okId,ps)		= openId ps
    # (cancelId,ps)	= openId ps
	# (rgbid,ps)	= openRGBId ps
	# (fcid,ps)		= openId ps
	# (bcid,ps)		= openId ps
	# (lsid,ps)		= openRId ps
	# (fontNames, ps) = accPIO (accScreenPicture getFontNames) ps
	# fontSizes		= [7,8,9,10,11,12]
	# (fbi,ps)		= getFBI ps
	# font			= fbi.src_font
	# fdef			= getFontDef font
	# inifn			= fdef.fName
	# inifs			= fdef.fSize
	# inifc			= fbi.src_forg
	# inibc			= fbi.src_back
	# inistate		= {fn = inifn, fs = inifs, fc = inifc, bc = inibc, cur = TXT}
    # controls		=
    	(LayoutControl 
		(	FontNameSizeControl inifn inifs fontNames fontSizes fontfun sizefun [ left ]
		:+:	RGBColourPickControl` rgbid inifc fcid (Just (Left, zero))
		) []
		:+: LayoutControl
		(	TextControl "Text:" [ left , ControlWidth (ContentWidth "Background: ")]
		:+: ColourBoxControl` (toRGBColour inifc) fcid (mfilter,mfun rgbid lsid fcid bcid TXT) Nothing
		:+: TextControl "Background:" [ left, ControlWidth (ContentWidth "Background: ")]
		:+: ColourBoxControl` (toRGBColour inibc) bcid (mfilter,mfun rgbid lsid fcid bcid BCK) Nothing
		) []
	   	:+:	ButtonControl "Ok"
  			[ ControlId okId
  			, ControlFunction (okFun rgbid lsid dialogId) 
  			, ControlPos (Right, zero)
  			, ControlWidth (ContentWidth "Cancel")
  			]
    	:+:	ButtonControl "Cancel"
  			[ ControlPos (LeftOfPrev, zero) 
  			, ControlFunction (cancelFun inistate dialogId)
  			, ControlId cancelId
  			] 
		:+: ButtonControl "Apply"
			[ ControlPos (LeftOfPrev,zero)
			, ControlFunction (applyFun rgbid lsid)
			]
  		:+: ButtonControl "Paste"
  			[ ControlPos (LeftOfPrev,zero)
  			, ControlFunction (pasteFun rgbid fcid bcid)
  			]
  		:+: ButtonControl "Copy"
  			[ ControlPos (LeftOfPrev,zero)
  			, ControlFunction (copyFun rgbid)
  			]

  		:+: Receiver lsid lsfun []
		)
	# dialog		=
		Dialog "Search Window..." controls 
  		[ WindowId		dialogId 
  		, WindowOk		okId
  		, WindowCancel	cancelId
  		, WindowClose	(cancelFun inistate dialogId)
		, WindowInit	(setBoxCol fcid bcid)
  		]
	# (_,ps) = openModalDialog inistate dialog ps
	= ps
where
	okFun rgbid lsid dialogId (ls,ps)
		# ps = getColourBoxColour rgbid cont ps
		= (ls,ps)
	where
		cont col ps
			| isNothing col
				= ps
			# col = fromJust col
			# (_,ps) = asyncSend lsid (cont2 col) ps
			= ps
		cont2 col (ls=:{cur},ps)
			# ls	= case cur of
						TXT -> {ls & fc = col}
						BCK -> {ls & bc = col}
			# (ls,ps)= apply (ls,ps)
			= (ls,closeWindow dialogId ps)
	cancelFun inistate dialogId (ls,ps)
		# ls		= inistate
		# (ls,ps)	= apply (ls,ps)
		= (ls,closeWindow dialogId ps)
	applyFun rgbid lsid (ls,ps)
		# ps = getColourBoxColour rgbid cont ps
		= (ls,ps)
	where
		cont col ps
			| isNothing col
				= ps
			# col = fromJust col
			# (_,ps) = asyncSend lsid (cont2 col) ps
			= ps
		cont2 col (ls=:{cur},ps)
			# ls	= case cur of
						TXT -> {ls & fc = col}
						BCK -> {ls & bc = col}
			= apply (ls,ps)
	toStringC :: !Colour -> String
	toStringC c = toString c
	copyFun rgbid (ls,ps)
		# ps = getColourBoxColour rgbid cont ps
		= (ls,ps)
	where
		cont col ps
			| isNothing col
				= ps
			# col = fromJust col
			# ps	= setClipboard [toClipboard (toString col)] ps
			= ps
	pasteFun rgbId fcid bcid (ls=:{cur},ps)
		// get clipboard
		// and put in active colour control
		# (its,ps)	= getClipboard ps
		| isEmpty its
			= (ls,ps)
		# its		= map fromClipboard its
		# its		= filter isJust its
		| isEmpty its
			= (ls,ps)
		# it		= fromJust (hd its)
		| it <> toStringC (fromString it)
			= (ls,ps)
		# col		= fromString it
		# ls		= case cur of
						TXT -> {ls & fc = col}
						BCK -> {ls & bc = col}
		# (ls,ps)	= setBoxCol fcid bcid (ls,ps)
		# ps		= setColourBoxColour` rgbId col ps
		= (ls,ps)
869
	setBoxCol fcid bcid (ls=:{cur,fc,bc},ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
870
		# (cId,col) = case cur of
871 872
						TXT	-> (fcid,fc)
						BCK	-> (bcid,bc)
Diederik van Arkel's avatar
Diederik van Arkel committed
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
		# ps = appPIO (SetColourBox` cId (toRGBColour col)) ps
		= (ls,ps)
	mfilter (MouseDown _ _ _) = True
	mfilter _ = False
	mfun rgbid lsid fcid bcid act _ (ls=:{cur,fc,bc},ps)
		| act == cur = (ls,ps)
		# ps = getColourBoxColour rgbid cont ps
		= (ls,ps)
	where
		cont col ps
			| isNothing col = ps
			# col = fromJust col
			# ps	= appPIO (case act of
								TXT	-> SetColourBox` fcid (case cur of
									TXT	-> toRGBColour col
									_	-> toRGBColour fc
									)
								_	-> SetColourBox fcid (case cur of
									TXT	-> toRGBColour col
									_	-> toRGBColour fc
									)
							) ps
			# ps	= appPIO (case act of
								BCK	-> SetColourBox` bcid (case cur of
									BCK	-> toRGBColour col
									_	-> toRGBColour bc
									)
								_	-> SetColourBox bcid (case cur of
									BCK	-> toRGBColour col
									_	-> toRGBColour bc
									)
							) ps
			# cId = case act of
						TXT -> fcid
						BCK -> bcid
			# col` = case act of
						TXT -> fc
						BCK -> bc
			# ps	= setColourBoxId rgbid cId ps
			# ps	= setColourBoxColour` rgbid col` ps
			# (_,ps) = asyncSend lsid (cont2 col) ps
			= ps
		cont2 col (ls=:{cur},ps)
			# ls	= case cur of
						TXT -> {ls & fc = col, cur = act}
						BCK -> {ls & bc = col, cur = act}
			= (ls,ps)
	lsfun f (ls,ps)
		= f (ls,ps)
	apply (ls=:{fc,bc,fn,fs},ps)
		# (fbi,ps)	= getFBI ps
		# lbId		= fbi.windlbId
		# (fnt,ps)	= accScreenPicture (safeOpenFixedFont {fName = fn, fSize = fs, fStyles = []}) ps
		# pen		= [PenColour fc, PenBack bc, PenFont fnt] 
		# ps		= setExtListBoxPen lbId pen ps
		# fbi		= {fbi & src_forg = fc, src_back = bc, src_font = fnt}
		# ps		= setFBI fbi ps
		= (ls,ps)
	fontfun name (ls,ps)
		# ls		= {SWO | ls & fn = name}
		= (ls,ps)
	sizefun size (ls,ps)
		# ls		= {SWO | ls & fs = size}
		= (ls,ps)

    left = ControlPos (Left, zero)

wind_next :: !Bool !*(PSt *General) -> *PSt *General
wind_next next ps		// Find Search result	=> next is forward, otherwise backwards
	# ({windlbId=lbId},ps) = getFBI ps
	= exec_next next lbId ps