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

3
import StdArray, StdEnum, StdFunc, StdMisc, StdTuple, StdOrdList
Diederik van Arkel's avatar
Diederik van Arkel committed
4 5 6 7 8 9 10 11
import StdFileSelect,StdMenu,StdMenuReceiver,StdProcess, StdPStClass
import ExtNotice
import UtilIO

import PmDialogues
import PmParse
import PmPath

Diederik van Arkel's avatar
Diederik van Arkel committed
12
from EdKeyMapping import macKeyMapping, ReadKeyMapFile, KeyMapFileName
13 14
from finder import sr_find, sr_find_next, sr_find_sel, sr_rep_find, sr_goto_cursor,
				   sr_goto_line, sr_goto_selection
Diederik van Arkel's avatar
Diederik van Arkel committed
15 16
from edoptions import defaultFontAndTabs, optionsKeyMapping, editColours

17 18 19
from EdClient import :: EditAction, isEditWin, msgGetPathName,msgSelectAll,
					 emptySelection, sendToActiveWindow, msgGetSelection,
					 msgUndo,msgPaste,msgCopy,msgCut,msgClear,msgBalance,msgDetab
Diederik van Arkel's avatar
Diederik van Arkel committed
20 21 22 23 24 25 26 27
import prefix, tools

import IdeState
import ideoptions

import clipboard,typewin,idehelp,PmEnvironment,search
import errwin, messwin, projwin, edfiles
import projmen, filehist, ioutil, menubar
28
from PmDirCache import SearchDisk,FindHModule
Diederik van Arkel's avatar
Diederik van Arkel committed
29 30
import targetui
from PmCleanSystem import QuitCleanCompiler
31
import Platform,PlatformObjectIO, IdePlatform
Diederik van Arkel's avatar
Diederik van Arkel committed
32

33
import PmDriver
Diederik van Arkel's avatar
Diederik van Arkel committed
34
import StdSystem, StdClipboard
35

Diederik van Arkel's avatar
Diederik van Arkel committed
36
//trace_n m f :== trace_n` m f
Diederik van Arkel's avatar
Diederik van Arkel committed
37 38 39
trace_n _ f :== f

//--
Diederik van Arkel's avatar
Diederik van Arkel committed
40
import Directory
Diederik van Arkel's avatar
Diederik van Arkel committed
41

Diederik van Arkel's avatar
Diederik van Arkel committed
42 43 44 45 46 47
ensureDirectory pd_string env
	# ((ok,path),env)	= pd_StringToPath pd_string env
	| not ok
		= (ok,env)
	# (err_code, env) = createDirectory path env
	= (err_code==NoDirError || err_code==AlreadyExists, env)
Diederik van Arkel's avatar
Diederik van Arkel committed
48

Diederik van Arkel's avatar
Diederik van Arkel committed
49 50 51 52 53 54 55
Start :: !*World -> *World
Start world
	#	(stup,world)		= accFiles GetFullApplicationPath world
		(mEditId,world) 	= openId world
		(mEdUndoId,world)	= openId world
		(mMdEdOptId,world)	= openId world

Diederik van Arkel's avatar
Diederik van Arkel committed
56 57 58 59 60
	# (ok,world)			= ensureDirectory PrefsDir world
	| not ok
		= abort ("Missing directory for preferences:\n" +++ PrefsDir +++ "\nUnable to create it.\n")
	# (ok,world)			= ensureDirectory EnvsDir world
	| not ok
61
		= abort ("Missing directory for environments:\n" +++ EnvsDir +++ "\nUnable to create it.\n")
Diederik van Arkel's avatar
Diederik van Arkel committed
62 63
	# (ok,world)			= ensureDirectory TempDir world
	| not ok
64
		= abort ("Missing directory for temporary files:\n" +++ TempDir +++ "\nUnable to create it.\n")
65

66
	# prefspath				= MakeFullPathname PrefsDir	PrefsFileName
Diederik van Arkel's avatar
Diederik van Arkel committed
67 68
	#!	(prefs,world)		= openPrefs prefspath world

69
	# envspath				= MakeFullPathname EnvsDir EnvsFileName
Diederik van Arkel's avatar
Diederik van Arkel committed
70 71
	#!	(iniTargets,world)
							= openEnvironments stup envspath world
Diederik van Arkel's avatar
Diederik van Arkel committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

	#	(ffind,world)		= initFindBoxInfo prefs world
	#	(iniTwi,world)		= iniTypeWinInfo mEditId mEdUndoId ([]) prefs.typ_prefs world
// Win only?
	#	(iniCons,world)		= iniConsWinInfo mEditId mEdUndoId ([]) prefs.con_prefs world
	#!	(lbId,world)		= openExtListBoxId world
	#!	(mTargetId,world)	= openId world
		(eTargetId,world)	= openId world
		(mProjectId,world)	= openId world
		(mPrListId,world)	= openId world
	#!	(mPrRecId,world)	= openR2Id world
	#	(toolbar,world)		= setupToolBar prefs.show_toolbar world
	#	(keymap,world)		= setupKeyMap world
	#	emptyFindInfo		= { fi_find = [], fi_repl = [], fi_ic = False, fi_wa = True
							  , fi_bw = False, fi_mw = False, fi_re=False
							  }
88 89
	# (interact, force_update, proj_path, logfile, world)
							=	batchOptions world
90 91
	#!	(iniClip,pub,world)	= iniGeneral prefs stup interact logfile
								mTargetId eTargetId lbId
Diederik van Arkel's avatar
Diederik van Arkel committed
92
								(initEditorState keymap)
93 94
								emptyFindInfo ffind
								mEdUndoId mMdEdOptId
Diederik van Arkel's avatar
Diederik van Arkel committed
95 96 97 98
								iniTwi
// winOnly?
								iniCons
								iniTargets
99
								mProjectId mPrListId mPrRecId
Diederik van Arkel's avatar
Diederik van Arkel committed
100 101 102 103 104 105
								world
	#	patt				=	[ ProcessClose (Quit prefspath)
								, ProcessOpenFiles openfiles
//								, ProcessClipboardChanged clip_changed
								: toolbar
								] ++ PlatformProcessAttributes
106
	#!	(ids,world)			= openIds 7/*8*/ world
Diederik van Arkel's avatar
Diederik van Arkel committed
107 108 109 110 111
	#	(mFhMenId,world)	= openId world
		(mPhMenId,world)	= openId world
		pini				= ini envspath prefspath
								mEditId mEdUndoId iniClip iniTargets mTargetId
								eTargetId mProjectId mPrListId mPrRecId mFhMenId
112
								mPhMenId ids
113 114 115 116
	| interact
		= startIO MDI pub pini patt world
	// not interact
		= Batch stup force_update proj_path pub world
Diederik van Arkel's avatar
Diederik van Arkel committed
117 118
where
	setupKeyMap world
Diederik van Arkel's avatar
Diederik van Arkel committed
119 120
		# keymappath		= MakeFullPathname PrefsDir	KeyMapFileName
		# ((km,ok,_),world) = accFiles (ReadKeyMapFile keymappath) world
