forked from engor/Ted2Go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathsProvider.monkey2
136 lines (103 loc) · 3.15 KB
/
PathsProvider.monkey2
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
71
72
73
74
75
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
Namespace ted2go
Class PathsProvider
Const MX2_TMP:=".mx2"
Function GetActiveMainFilePath:String( checkCurrentDoc:Bool=True,showNoMainFileAlert:Bool=False )
If _customBuildProject
If showNoMainFileAlert Then ProjectView.CheckMainFilePath( _customBuildProject,True )
Return _customBuildProject.MainFilePath
Endif
Local lockedDoc:=docsManager().LockedDocument
Local path:=lockedDoc?.Path
If Not path
If checkCurrentDoc
path=docsManager().CurrentDocument?.Path
Endif
Local proj:=projView().ActiveProject
If proj
If showNoMainFileAlert Then ProjectView.CheckMainFilePath( proj,True )
If proj.MainFilePath
path=proj.MainFilePath
Endif
Endif
Endif
If Not CodeParsing.IsFileBuildable( path )
'If showNoMainFileAlert Then Alert( "Unsupported file format - "+ExtractExt( path )+"!~nFile must have .monkey2 extension to be buildable.","Build error" )
path=""
Endif
' Print "locked: "+_docsManager.LockedDocument?.Path
' Print "active: "+_projectView.ActiveProject?.MainFilePath
' Print "current: "+_docsManager.CurrentDocument?.Path
Return path
End
Function GetMainFileOfDocument:String( path:String )
'Print "GetFilePathToParse: "+path
' is it a module file?
'
Local modsDir:=Prefs.MonkeyRootPath+"modules/"
' excluding of tests dirs
'
If path.StartsWith( modsDir ) And path.Find( "/tests/")=-1
Local i1:=modsDir.Length
Local i2:=path.Find( "/",i1+1 )
If i2<>-1
Local modName:=path.Slice( i1,i2 )
' main file of a module
'
Return modsDir+modName+"/"+modName+".monkey2"
Endif
Else
' priority for locked file
'
Local lockedPath:=docsManager().LockedDocument?.Path
If lockedPath
If ExtractDir( path ).Contains( ExtractDir( lockedPath ) )
' will parse locked file coz 'path' is under 'locked' folder
Return lockedPath
Endif
Endif
' check as a part of project
'
Local proj:=ProjectView.FindProject( path )
If proj
Local showNote:=True
If proj.MainFilePath
Return proj.MainFilePath
Endif
If showNote Then ProjectView.CheckMainFilePath( proj,False )
Endif
Endif
' as is
Return path
End
Function SetCustomBuildProject( proj:Monkey2Project )
_customBuildProject=proj
End
Function GetGeninfoPath:String( filePath:String )
Return ExtractDir( filePath )+MX2_TMP+"/"+StripDir( StripExt( filePath ) )+".geninfo"
End
Function GetTempFilePathForParsing:String( srcPath:String )
Local dir:=ExtractDir( srcPath )+MX2_TMP+"/"
CreateDir( dir )
Local name:=StripDir( srcPath )
Return dir+name
End
Private
Global _customBuildProject:Monkey2Project
Function GetActiveProject:Monkey2Project()
If _customBuildProject Return _customBuildProject
Return projView().ActiveProject
End
Function projView:ProjectView()
Global _projView:ProjectView
If Not _projView Then _projView=Di.Resolve<ProjectView>()
Return _projView
End
Function docsManager:DocumentManager()
Global _docsManager:DocumentManager
If Not _docsManager
' dirty but better than MainWindow.DocsManager
_docsManager=Di.Resolve<DocumentManager>()
Endif
Return _docsManager
End
End