1 ' nevrax_macros_98.dsm
\r
3 ' Copyright (C) 2000-2005 Nevrax. All rights reserved.
\r
5 ' The redistribution, use and modification in source or binary forms of
\r
6 ' this software is subject to the conditions set forth in the copyright
\r
7 ' document ("Copyright") included with this distribution.
\r
9 '------------------------------------------------------------------------------
\r
10 ' FILE DESCRIPTION: Nevrax Visual Studio macro file
\r
11 ' when Scripting.FileSystemObject cannot be instanciated
\r
12 ' $Id: nevrax_macros_98.dsm,v 1.21 2005/01/03 14:46:02 cado Exp $
\r
13 '------------------------------------------------------------------------------
\r
16 ' *** NevraxNewClass ***
\r
19 ' NevraxInsertFileHeader
\r
20 ' Utility Sub for NevraxNewClass()
\r
21 ' Author : Olivier Cado
\r
22 Sub NevraxInsertFileHeader( filename, productname )
\r
23 ActiveDocument.Selection.StartOfDocument
\r
24 ActiveDocument.Selection = _
\r
25 "/** \file " + filename + vbLf + _
\r
26 " * <File description>" + vbLf + _
\r
32 Function IsUpCase( str )
\r
33 IsUpcase = ( str = Ucase(str) )
\r
37 ' NevraxClassNameToFileName
\r
38 ' Utility Function for NevraxNewClass()
\r
39 ' 1/08/2000 : now analyses the first character
\r
40 ' Author : Olivier Cado
\r
41 Function NevraxClassNameToFileName( classname )
\r
43 first = left(classname,1)
\r
44 if ((first="C") or (first="E") or (first="I")) then
\r
45 if len(classname)>1 then
\r
46 if IsUpCase( mid(classname,2,1) ) then
\r
51 filename = lcase(mid(classname,beginningpos,1))
\r
52 for i = beginningpos+1 to len( classname )
\r
53 charact = mid(classname,i,1 )
\r
54 if IsUpCase( charact ) then
\r
55 if i+1 <= len( classname ) then
\r
56 if not IsUpCase( mid(classname,i+1,1) ) then
\r
57 filename = filename + "_"
\r
60 filename = filename + "_"
\r
63 filename = filename + lcase(charact)
\r
65 NevraxClassNameToFileName = filename
\r
70 ' Utility Function for NevraxNewClass()
\r
71 ' Author : Olivier Cado
\r
72 Function NevraxProjectOpen( projname )
\r
75 for i = 1 to Projects.Count
\r
76 if Projects(i).Name = projname then
\r
81 NevraxProjectOpen = found
\r
86 Dim CurrentDirectoryName
\r
87 Dim CurrentProgrammerName
\r
91 ' DESCRIPTION: Wizard for new class creation
\r
92 ' 1/08/2000 : added input boxes for directories
\r
93 ' 7/09/2000 : added programmer's name dialog and test for file existence (dirs & files)
\r
94 ' 18/09/2000 : namespace, programmer's name saved in a file, file added to the right project
\r
95 ' 12/10/2000 : modified output
\r
97 ' - CreateObject( Scripting.FileSystemObject ) doesn't work on Win 98, but on 2000
\r
98 ' - Projects.Item( string ) doesn't work. Using number instead
\r
99 ' Author : Olivier Cado
\r
100 Sub NevraxNewClass()
\r
102 ' ** Input class name and file name
\r
103 ClassName = InputBox( "Bienvenue dans l'assistant de création de classe." + vbLf + vbLf + _
\r
104 "Nom de la nouvelle classe :", "Nouvelle classe (1)" )
\r
105 if ClassName = "" then
\r
108 Filename = NevraxClassNameToFileName( ClassName )
\r
109 ' Warning: do not enter an existing filename, or MsDev will crash when attempting to save
\r
110 Filename = InputBox( "Nom de fichier sans l'extension:", "Nouvelle classe (2)", Filename )
\r
111 if Filename = "" then
\r
114 UniqueName = "NL_" + UCase( Filename ) + "_H"
\r
115 HFilename = Filename + ".h"
\r
116 CppFilename = Filename + ".cpp"
\r
118 ' ** Directories (NB: input boxes cannot be canceled in this part)
\r
119 SrcDirectory = "R:\code\nel\src"
\r
120 SrcDirectory = InputBox( "Répertoire racine (existant) des sources (.cpp)" + vbLf + "(entrer . pour un projet hors-NeL) :","Nouvelle classe (3)", SrcDirectory )
\r
121 if SrcDirectory <> "" then
\r
122 if right(SrcDirectory,1)<>"\" then
\r
123 SrcDirectory = SrcDirectory + "\"
\r
128 IncDirectory = "R:\code\nel\include\nel"
\r
129 IncDirectory = InputBox( "Répertoire racine (existant) des include (.h)" + vbLf + "(ex: R:\code\nel\include\nel pour NeL ; chaîne vide pour le même répertoire que les fichiers source ) :","Nouvelle classe (4)", IncDirectory )
\r
130 if IncDirectory = "" then
\r
131 IncDirectory = SrcDirectory
\r
133 if (right(IncDirectory,1)<>"\") then
\r
134 IncDirectory = IncDirectory + "\"
\r
137 CurrentDirectoryName = InputBox( "Nom du répertoire de travail (ex: misc)" + vbLf + "(existant dans " + SrcDirectory + _
\r
138 " et dans " + IncDirectory + ")" + vbLf + "Ce nom restera mémorisé" + vbLf + "(chaîne vide pour pour un projet hors-NeL).", "Nouvelle classe (5)", CurrentDirectoryName )
\r
139 if CurrentDirectoryName<>"" then
\r
140 CurrentDirectoryDir = CurrentDirectoryName + "\"
\r
141 Namesp = "NL" + ucase(CurrentDirectoryName)
\r
143 If InStr( IncDirectory, "nel" ) then
\r
145 ShortIncDir = "nel/" + CurrentDirectoryName + "/"
\r
147 ProdName = "NeL Network Services" ' not Distributed Toolkit Components System anymore
\r
150 FinalCPPdir = SrcDirectory + CurrentDirectoryDir
\r
151 FinalHdir = IncDirectory + CurrentDirectoryDir
\r
152 FinalCPPfilename = FinalCPPdir + CppFilename
\r
153 FinalHfilename = FinalHdir + HFilename
\r
155 ' ** Check for open project
\r
156 if CurrentDirectoryName="" then
\r
159 AddToProject = NevraxProjectOpen( CurrentDirectoryName )
\r
162 ' ** Programmer's name
\r
163 ConfigFileName = "R:\code\tool\visual_studio_macros\nevrax_new_class.cfg"
\r
164 if CurrentProgrammerName = "" then
\r
165 CurrentProgrammerName = "Fox Mulder"
\r
167 CurrentProgrammerName = InputBox( "Votre prénom et votre nom (qui restera mémorisé dans un fichier) :", "Nouvelle classe (6)", CurrentProgrammerName )
\r
168 if CurrentProgrammerName = "" then
\r
172 ' ** Input ancestor class name and file name
\r
173 NoAncestor = "NO BASE CLASS"
\r
174 AncClassName = InputBox( "Nom de la classe de base :", "Nouvelle classe (7)", NoAncestor )
\r
175 if AncClassName = "" then
\r
178 if AncClassName = NoAncestor then
\r
181 AncFilename = InputBox( "Nom de fichier (avec chemin) sans l'extension (ex: nel/misc/toto) :", "Nouvelle classe (8)" )
\r
182 if AncFileName = "" then
\r
185 AncHFilename = AncFilename + ".h"
\r
189 ' ** Now write .cpp
\r
190 Documents.Add( "Text" )
\r
191 NevraxInsertFileHeader CppFilename, ProdName
\r
192 ActiveDocument.Selection = vbLf + "#include """ + ShortIncDir + HFilename + """" + vbLf + vbLf + vbLf
\r
193 if ( CurrentDirectoryName<>"" ) then
\r
194 ActiveDocument.Selection = "namespace " + Namesp + " {" + vbLf + vbLf + vbLf
\r
196 ActiveDocument.Selection = "/*" + vbLf + _
\r
197 " * Constructor" + vbLf + _
\r
199 ClassName + "::" + ClassName + "()" + vbLf + _
\r
201 "}" + vbLf + vbLf + vbLf
\r
202 if ( CurrentDirectoryName<>"" ) then
\r
203 ActiveDocument.Selection = "} // " + Namesp + vbLf
\r
205 ' Warning: ActiveDocument.Save raises an "Unknown error" if the directory does not exist"
\r
206 ActiveDocument.Save( FinalCPPfilename )
\r
207 if AddToProject=0 then
\r
208 ActiveProject.AddFile( FinalCPPfilename )
\r
210 Projects(AddToProject).AddFile( FinalCPPfilename )
\r
214 Documents.Add( "Text" )
\r
215 NevraxInsertFileHeader HFilename, ProdName
\r
216 ActiveDocument.Selection = vbLf + "#ifndef " + UniqueName + vbLf + _
\r
217 "#define " + UniqueName + vbLf + vbLf
\r
218 ActiveDocument.Selection = "#include ""nel/misc/types_nl.h""" + vbLf
\r
219 if AncClassName <> "" then
\r
220 ActiveDocument.Selection = "#include """ + AncHFilename + """" + vbLf
\r
222 if ( CurrentDirectoryName<>"" ) then
\r
223 ActiveDocument.Selection = vbLf + vbLf + "namespace " + Namesp + " {" + vbLf
\r
225 ActiveDocument.Selection = vbLf + vbLf + _
\r
227 " * <Class description>" + vbLf + _
\r
228 " * \author " + CurrentProgrammerName + vbLf + _
\r
229 " * \author Nevrax France" + vbLf + _
\r
230 " * \date 2005" + vbLf + _
\r
232 "class " + ClassName
\r
233 if AncClassName <> "" then
\r
234 ActiveDocument.Selection = " : public " + AncClassName
\r
236 ActiveDocument.Selection = vbLf + _
\r
238 "public:" + vbLf + vbLf + _
\r
239 " /// Constructor" + vbLf + _
\r
240 " " + ClassName + "();" + vbLf + vbLf + _
\r
242 if ( CurrentDirectoryName<>"" ) then
\r
243 ActiveDocument.Selection = vbLf + "} // " + Namesp + vbLf + vbLf
\r
245 ActiveDocument.Selection = vbLf + "#endif // " + UniqueName + vbLf
\r
246 ActiveDocument.Selection = vbLf + "/* End of " + HFilename + " */" + vbLf
\r
247 ' Warning: ActiveDocument.Save raises an "Unknown error" if the directory does not exist"
\r
248 ActiveDocument.Save( FinalHfilename )
\r
249 if AddToProject=0 then
\r
250 ActiveProject.AddFile( FinalHfilename )
\r
252 Projects(AddToProject).AddFile( FinalHfilename )
\r
257 ' *** End of NevraxNewClass ***
\r
260 ' ** NevraxToggleHCPP
\r
263 ' DESCRIPTION: Opens the .cpp or .h file (toggles) for the current document.
\r
264 ' NOTE: Can be used in conjunction with NevraxNewClass (NevraxToggleHCPP uses the CurrentDirectoryName global variable)
\r
265 ' TIP: Bind this macro to Ctrl+<
\r
266 ' Author : Olivier Cado
\r
267 Sub NevraxToggleHCPP()
\r
269 ' ** Get filename extension and ensure it is .h or .cpp
\r
270 ActFilename = ActiveDocument.FullName
\r
271 pos = InstrRev( ActFilename, "." )
\r
272 if ( pos <> 0 ) then
\r
273 Ext = mid(ActFilename,pos)
\r
274 if (Ext<>".h" and Ext<>".cpp") then
\r
275 msgbox( "Error : Active document is not a .cpp or .h file" )
\r
282 ' ** Build the alternative filename
\r
284 if (InStr(ActFilename,"nel\src\")<>0) or (InStr(ActFilename,"nel\include\")<>0) then
\r
286 NewFilename = "R:\code\nel\src\"
\r
288 NewFilename = "R:\code\nel\include\nel\"
\r
290 ' Take the module name (the word between the two last backslashes)
\r
291 DirectoryName = left( ActFilename, InstrRev(ActFilename,"\")-1 )
\r
292 DirectoryName = mid( DirectoryName, InstrRev(DirectoryName, "\")+1 )
\r
293 ' Add the rest of the path
\r
294 NewFilename = NewFilename + DirectoryName + "\"
\r
295 ShortFilenameDot = mid( ActFilename, InstrRev(ActFilename,"\")+1 )
\r
297 ShortFilenameDot = ActFilename
\r
299 ShortFilenameDot = left( ShortFilenameDot, Instr(ShortFilenameDot,".") )
\r
305 NewFilename = NewFilename + ShortFilenameDot + Ext
\r
307 ' ** Open the alternative file
\r
308 Documents.Open( NewFilename )
\r