Diederik van Arkel's avatar
Diederik van Arkel committed
121 122 123 124 125 126 127
		# keymap			= if ok km macKeyMapping
		= (keymap,world)
	setupToolBar show world		// need to conditionalise for Mac...
		| not show
			= ([],world)
		# items					= []
		# (items,world)			= toolIconFun
128
									srchBM
Diederik van Arkel's avatar
Diederik van Arkel committed
129 130 131 132
									(Just "Search...")
									(sr_find_idi True)
									items world
		# (items,world)			= toolIconFun
133
									findBM
Diederik van Arkel's avatar
Diederik van Arkel committed
134 135 136 137
									(Just "Find...")
									sr_find
									items world
		# items					= if (isEmpty items) [] [ToolbarSeparator:items]
Diederik van Arkel's avatar
Diederik van Arkel committed
138
/*		# (items,world)			= toolIconFun
139
									execBM
Diederik van Arkel's avatar
Diederik van Arkel committed
140 141 142
									(Just "Run")
									pm_run
									items world
Diederik van Arkel's avatar
Diederik van Arkel committed
143
*/		# (items,world)			= toolIconFun
144
									updtBM
Diederik van Arkel's avatar
Diederik van Arkel committed
145 146 147 148
									(Just "Update")
									(pm_upto False)
									items world
		# (items,world)			= toolIconFun
149
									urunBM
Diederik van Arkel's avatar
Diederik van Arkel committed
150 151 152 153 154
									(Just "Update and Run")
									pm_exec
									items world
		# items					= if (isEmpty items) [] [ToolbarSeparator:items]
		# (items,world)			= toolIconFun
155
									prntBM
Diederik van Arkel's avatar
Diederik van Arkel committed
156 157 158 159 160
									(Just "Print...")
									ed_print
									items world
		# items					= if (isEmpty items) [] [ToolbarSeparator:items]
		# (items,world)			= toolIconFun
161
									saveBM
Diederik van Arkel's avatar
Diederik van Arkel committed
162 163 164 165
									(Just "Save")
									(ide_save NoModifiers)
									items world
		# (items,world)			= toolIconFun
166
									openBM
Diederik van Arkel's avatar
Diederik van Arkel committed
167 168 169 170
									(Just "Open...")
									(ed_open NoModifiers)
									items world
		# (items,world)			= toolIconFun
171
									newfBM
Diederik van Arkel's avatar
Diederik van Arkel committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185
									(Just "New...")
									(ed_new "*.icl")
									items world
		| isEmpty items
			= ([],world)
		# toolbar			=	[ ProcessToolbar items]
		= (toolbar,world)
	ini envspath prefspath mEditId mEdUndoId iniClip iniTargets mTargetId eTargetId
		mProjectId mPrListId mPrRecId mFhMenId mPhMenId
		[ mFileId
		, mSearchId
		, mCommandsId
		, mOptionsId, mGoodiesId
		, mPrNewId, mPrOpenId
186
//		, quitId
Diederik van Arkel's avatar
Diederik van Arkel committed
187
		: _
188 189
		] ps

190
		# ps			= PlatformInteractiveInit ps	// can modify Prefs! 
191
		# (prefs,ps)	= getPrefs ps
Diederik van Arkel's avatar
Diederik van Arkel committed
192 193 194
		# (fhRecId,ps)	= getFHI ps
		# (phRecId,ps)	= getPHI ps
		# (menuIds,ps)	= getMenuIds ps
195
		# (err,ps)		= openMenu Void (fileMenu prefspath menuIds mPrNewId mFileId mFhMenId mPhMenId /*quitId*/ fhRecId phRecId prefs) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
196 197 198
		| err <> NoError
			= abort "unable to open File menu"
		# (editRecId,ps)= getEditRecId ps
199
		# (err,ps)		= openMenu iniEditLS (editMenu prefs.altgr_workaround mEditId editRecId menuIds.mn_sav menuIds.mn_rev menuIds iniClip) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
200 201
		| err <> NoError
			= abort "unable to open Edit menu"
202
		# (err,ps)		= openMenu Void (searchMenu prefs.altgr_workaround mSearchId menuIds.searchIds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
		| err <> NoError
			= abort "unable to open Search menu"
		# (err,ps)		= openMenu Void (projectMenu mProjectId mPrOpenId mPrListId mPrRecId menuIds prefs) ps
		| err <> NoError
			= abort "unable to open Project menu"
		# (err,ps)		= openMenu Void (moduleMenu menuIds) ps
		| err <> NoError
			= abort "unable to open Module menu"
		# (err,ps)		= openMenu Void (optionsMenu mOptionsId) ps
		| err <> NoError
			= abort "unable to open Defaults menu"
		# (err,ps)		= openMenu Void (targetMenu envspath iniTargets mTargetId eTargetId getTargets setTargets) ps
		| err <> NoError
			= abort "unable to open Environment menu"
		# ps			= setProjectTarget (hd iniTargets).target_name ps
		# ps			= pm_open_project_window ps
		# (wId,ps)		= getPWW ps
		# ps			= initHelpMenu wId ps
		# (twi,ps)		= accPLoc getTypeWinInfo ps
		# twi			= TW_SetUpd ([menuIds.mn_cut,menuIds.mn_pst,menuIds.mn_clr:menuIds.mg_edt]) twi
		# ps			= appPLoc (setTypeWinInfo twi) ps
224
		# (files,ps)	= initPlatformCommandLineArguments ps
Diederik van Arkel's avatar
Diederik van Arkel committed
225
		# ps			= openfiles files ps
226
		# ps			= SetProcessIcon CleanIcon ps
Diederik van Arkel's avatar
Diederik van Arkel committed
227
		= installPlatformEventHandlers ps
228
	ini _ _ _ _ _ _ _ _ _ _ _ _ _ _ ps = abort "IDE.icl: ini called with insufficient id's"
Diederik van Arkel's avatar
Diederik van Arkel committed
229 230

fileMenu prefspath {mn_clo,mn_sva,mn_sav,mn_rev,mn_oth,mn_prt,mn_prs,mn_odm,mn_oim}
231
	mPrNewId mFileId mFhMenId mPhMenId /*quitId*/ fhRecId phRecId prefs
