EdCommon.icl 2.69 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1
2
3
4
5
6
7
implementation module EdCommon

import EdMonad, EdText, EdSelection
import StrictList
import IdeState
import PmParse, PmPath
import StdMenuElement
8
import search, EdMovement, EdVisualCursor
Diederik van Arkel's avatar
Diederik van Arkel committed
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

:: *PLocState :== General

mChangeSelectionTo :: Selection -> EditMonad (PSt General) nothing
mChangeSelectionTo newSelection =
	getText											>>>= \text ->
	getMenuSelection								>>>= \mselold ->
	accEnv (getMenuIds)								>>>= \mIds ->
	let (frag,_)	= getTextFragment (orderSelection newSelection) text
		mselnew		= dofrag frag
		fragaction
			| changed mselold mselnew = (handlefrag mselnew mIds	>>> setMenuSelection mselnew)
			= skip
	in
	fragaction
where
	changed Nothing Nothing = False
	changed (Just strl) (Just strr) = strl <> strr
	changed _ _ = True
	
	dofrag (SCons (str) SNil) 
		| CleanModId str
			= Just str
		= Nothing
	dofrag _ = Nothing

	handlefrag (Just str) mIds
		=	appEnv (appPIO (setMenuElementTitles
				[(mIds.mn_odm,"Open "+++(MakeDefPathname str))
				,(mIds.mn_oim,"Open "+++(MakeImpPathname str))
				]))
	handlefrag _ mIds =
		appEnv (appPIO (setMenuElementTitles
			[(mIds.mn_odm,"Open Definition...")
			,(mIds.mn_oim,"Open Implementation...")
			]))

mRemoveSelection :: EditMonad (PSt General) nothing
mRemoveSelection =
	getMenuSelection								>>>= \mselold ->
	accEnv (getMenuIds)								>>>= \mIds ->
	let
		mselnew		= Nothing
		fragaction
			| changed mselold mselnew = (handlefrag mselnew mIds	>>> setMenuSelection mselnew)
			= skip
	in
	fragaction
where
	changed Nothing Nothing = False
	changed (Just strl) (Just strr) = strl <> strr
	changed _ _ = True
	
	handlefrag (Just str) mIds
		=	appEnv (appPIO (setMenuElementTitles
				[(mIds.mn_odm,"Open "+++(MakeDefPathname str))
				,(mIds.mn_oim,"Open "+++(MakeImpPathname str))
				]))
	handlefrag _ mIds =
		appEnv (appPIO (setMenuElementTitles
			[(mIds.mn_odm,"Open Definition...")
			,(mIds.mn_oim,"Open Implementation...")
			]))

// control click

controlDoubleClick :: !.Bool !.Position -> EditMonad (PSt General) nothing
controlDoubleClick shiftDown position =
	selectWordAt position						>>>= \selection ->
  	getPathName									>>>= \pathname ->
  	getText										>>>= \text ->
	let orderedSelection	= orderSelection selection
		(fragment, _)		= getTextFragment orderedSelection text
	    string				= case fragment of
	    						SCons string SNil	-> string
	    						_					-> ""
	in
	vChangeSelectionTo selection				>>>
	setSelectMode (SelectWords selection)		>>>
	accEnv getFBI								>>>= \fbi ->
	let
		fbi` = {fbi & kind = if shiftDown Implementation Definition, type = SearchImports}
	in
	// should make sure single line selection, here or in sr_find_def_imp...
	// now done above...
	appEnv ( sr_find_def_imp_sel False string pathname fbi` )