Diederik van Arkel's avatar
Diederik van Arkel committed
232 233 234 235 236 237 238 239 240 241 242

	# altgr_workaround	= prefs.altgr_workaround
	= Menu "&File"
		(	MenuItem	"&New File..."
				[ MenuShortKey 'N'
				, MenuModsFunction newffun
				]
		:+:	MenuItem "New Project..."
				[ MenuFunction (noLS pm_new)
				, MenuId mPrNewId
				]
243
		:+:	MenuItem "New Project Using Template..." [MenuFunction (noLS pm_new_project_using_template)]
Diederik van Arkel's avatar
Diederik van Arkel committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
		:+: MenuItem	"&Open..."
				[ MenuShortKey 'O'
				, MenuModsFunction (noLS1 ed_open)
				]
		:+:	MenuItem	"&Save"
				[ MenuShortKey 'S'
				, MenuModsFunction (noLS1 ide_save)
				, MenuId mn_sav
				]
		:+:	MenuItem	"Save As..."
				[ MenuModsFunction (noLS1 ide_save_as)
				, MenuId mn_sva
				]
		:+:	MenuItem	"Save All"
				[ MenuFunction (noLS ed_save_all)
				]
		:+:	MenuSeparator []
		:+:	MenuItem	"&Revert"
				[ MenuFunction (noLS ed_revert)
				, MenuId mn_rev
				, MenuSelectState Unable
				]
		:+: MenuItem	"&Close"
				[ MenuShortKey 'W'
				, MenuId mn_clo
				, MenuSelectState Able
				, MenuModsFunction (noLS1 ide_menu_close)
				]
		:+: MenuItem	"Close All"
				[ MenuFunction (noLS ide_close_all)
				]
		:+:	MenuSeparator []
		:+: MenuItem	"Open Other"
				[ MenuFunction (noLS ed_open_other)
				, MenuId mn_oth
				, MenuSelectState Unable
				: if altgr_workaround [] [MenuShortKey '/']
				]
		:+: MenuItem	"Open Definition..."
				[ MenuShortKey 'D'
				, MenuModsFunction (noLS1 (ed_open_sel False))
				, MenuId mn_odm
				]
		:+: MenuItem	"Open Implementation..."
				[ MenuShortKey 'I'
				, MenuModsFunction (noLS1 (ed_open_sel True))
				, MenuId mn_oim
				]
		:+:	MenuSeparator []
		:+: MenuItem	"Print Setup..."
				[ MenuId mn_prs
				, MenuFunction (noLS ed_print_setup)
				]
		:+:	MenuItem	"&Print..."
				[ MenuShortKey 'P'
				, MenuFunction (noLS ed_print)
				, MenuId mn_prt
				, MenuSelectState Unable
				]
		:+:	MenuItem	"Print All..."
				[ MenuFunction (noLS ed_print_all)
				]
		:+:	MenuSeparator []
Diederik van Arkel's avatar
Diederik van Arkel committed
307 308
		:+: FileHistMenu "Recent Files" 12 mFileId fhRecId mFhMenId (StrictListToList prefs.file_hist) fhopen
		:+: FileHistMenu "Recent Projects" 12 mFileId phRecId mPhMenId (StrictListToList prefs.proj_hist) phopen
309 310 311 312 313 314 315 316
		:+:	PlatformItem (PlatformDependant True (not onOSX))
			(	MenuSeparator []
			:+: MenuItem	"&Quit"
					[ MenuShortKey 'Q'
					, MenuFunction (noLS (Quit prefspath))
//					, MenuId (quitId)
					]
			)
Diederik van Arkel's avatar
Diederik van Arkel committed
317 318 319 320 321 322 323 324 325 326 327 328
		)
		[ MenuId (mFileId)
		]
where
	newffun mods (ls,ps)
		| not mods.shiftDown
			# ps	= case mods.altDown || mods.optionDown of
						True	-> ed_new "*.dcl" ps
						False	-> ed_new "*.icl" ps
			= (ls,ps)
		# ps		= pm_new ps
		= (ls,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
329 330 331 332 333 334 335 336 337 338
	fhopen pathName ps
		= ed_open_cont pathName cont ps
	where
		cont _ _ ps
			# (_,ps) = syncSend2 fhRecId pathName ps
			= ps
	phopen pathName ps
		= pm_open_path pathName ps
//		# (ok,ps)		= pm_switch pathName ps
//		= ps
339 340 341 342 343 344 345 346 347 348 349

:: PlatformItem m ls pst = PlatformItem Bool (m ls pst)

instance MenuElements (PlatformItem m)	| MenuElements m where
	menuElementToHandles (PlatformItem False _) pState
		= menuElementToHandles NilLS pState
	menuElementToHandles (PlatformItem True item) pState
		= menuElementToHandles item pState
	getMenuElementType _
		= "PlatformItem"

Diederik van Arkel's avatar
Diederik van Arkel committed
350 351
searchMenu altgr_workaround mSearchId {srchIds,findIds,gotoIds,nextIds}
	= Menu "&Search"
352
		(	MenuItem "&Find..."					[ MenuId (findIds!!0), MenuShortKey 'F', MenuModsFunction findfun ]
Diederik van Arkel's avatar
Diederik van Arkel committed
353
		:+:	MenuItem "Find &Next"				[ MenuId (findIds!!1), MenuShortKey 'G', MenuModsFunction (shiftfun sr_find_next) ]
354
		:+:	MenuItem "Find Selection"			[ MenuId (findIds!!2), /*MenuShortKey 'H',*/ MenuModsFunction (shiftfun sr_find_sel) ]
Diederik van Arkel's avatar
Diederik van Arkel committed
355 356 357 358 359 360 361
		:+:	MenuItem "Replace && Find Again"	[ MenuId (findIds!!3), MenuShortKey 'T', MenuModsFunction (shiftfun sr_rep_find) ]
		:+: MenuSeparator						[]
		:+:	MenuItem "&Search Identifier"
			[ MenuId (srchIds!!0)
			, MenuModsFunction (shiftfun` sr_find_idi) 
			: if altgr_workaround [] [MenuShortKey '=']
			]
362 363
		:+:	MenuItem "Search Definition"		[ MenuId (srchIds!!1), MenuShortKey 'L', MenuModsFunction defimpfun ]
		:+:	MenuItem "Search Implementation"	[ MenuId (srchIds!!2), /*MenuShortKey 'M',*/ MenuModsFunction (shiftfun` sr_find_imp) ]
Diederik van Arkel's avatar
Diederik van Arkel committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
		:+: MenuSeparator						[]
		:+: MenuItem "Goto Next Search &Result"
			[ MenuId (nextIds!!0)
			, MenuSelectState Unable
			, MenuModsFunction findresfun
			: if altgr_workaround [] [MenuShortKey ',']
			]
		:+:	MenuItem "Goto Next &Error"			[ MenuId (nextIds!!1), MenuShortKey 'E', MenuSelectState Unable, MenuModsFunction finderrfun ]
		:+:	MenuItem "Goto &Cursor"				[ MenuId (gotoIds!!0), MenuFunction (noLS sr_goto_cursor) ]
		:+:	MenuItem "Goto &Line..."			[ MenuId (gotoIds!!1), MenuFunction (noLS sr_goto_line) ]
		:+:	MenuItem "Goto Selection..."		[ MenuId (gotoIds!!2), MenuFunction (noLS sr_goto_selection) ]
		)
		[ MenuId (mSearchId)
		]
where
379 380 381
	findfun mods (ls,ps)
		# ps		= flip_dir mods.shiftDown ps
		| mods.altDown || mods.optionDown
382
			# ps	= sr_find_sel ps
383 384
			# ps	= flip_dir mods.shiftDown ps
			= (ls,ps)
385
		# ps		= sr_find ps
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
		# ps		= flip_dir mods.shiftDown ps
		= (ls,ps)
	where
		flip_dir flip ps
			| not flip
				= ps
			# (fi,ps)	= getFI ps
			# fi		= {fi & fi_bw = not fi.fi_bw}
			# ps		= setFI fi ps
			= ps
	defimpfun mods (ls,ps)
		| mods.altDown || mods.optionDown
			# ps	= sr_find_imp mods.shiftDown ps
			= (ls,ps)
		# ps		= sr_find_def mods.shiftDown ps
		= (ls,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 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
	shiftfun fun mods (ls,ps)
		| not mods.shiftDown
			# ps	= fun ps
			= (ls,ps)
		# (fi,ps)	= getFI ps
		# fi		= {fi & fi_bw = not fi.fi_bw}
		# ps		= setFI fi ps
		# ps		= fun ps
		# (fi,ps)	= getFI ps	// so that we do get the modifications in find info from find selection...
		# fi		= {fi & fi_bw = not fi.fi_bw}
		# ps		= setFI fi ps
		= (ls,ps)
	shiftfun` fun mods (ls,ps)
		| not mods.shiftDown
			# ps	= fun False ps
			= (ls,ps)
		# ps		= fun True ps
		= (ls,ps)
	finderrfun mods (ls,ps)
		# ps = sr_find_err (not mods.shiftDown) ps
		= (ls,ps)
	findresfun mods (ls,ps)
		# ps = wind_next (not mods.shiftDown) ps
		= (ls,ps)
			
projectMenu
	mProjectId mPrOpenId
	mPrListId mPrRecId
	{projIds} prefs
	= Menu "&Project"
	(
		MenuItem "Bring &Up To Date"
			[ MenuShortKey 'U'
			, MenuModsFunction (shiftfun (noLS (pm_upto False)) (noLS (pm_upto True)))
			, MenuId (projIds!!3)
			, MenuSelectState Unable
			]
	:+: MenuItem "Update and &Run"
			[ MenuShortKey 'R'
			, MenuModsFunction (shiftfun (noLS pm_exec) (noLS pm_run))
			, MenuId (projIds!!4)
			, MenuSelectState Unable
			]
	:+:	MenuItem "Run"
			[ MenuFunction (noLS pm_run)
			, MenuId (projIds!!5)
			, MenuSelectState Unable
			]
	:+: MenuSeparator []
	:+: MenuItem "&Set Main Module"
			[ MenuFunction (noLS pm_set)
			, MenuId (projIds!!10)
			, MenuSelectState Unable
			]
	:+: MenuItem "&Project Options..."
			[ MenuFunction (noLS projectOptions)
			, MenuId (projIds!!12)
			, MenuSelectState Unable
			]
461 462
	:+:	MenuItem "Project Directory Up" [MenuFunction (noLS project_directory_up)]
	:+:	MenuItem "Project Directory Down" [MenuFunction (noLS project_directory_down)]
463
	:+:	MenuItem "Save Project Template..." [MenuFunction (noLS pm_save_project_as_template)]
Diederik van Arkel's avatar
Diederik van Arkel committed
464 465 466
	:+:	MenuItem "Project Defaults..."
			[ MenuFunction (noLS projectDefaults)
			]
Diederik van Arkel's avatar
Diederik van Arkel committed
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
	:+: MenuSeparator []
	:+: MenuItem "Show &Heap Profile"
			[ MenuFunction (noLS shoheapfun)
			, MenuId (projIds!!6)
			, MenuSelectState Unable
			]
	:+: MenuItem "Show &Time Profile"
			[ MenuFunction (noLS shoprofun)
			, MenuId (projIds!!7)
			, MenuSelectState Unable
			]
	:+:	MenuItem "Theorem &Prover Project"
			[ MenuFunction (noLS provefun)
			, MenuId (projIds!!8)
			, MenuSelectState Unable
			]
Diederik van Arkel's avatar
Diederik van Arkel committed
483 484 485 486
//	:+: MenuItem "Theorem Prover Module"
//			[ MenuSelectState Unable
//			, MenuId (projIds!!9)
//			]
Diederik van Arkel's avatar
Diederik van Arkel committed
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
	:+: MenuSeparator []
	:+: ProjListMenu mProjectId mPrListId mPrRecId
	)
	[ MenuId mProjectId
	]
where
	shiftfun fun1 fun2 mods (ls,ps)
		| not mods.shiftDown
			= fun1 (ls,ps)
		= fun2 (ls,ps)

moduleMenu {md_cmp,md_chk,md_gen,md_cst,md_est} =
	Menu "&Module"
	(	MenuItem "&Compile"
			[ MenuShortKey 'K'
			, MenuFunction (noLS pm_compile)
			, MenuId md_cmp
			, MenuSelectState Unable
			]
	:+: MenuItem "Check Syntax"
			[ MenuShortKey 'Y'
			, MenuFunction (noLS pm_check)
			, MenuId md_chk
			, MenuSelectState Unable
			]
	:+: MenuItem "Generate &Assembly"
			[ MenuFunction (noLS pm_gen_asm)
			, MenuId md_gen
			, MenuSelectState Unable
			]
	:+: MenuSeparator []
	:+: MenuItem "Module Options..."
			[ MenuFunction (noLS pm_copt)
			, MenuId md_cst
			, MenuSelectState Unable
522
			, MenuShortKey 'J'						// 'Fix' ctrl-J -> newline bug.
Diederik van Arkel's avatar
Diederik van Arkel committed
523
			]
Diederik van Arkel's avatar
Diederik van Arkel committed
524 525 526
	:+:	MenuItem "Module Defaults..."
			[ MenuFunction (noLS pm_coprefs)
			]
Diederik van Arkel's avatar
Diederik van Arkel committed
527 528 529 530 531 532 533 534 535 536 537 538 539
/*
	:+:	MenuItem "Editor Settings..."
			[ MenuShortKey 'J'
			, MenuFunction (noLS optionsFontAndTabs) 
			, MenuId md_est
			, MenuSelectState Unable
			]
*/
	)
	[]

optionsMenu mOptionsId
	= Menu "&Defaults"
Diederik van Arkel's avatar
Diederik van Arkel committed
540
		(	SubMenu "Window Settings"
Diederik van Arkel's avatar
Diederik van Arkel committed
541 542 543 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 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
		(	MenuItem "Editor Colours..."
				[ MenuFunction (noLS editColours)
				]
		:+:	MenuItem "Editor Settings..."
				[ MenuFunction (noLS defaultFontAndTabs)
				]
		:+: MenuItem "Project Window..."
				[ MenuFunction (noLS projwinOptions)
				]
		:+: MenuItem "Types Window..."
				[ MenuFunction (noLS typewinColours)
				]
// winOnly?
		:+: MenuItem "Console Window..."
				[ MenuFunction (noLS conswinColours)
				]
// ...
		:+: MenuItem "Search Window..."
				[ MenuFunction (noLS src_options)
				]
		:+: MenuItem "Error Window..."
				[ MenuFunction (noLS err_options)
				]
		) []
		:+:	MenuItem "Key Mapping..."	[ MenuFunction (noLS optionsKeyMapping)]
		:+: MenuItem "IDE Options..."
			[ MenuFunction (noLS (ideOptionsDialog))
			]
		)
		[ MenuId mOptionsId
		]

//--

openfiles [] ps = ps
openfiles [file:files] ps
	# ps = ide_open file ps
	# ps = openfiles files ps
	= ps
where
	ide_open :: !String !(PSt *General) -> (PSt *General)
	ide_open file ps
		| IsPrjPathname file
			= pm_open_path file ps
		= ed_open_path file ps

//--

ed_open :: !Modifiers !(PSt *General) -> (PSt *General)
ed_open {shiftDown} ps
	// ask user for a file to open
	# (maybeString, ps) = selectInputFile ps
	| isNothing maybeString
		= ps
	# pathname		= fromJust maybeString
	// look if project; if so open as project
	| (IsPrjPathname pathname) && (not shiftDown)		// if shift-down always open as text
		= pm_open_path pathname ps
	= ed_open_path pathname ps

Quit :: !String !(PSt *General) -> (PSt *General)
Quit prefspath ps
Diederik van Arkel's avatar
Diederik van Arkel committed
603
	= ed_ask_save_all True False cont ps
Diederik van Arkel's avatar
Diederik van Arkel committed
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 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
where
	cont ps
		// save project
		# (prefs,ps)			= getPrefs ps
		# (twi,ps)				= accPLoc getTypeWinInfo ps
// winOnly
		# (cwi,ps)				= accPLoc getConsWinInfo ps

		# (errinf,ps)			= getErrInfo ps
		# err_prefs				= err_shut errinf

		# ((proj_pos,proj_siz),ps)
								= pm_get_projwin_possiz ps

		# (fbi,ps)				= getFBI ps
		# srcfdef				= getFontDef fbi.src_font
		# srcfname				= srcfdef.fName
		# srcfsize				= srcfdef.fSize

		# (fhId,ps)				= getFHI ps
		# ((rep,file_hist),ps)	= syncSend2 fhId "" ps
		# file_hist				= if ((rep == SendOk) && isJust file_hist) (fromJust file_hist) []

		# (phId,ps)				= getPHI ps
		# ((rep,proj_hist),ps)	= syncSend2 phId "" ps
		# proj_hist				= if ((rep == SendOk) && isJust proj_hist) (fromJust proj_hist) []
		# src_prefs				=
							 		{ src_pos		= fbi.src_offset
							 		, src_siz		= fbi.src_size
							 		, src_fname		= srcfname
							 		, src_fsize		= srcfsize
							 		, src_forc		= fbi.src_forg
							 		, src_bacc		= fbi.src_back
							 		}
		# prefs					=
							 		{ prefs
							 		& typ_prefs		= TW_GetInf twi
// winOnly
							 		, con_prefs		= getConPrefs cwi
									, err_prefs		= err_prefs
									, src_prefs		= src_prefs
							 		, prj_prefs.proj_pos		= proj_pos
							 		, prj_prefs.proj_siz		= proj_siz
									, proj_hist		= ListToStrictList proj_hist
									, file_hist		= ListToStrictList file_hist
							 		}
		# ps			= savePrefs prefspath prefs ps
		# ps			= pm_save ps
// macOnly?
653 654 655
		# (method,ps) = getCurrentMeth ps
		# use_compiler_process_ids = case method of CompileAsync _ -> True ; _ -> False
		# (compiler_process_ids,ps) = getCompilerProcessIds ps
656
		# ps = app_world_instead_of_ps (QuitCleanCompiler use_compiler_process_ids compiler_process_ids) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
657
		= closeProcess ps
658

Diederik van Arkel's avatar
Diederik van Arkel committed
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
//--- Window rotating

nextWindow :: *(PSt .a) -> *PSt .a
nextWindow ps
	# (stack,ps)	= accPIO getWindowsStack ps
	| isEmpty stack = ps
	# [h:t]			= stack
	| isEmpty t = ps
	# f				= last t
	# new			= hd t
	# ps			= stackWindow h f ps
	# ps			= setActiveWindow new ps
	= ps

prevWindow :: *(PSt .a) -> *PSt .a
prevWindow ps
	# (stack,ps)	= accPIO getWindowsStack ps
	| isEmpty stack = ps
	# [_:t]			= stack
	| isEmpty t = ps
	# f				= last t
	# ps			= setActiveWindow f ps
	= ps


//--- editor routines

ide_menu_close mods ps
	| mods.shiftDown
		= ide_close_all ps
	= ide_close ps
	
ide_close ps
	#	(mi,ps)		= accPIO getActiveWindow ps
	| isNothing mi
		= ps
	#	win			= fromJust mi
	#	(isEdit,ps) = isEditWin win ps
	| isEdit
		= ed_close win ps
	# (done,ps) = ew_maybe_close win ps
	| done
		= ps
	# (done,ps) = tw_maybe_close win ps
	| done
		= ps
	# (done,ps) = sw_maybe_close win ps
	| done
		= ps
	// still need to do message win...
	= ps

ide_close_all pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
712
	= ed_ask_save_all True True id pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
713 714 715 716 717 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

ide_save mods ps
	| mods.altDown || mods.optionDown
		= ide_save_as mods ps
	| mods.shiftDown
		= ed_save_all ps					// also save project?
	#	(mi,ps)		= accPIO getActiveWindow ps
	| isNothing mi
		= ps
	#	win			= fromJust mi
	#	(isEdit,ps) = isEditWin win ps
	| isEdit
		# (_,ps)	= ed_save win ps
		= ps
	# (isProj,ps)	= isProjWin win ps
	| isProj
		= pm_save ps
	= ps

ide_save_as mods ps
	#	(mi,ps)		= accPIO getActiveWindow ps
	| isNothing mi
		= ps
	#	win			= fromJust mi
	#	(isEdit,ps) = isEditWin win ps
	# (isProj,ps)	= isProjWin win ps
	| mods.shiftDown
		| isEdit
			= ed_save_copy_as ps
		| isProj
			= pm_save_copy_as ps
		= ps
	| isEdit
		= ed_save_as ps
	| isProj
		= pm_save_as ps
	= ps

//--

ed_open_sel openImp mods ps
	| mods.shiftDown
		= open_dlog ps
	# (wId,ps) = accPIO getActiveWindow ps
	| isNothing wId
		= open_dlog ps
	# wId = fromJust wId
	# (res,ps) = maybe_type_win_message wId msgGetSelection ps
	| isJust res
		#	(sel,_)			= fromJust res
763
		| sel == "" || not (is_h_module_name sel)
Diederik van Arkel's avatar
Diederik van Arkel committed
764
			= open_dlog ps
765
			= open_imp_or_def_module openImp sel ps
Diederik van Arkel's avatar
Diederik van Arkel committed
766 767 768 769
	#	(msel,ps)	= sendToActiveWindow msgGetSelection ps
	| isNothing msel
		= open_dlog ps
	#	(sel,_)			= fromJust msel
770
	| sel == "" || not (is_h_module_name sel)
Diederik van Arkel's avatar
Diederik van Arkel committed
771
		= open_dlog ps
772
		= open_imp_or_def_module openImp sel ps
Diederik van Arkel's avatar
Diederik van Arkel committed
773
where
774 775 776 777 778
	open_imp_or_def_module openImp sel ps
		| openImp
			= open_imp_module sel ps
			= open_def_module sel ps

Diederik van Arkel's avatar
Diederik van Arkel committed
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
	open_dlog pstate
		#	(dlogId,pstate)		= openId pstate
			(textId,pstate)		= openId pstate
			(okId,pstate)		= openId pstate
			(cancelId,pstate)	= openId pstate
			(_,pstate)			= openModalDialog Void (dialog dlogId textId okId cancelId) pstate
		= pstate
	dialog dlogId textId okId cancelId = Dialog "Open Module"
				(	EditControl (if openImp ".icl" ".dcl") (PixelWidth 200) 1
					[ ControlId textId
					, ControlKeyboard filterReturnKeys Able (\_ -> noLS (dfun True))
					]
				:+:	ButtonControl "Cancel"
					[ ControlPos (Left,zero)
					, ControlFunction (noLS (closeWindow dlogId))
					, ControlId cancelId
					, ControlWidth (ContentWidth "Cancel")
					]
				:+:	ButtonControl "OK"
					[ ControlFunction (noLS (dfun False))
					, ControlId okId
					, ControlWidth (ContentWidth "Cancel")
					]
				)
				[ WindowId dlogId
				, WindowOk okId
				, WindowCancel cancelId
				, WindowClose (noLS (closeWindow dlogId))
				]
	where
		dfun strip ps
			#	(wdef,ps)		= accPIO (getWindow dlogId) ps
			| isNothing wdef
				= closeWindow dlogId ps		// shouldn't be possible
			#	wdef			= fromJust wdef
				(ok,text)		= getControlText textId wdef
			| not ok || isNothing text
				= closeWindow dlogId ps		// shouldn't be possible
			#	text			= fromJust text
			#!	ps				= closeWindow dlogId ps
			#	text			= if strip
									{c \\ c <- [c \\ c <-: text | c <> '\n']}
									text
			= OpenModule text emptySelection ps

ed_open_other pstate
	#	(mpath,pstate) = sendToActiveWindow msgGetPathName pstate
	| isNothing mpath = pstate
	#	path			= fromJust mpath
	| IsDefPathname path
		#	path		= RemoveSuffix path
			path		= MakeImpPathname path
831 832 833 834 835
		#	(exists,pstate)	= accFiles (FExists path) pstate
		| exists
						= ed_open_path path pstate
		| CleanModId (RemovePath (RemoveSuffix path))
						= OpenModuleNoSel (RemovePath path) pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
836 837 838 839
		= pstate
	| IsImpPathname path
		#	path		= RemoveSuffix path
			path		= MakeDefPathname path
840 841 842 843 844
		#	(exists,pstate)	= accFiles (FExists path) pstate
		| exists
						= ed_open_path path pstate
		| CleanModId (RemovePath (RemoveSuffix path))
						= OpenModuleNoSel (RemovePath path) pstate
Diederik van Arkel's avatar
Diederik van Arkel committed
845 846 847
		= pstate
	= pstate

848 849
get_environment_and_project_paths :: !(*PSt General) -> (!List {#Char},!*PSt General)
get_environment_and_project_paths ps
850 851 852
	# (syspaths,ps)			= getCurrentPaths ps
	# (prj,ps)				= getProject ps
	# prjpaths				= PR_GetPaths prj
853 854 855 856 857 858 859
	= (AppendLists prjpaths syspaths, ps)

OpenModuleNoSel pathname ps
	# (srcpaths,ps)			= get_environment_and_project_paths ps
	# srcpaths				= if (IsABCPathname pathname)
								(Map MakeSystemPathname srcpaths)
								srcpaths
860
	# ((ok,fullpath),ps)	= accFiles (SearchDisk pathname srcpaths) ps
861
	| not ok
862
		= could_not_find_file_notice pathname ps
863 864 865
	# fullpath`				= GetLongPathName fullpath
	= ed_open_path fullpath` ps

866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
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
	
	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
888 889
OpenModule :: !.Modulename !.Selection !*(PSt General) -> *PSt General
OpenModule pathname sel ps
890 891 892 893 894 895 896 897 898 899
	# (srcpaths,ps) = get_environment_and_project_paths ps
	# srcpaths = if (IsABCPathname pathname)
					(Map MakeSystemPathname srcpaths)
					srcpaths
	# n=n_chars_of_file_ext pathname
	# ((ok,fullpath),ps)
		= if (n==0)
			(accFiles (SearchDisk pathname srcpaths) ps)
			(let (module_name,file_ext) = split_string n pathname
			 in accFiles (FindHModule module_name file_ext srcpaths) ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
900
	| not ok
901
		= could_not_find_file_notice pathname ps
Diederik van Arkel's avatar
Diederik van Arkel committed
902 903 904
	# fullpath`				= GetLongPathName fullpath
	= ed_open_path_sel fullpath` sel ps

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
open_def_module :: !Modulename !*(PSt General) -> *PSt General
open_def_module pathname ps
	# module_name = RemoveSuffix pathname
	# (srcpaths,ps) = get_environment_and_project_paths ps
	# ((ok,fullpath),ps)	= accFiles (FindHModule module_name ".dcl" srcpaths) ps
	| not ok
		= could_not_find_file_notice (module_name+++".dcl") ps
	# fullpath`				= GetLongPathName fullpath
	= ed_open_path_sel fullpath` emptySelection ps

open_imp_module :: !Modulename !*(PSt General) -> *PSt General
open_imp_module pathname ps
	# module_name = RemoveSuffix pathname
	# (srcpaths,ps) = get_environment_and_project_paths ps
	# ((ok,fullpath),ps) = accFiles (FindHModule module_name ".icl" srcpaths) ps
	| ok
		= open_file fullpath ps
	| not ok
		= could_not_find_file_notice (module_name+++".icl") ps
where
	open_file fullpath ps
		# fullpath`				= GetLongPathName fullpath
		= ed_open_path_sel fullpath` emptySelection ps

could_not_find_file_notice file_name ps
	= okNotice
		[ "Clean Project Manager"
		, "Could not find file:"
		, file_name
		] ps

Diederik van Arkel's avatar
Diederik van Arkel committed
936 937 938 939 940 941 942 943 944 945 946 947 948 949
//--- edit menu stuff

iniEditLS =
	{ zfun = ed_Undo
	, xfun = ed_Cut
	, cfun = ed_Copy
	, vfun = ed_Paste
	}
recfun MGet (ls,ps)		= (ls,(ls,ps))
recfun (MSet ss) (ls,ps)	= (ss,(ss,ps))

editMenu altgr_workaround mEditId editRecId mFileSaveId mFileRevertId {mn_und, mn_cut, mn_cpy, mn_pst, mn_clr, mg_edt, searchIds} iniClip = Menu "&Edit"
		(	MenuItem "&Undo"
				[ MenuShortKey 'Z'
950
				, MenuFunction (\(ls=:{zfun},ps)->(ls,zfun ps))
Diederik van Arkel's avatar
Diederik van Arkel committed
951 952 953 954 955
				, MenuSelectState Unable
				, MenuId mn_und
				]
		:+:	MenuItem "Cu&t"
				[ MenuShortKey 'X'
956
				, MenuFunction (\(ls=:{xfun},ps)->(ls,xfun ps))
Diederik van Arkel's avatar
Diederik van Arkel committed
957 958 959 960
				, MenuId mn_cut
				]
		:+:	MenuItem "&Copy"
				[ MenuShortKey 'C'
961
				, MenuFunction (\(ls=:{cfun},ps)->(ls,cfun ps))
Diederik van Arkel's avatar
Diederik van Arkel committed
962 963 964 965
				, MenuId mn_cpy
				]
		:+:	MenuItem "&Paste"
				[ MenuShortKey 'V'
966
				, MenuFunction (\(ls=:{vfun},ps)->(ls,vfun ps))
Diederik van Arkel's avatar
Diederik van Arkel committed
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
				, MenuId mn_pst
				]
		:+: Receiver2 editRecId recfun []
		:+:	MenuItem "Cl&ear"			[ MenuId mn_clr,	MenuFunction (noLS ed_Clear) ]
		:+: MenuSeparator []
		:+: MenuItem "Shift &Left"
			[ MenuId (mg_edt!!0)
			, MenuFunction (noLS shift_selection_left)
			: if altgr_workaround [] [MenuShortKey '[']
			]
		:+: MenuItem "Shift &Right"
			[ MenuId (mg_edt!!1)
			, MenuFunction (noLS shift_selection_right)
			: if altgr_workaround [] [MenuShortKey ']']
			]
		:+: MenuItem "&Balance"			[ MenuId (mg_edt!!2), MenuShortKey 'B', MenuFunction (noLS ed_Balance)]
		:+: MenuItem "Select &All"		[ MenuId (mg_edt!!3), MenuShortKey 'A', MenuFunction (noLS ed_SelectAll)]
		:+:	MenuItem "&Detab"			[ MenuId (mg_edt!!4), MenuFunction (noLS detabfun)]
985 986 987
		:+: MenuItem "Add Pre&fix"		[ MenuId (mg_edt!!5), MenuFunction (noLS add_prefix_selection)]
		:+: MenuItem "Remove Pref&ix"	[ MenuId (mg_edt!!6), MenuFunction (noLS rem_prefix_selection)]
		:+: MenuItem "Change Prefi&x..."	[ MenuId (mg_edt!!7), MenuFunction (noLS change_prefix_dlog)]
988 989
		:+: MenuItem "I&ncrement Integers"	[ MenuId (mg_edt!!8), MenuFunction (noLS increment_integers_in_selection)]
		:+: MenuItem "De&crement Integers"	[ MenuId (mg_edt!!9), MenuFunction (noLS decrement_integers_in_selection)]
Diederik van Arkel's avatar
Diederik van Arkel committed
990 991 992 993 994 995 996 997 998
		:+: MenuSeparator []
		:+: MenuItem "Next &Window"
			[ MenuModsFunction stackfun
			: if altgr_workaround [] [MenuShortKey '\\']
			]
		:+: clipMenuItems mFileSaveId mFileRevertId iniClip
// Wrap...
//		:+: MenuItem "Wrap1320" [MenuShortKey '`', MenuFunction (noLS wrap_preprocessor)]
// ...Wrap
999 1000 1001 1002
		:+: MenuItem "List Defi&nitions..." 
			[ MenuFunction (noLS popup_funs)
			: if altgr_workaround [] [MenuShortKey '`']
			]
Diederik van Arkel's avatar
Diederik van Arkel committed
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
		)
		[ MenuId (mEditId)
		]
where
	stackfun mods (ls,ps)
		| mods.shiftDown
			= (ls,prevWindow ps)
		= (ls,nextWindow ps)

	detabfun ps
		// Add 'Are you sure dialog' ?
		# (_,ps)			= sendToActiveWindow msgDetab ps
		= ps

//--
Diederik van Arkel's avatar
Diederik van Arkel committed
1018

Diederik van Arkel's avatar
Diederik van Arkel committed
1019 1020 1021 1022 1023 1024 1025 1026
ed_Undo ps
	# (_,ps)		= sendToActiveWindow msgUndo ps
	= mb_update_undoinfo ps

ed_Paste ps
	# (_,ps)		= sendToActiveWindow msgPaste ps
	= mb_update_undoinfo ps

Diederik van Arkel's avatar
Diederik van Arkel committed
1027 1028
ed_Copy ps
	# (res,ps)		= sendToActiveWindow msgCopy ps
Diederik van Arkel's avatar
Diederik van Arkel committed
1029
	| isNothing res
Diederik van Arkel's avatar
Diederik van Arkel committed
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
		# (isErrWin,ps)	= ew_is_active ps
		| isErrWin
			# (errinf,ps)	= getErrInfo ps
			# lbId			= errinf.infoId
			# ((ok,sel),ps) = getFilteredListBoxSelection lbId ps
			| not ok = ps
			# sel = map fst sel
		    # string = foldr (\l r->l+++"\n"+++r) "" sel
		    # newclip = [toClipboard string]
		    # ps = setClipboard newclip ps
			= ps
		# (win,ps)	= accPIO (getActiveWindow) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
1042
		| isNothing win
Diederik van Arkel's avatar
Diederik van Arkel committed
1043
			= ps
Diederik van Arkel's avatar
Diederik van Arkel committed
1044
		# win			= fromJust win
Diederik van Arkel's avatar
Diederik van Arkel committed
1045 1046 1047
		# (_,ps)	= maybe_type_win_message win msgCopy ps
		= mb_update_undoinfo ps
	= mb_update_undoinfo ps
Diederik van Arkel's avatar
Diederik van Arkel committed
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064

ed_Cut pstate
	# (res,pstate)		= sendToActiveWindow msgCut pstate
	| isNothing res
		# (win,pstate)	= accPIO (getActiveWindow) pstate
		| isNothing win
			= pstate
		# win			= fromJust win
		# (_,pstate)	= maybe_type_win_message win msgCopy pstate
		= mb_update_undoinfo pstate
	= mb_update_undoinfo pstate

ed_Clear ps
	# (_,ps)	= sendToActiveWindow msgClear ps
	= mb_update_undoinfo ps

ed_SelectAll ps
Diederik van Arkel's avatar
Diederik van Arkel committed
1065 1066 1067 1068 1069 1070 1071 1072
	# (win,ps)		= accPIO getActiveWindow ps
	# (isPrjWin,ps)	= case win of
						Just wId	-> isProjWin wId ps
						_			-> (False,ps)
	| isPrjWin
		# (lbId,ps)	= getPWI ps
		# ps		= setExtListBoxSelectionAll lbId ps
		= ps
Diederik van Arkel's avatar
Diederik van Arkel committed
1073 1074 1075 1076 1077 1078 1079
	# (_,ps)	= sendToActiveWindow msgSelectAll ps
	= mb_update_undoinfo ps

ed_Balance ps
	# (_,ps)	= sendToActiveWindow msgBalance ps
	= mb_update_undoinfo ps

1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
//== x-perimental
import EdLineText, StrictList, EdClient

popup_funs ps
	# (ret,ps)	= sendToActiveWindow gettext ps
	| isNothing ret = ps
	# text		= fromJust ret
	# text		= textToStrings text
	# text		= slToList text
	# text		= {t \\ t <- text}
	# (defs,ps)	= accFiles (FindDefinesInText text) ps
	# defs		= cleanup defs
	# defs		= purge_and_reverse [] defs
	# defs		= sortBy sort defs
	# (_,ps)	= openMenu Void (PopUpMenu (ListLS [toMenuItem d \\ d <- defs])) ps
	= ps
where
	cleanup defs
		= case defs of
					[]									-> []
					[DefFun "definition" _:defs]		-> cleanup defs
					[DefFun "implementation" _:defs]	-> cleanup defs
					[DefFun "module" _:defs]			-> cleanup defs
					[DefFun "system" _:defs]			-> cleanup defs
					[def:defs]							-> [def:cleanup defs]
	
	sort (DefType id1 _)	(DefType id2 _)		= id1 < id2
	sort (DefType _ _)		_					= True
	sort _					(DefType _ _)		= False
	sort (DefClass id1 _)	(DefClass id2 _)	= id1 < id2
	sort (DefClass _ _)		_					= True
	sort _					(DefClass _ _)		= False
	sort (DefInst cl1 id1 _)(DefInst cl2 id2 _) | cl1 == cl2	= id1 < id2
												= cl1 < cl2
	sort (DefInst _ _ _)	_					= True
	sort _					(DefInst _ _ _)		= False
1116 1117 1118 1119 1120 1121 1122
	sort (DefGeneric id1 _)	(DefGeneric id2 _)	= id1 < id2
	sort (DefGeneric _ _)		_				= True
	sort _					(DefGeneric _ _)	= False
	sort (DefDerive cl1 id1 _)(DefDerive cl2 id2 _) | cl1 == cl2	= id1 < id2
												= cl1 < cl2
	sort (DefDerive _ _ _)	_					= True
	sort _					(DefDerive _ _ _)	= False
1123 1124 1125 1126 1127 1128 1129 1130 1131
	sort (DefFun id1 _)		(DefFun id2 _)		= id1 < id2
	sort (DefFun _ _)		_					= True
	sort _					(DefFun _ _)		= False
	sort _					_					= abort "IDE:sort called with unknown constructor\n"

toMenuItem (DefFun id ln)		= MenuItem (id) [MenuFunction (menfun ln)]
toMenuItem (DefType id ln)		= MenuItem (":: "+++.id) [MenuFunction (menfun ln)]
toMenuItem (DefClass id ln)		= MenuItem ("class "+++.id) [MenuFunction (menfun ln)]
toMenuItem (DefInst cl id ln)	= MenuItem ("instance "+++.cl+++." "+++.id) [MenuFunction (menfun ln)]
1132 1133
toMenuItem (DefGeneric id ln)	= MenuItem ("generic "+++.id) [MenuFunction (menfun ln)]
toMenuItem (DefDerive cl id ln)	= MenuItem ("derive "+++.cl+++." "+++.id) [MenuFunction (menfun ln)]
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147

menfun ln (ls,ps)
	# (_,ps) = sendToActiveWindow (msgScrollToLine ln) ps
	= (ls,ps)
	
gettext =
	getText							>>>= \text ->
	return text

purge_and_reverse :: [Def] [Def] -> [Def]
purge_and_reverse acc []
	= acc
purge_and_reverse [] [h:t]
	= purge_and_reverse [h] t
1148 1149 1150 1151 1152
purge_and_reverse [a=:(DefFun an al):as] [d=:(DefFun dn dl):ds]
	| an==dn
		| al<dl
			= purge_and_reverse [a:as] ds
			= purge_and_reverse [d:as] ds
1153
		= purge_and_reverse [d,a:as] ds
1154 1155
purge_and_reverse [a:as] [d:ds]
	= purge_and_reverse [d,a:as] ds
1156

Diederik van Arkel's avatar
Diederik van Arkel committed
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
//==== 13/20 transition hack...
// Wrap...
/*
import EdVisualText,EdVisualCursor,EdSelection,StrictList,EdCommon

wrap_preprocessor ps
	# (_,ps)	= sendToActiveWindow wrap ps
	= mb_update_undoinfo ps

wrap =
	getText									>>>= \text ->
	getSelection							>>>= \selection ->
	getNeedSave							>>>= \needsave ->
	IF (isEmptySelection selection)
	THEN
	  ( skip )
	ELSE
	  (
		let orderedSelection	= orderSelection selection
			(ofragment, _)		= getTextFragment orderedSelection text
			fragment			= if (slLast ofragment == "") (slInit ofragment) ofragment
		    nfragment			= slAppend (slAppend (SCons "//1.3" fragment) (SCons "//3.1" (SCons "/*2.0" fragment))) (SCons "0.2*/" (SCons "" SNil))
			position			= orderedSelection.start
			newPosition			= newCursorPos position nfragment
		in
		vDoCursorSafe (
			vRemoveSelection					>>>
			mRemoveSelection										>>>
			vInsertText position nfragment		>>>
			vChangeSelectionTo {start=newPosition,end=newPosition}	>>>
			mChangeSelectionTo {start=newPosition,end=newPosition}	>>>
			vCenterCursor
			)								>>>
		setNeedSave True					>>>
		setUndoInfo
			{ state = Undo
			, action = " Wrap"
			, uninfo = PasteInfo nfragment ofragment selection position needsave
			}
	  )
where
	newCursorPos :: !Position !TextFragment -> Position
  	newCursorPos pos=:{col, row} SNil
  	  = pos
  	newCursorPos {col, row} (SCons string SNil)
  	  = {col = col + size string, row = row }
  	newCursorPos {col, row} strings
  	  = { col = size (slLast strings)
  	    , row = row + slLength strings - 1
  	    }
*/
// ...Wrap
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218

Batch startup force_update proj_path initialState world
	# ((proj,ok,err),world)		= accFiles (ReadProjectFile proj_path startup) world
	| not ok || err <> ""
		= wAbort ("--batch-build failed while opening project: "+++.err+++."\n") world
		= startIO NDI initialState (pinit force_update proj proj_path) [ProcessClose closeProcess] world

pinit force_update proj proj_path ps
	# ps = setInteract False ps
	# ps = setProject proj ps
1219
	# ps = setProjectFilePath proj_path ps
1220
	# ps = selectProjectTarget getTargets ps
1221 1222
	# ps = ew_safe_close ps							// close error window
	# ps = tw_safe_close ps							// close types window
1223 1224 1225
	# ps = BringProjectUptoDate force_update cleanup ps
	= ps
where
1226 1227
	cleanup exepath linked ok ps
		= abortLog (not ok) "" ps