3 ' Copyright (C) 2000-2004 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 ' $Id: nevrax_macros_ryzom.dsm,v 1.6 2004/01/06 14:23:07 cado Exp $
\r
12 '------------------------------------------------------------------------------
\r
15 ' *** NevraxNewClass ***
\r
18 ' NevraxInsertFileHeader
\r
19 ' Utility Sub for NevraxNewClass()
\r
20 ' Author : Olivier Cado
\r
21 Sub NevraxInsertFileHeader( filename, productname )
\r
22 ActiveDocument.Selection.StartOfDocument
\r
23 ActiveDocument.Selection = _
\r
24 "/** \file " + filename + vbLf + _
\r
29 Function IsUpCase( str )
\r
30 IsUpcase = ( str = Ucase(str) )
\r
34 ' NevraxClassNameToFileName
\r
35 ' Utility Function for NevraxNewClass()
\r
36 ' 1/08/2000 : now analyses the first character
\r
37 ' Author : Olivier Cado
\r
38 Function NevraxClassNameToFileName( classname )
\r
40 first = left(classname,1)
\r
41 if ((first="C") or (first="E") or (first="I")) then
\r
42 if len(classname)>1 then
\r
43 if IsUpCase( mid(classname,2,1) ) then
\r
48 filename = lcase(mid(classname,beginningpos,1))
\r
49 for i = beginningpos+1 to len( classname )
\r
50 charact = mid(classname,i,1 )
\r
51 if IsUpCase( charact ) then
\r
52 if i+1 <= len( classname ) then
\r
53 if not IsUpCase( mid(classname,i+1,1) ) then
\r
54 filename = filename + "_"
\r
57 filename = filename + "_"
\r
60 filename = filename + lcase(charact)
\r
62 NevraxClassNameToFileName = filename
\r
67 ' Utility Function for NevraxNewClass()
\r
68 ' Author : Olivier Cado
\r
69 Function NevraxProjectOpen( projname )
\r
72 for i = 1 to Projects.Count
\r
73 if Projects(i).Name = projname then
\r
78 NevraxProjectOpen = found
\r
83 Dim CurrentDirectoryName
\r
84 Dim CurrentProgrammerName
\r
88 ' DESCRIPTION: Wizard for new class creation
\r
89 ' 1/08/2000 : added input boxes for directories
\r
90 ' 7/09/2000 : added programmer's name dialog and test for file existence (dirs & files)
\r
91 ' 18/09/2000 : namespace, programmer's name saved in a file, file added to the right project
\r
92 ' 12/10/2000 : modified output
\r
94 ' - CreateObject( Scripting.FileSystemObject ) doesn't work on Win 98, but on 2000
\r
95 ' - Projects.Item( string ) doesn't work. Using number instead
\r
96 ' Author : Olivier Cado
\r
97 Sub NevraxNewClass()
\r
99 ' ** Input class name and file name
\r
100 ClassName = InputBox( "Bienvenue dans l'assistant de création de classe." + vbLf + vbLf + _
\r
101 "Nom de la nouvelle classe :", "Nouvelle classe (1)" )
\r
102 if ClassName = "" then
\r
105 Filename = NevraxClassNameToFileName( ClassName )
\r
106 ' Warning: do not enter an existing filename, or MsDev will crash when attempting to save
\r
107 Filename = InputBox( "Nom de fichier sans l'extension:", "Nouvelle classe (2)", Filename )
\r
108 if Filename = "" then
\r
111 UniqueName = "NL_" + UCase( Filename ) + "_H"
\r
112 HFilename = Filename + ".h"
\r
113 CppFilename = Filename + ".cpp"
\r
115 ' Load configuration
\r
117 set fso = CreateObject("Scripting.FileSystemObject")
\r
118 ConfigFileName = "R:\code\tool\visual_studio_macros\nevrax_new_class.cfg"
\r
119 if fso.FileExists( ConfigFileName ) then
\r
120 set f = fso.OpenTextFile( ConfigFileName, 1 ) ' 1 = ForReading
\r
121 'if CurrentProgrammerName = "" then
\r
122 CurrentProgrammerName = f.ReadLine
\r
124 ' CurrentProgrammerName = "Richard Stallman"
\r
126 SrcDirectory = f.ReadLine
\r
127 IncDirectory = f.ReadLine
\r
131 ' ** Directories (NB: input boxes cannot be canceled in this part)
\r
132 SrcDirectory = InputBox( "Répertoire racine (existant) des sources (.cpp)" + vbLf + "(ex: R:\code\nel\src pour NeL) :","Nouvelle classe (3)", SrcDirectory )
\r
133 if SrcDirectory <> "" then
\r
134 if right(SrcDirectory,1)<>"\" then
\r
135 SrcDirectory = SrcDirectory + "\"
\r
140 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
141 if IncDirectory = "" then
\r
142 IncDirectory = SrcDirectory
\r
144 if (right(IncDirectory,1)<>"\") then
\r
145 IncDirectory = IncDirectory + "\"
\r
148 CurrentDirectoryName = InputBox( "Nom du répertoire de travail (ex: misc)" + vbLf + "(existant dans " + SrcDirectory + _
\r
149 " et dans " + IncDirectory + ")" + vbLf + "Ce nom restera mémorisé" + vbLf + "(chaîne vide pour pour un projet hors-NeL).", "Nouvelle classe (5)", CurrentDirectoryName )
\r
150 if CurrentDirectoryName<>"" then
\r
151 CurrentDirectoryDir = CurrentDirectoryName + "\"
\r
152 Namesp = "NL" + ucase(CurrentDirectoryName)
\r
154 If InStr( IncDirectory, "nel" ) then
\r
156 ShortIncDir = "nel/" + CurrentDirectoryName + "/"
\r
158 ProdName = "RYZOM" ' HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE
\r
161 ' ** Check for file existence
\r
162 FinalCPPdir = SrcDirectory + CurrentDirectoryDir
\r
163 FinalHdir = IncDirectory + CurrentDirectoryDir
\r
164 if not fso.FolderExists( FinalHdir ) then
\r
165 MsgBox "Erreur : le répertoire " + FinalHdir + " n'existe pas !", vbExclamation
\r
168 if not fso.FolderExists( FinalCPPdir ) then
\r
169 MsgBox "Erreur : le répertoire " + FinalCPPdir + " n'existe pas !", vbExclamation
\r
172 FinalCPPfilename = FinalCPPdir + CppFilename
\r
173 FinalHfilename = FinalHdir + HFilename
\r
174 if fso.FileExists( FinalHfilename ) then
\r
175 MsgBox "Erreur : le fichier " + FinalHfilename + " existe déjà !", vbExclamation
\r
178 if fso.FileExists( FinalCPPfilename ) then
\r
179 MsgBox "Erreur : le fichier " + FinalCPPfilename + " existe déjà !", vbExclamation
\r
183 ' ** Check for open project
\r
184 if CurrentDirectoryName="" then
\r
187 AddToProject = NevraxProjectOpen( CurrentDirectoryName )
\r
190 ' ** Programmer's name
\r
191 CurrentProgrammerName = InputBox( "Votre prénom et votre nom (qui restera mémorisé dans un fichier) :", "Nouvelle classe (6)", CurrentProgrammerName )
\r
192 if CurrentProgrammerName = "" then
\r
196 ' Save configuration
\r
197 set f = fso.OpenTextFile( ConfigFileName, 2, true ) ' 2 = ForWriting
\r
198 f.WriteLine CurrentProgrammerName
\r
199 f.WriteLine SrcDirectory
\r
200 f.WriteLine IncDirectory
\r
203 ' ** Input ancestor class name and file name
\r
204 NoAncestor = "NO BASE CLASS"
\r
205 AncClassName = InputBox( "Nom de la classe de base :", "Nouvelle classe (7)", NoAncestor )
\r
206 if AncClassName = "" then
\r
209 if AncClassName = NoAncestor then
\r
212 AncFilename = InputBox( "Nom de fichier (avec chemin) sans l'extension (ex: nel/misc/toto) :", "Nouvelle classe (8)" )
\r
213 if AncFileName = "" then
\r
216 AncHFilename = AncFilename + ".h"
\r
217 'if not fso.FileExists( AncHFilename ) then
\r
218 ' MsgBox "Attention : le fichier " + AncHFilename + " n'existe pas encore.", vbInformation
\r
223 ' ** Now write .cpp
\r
224 Documents.Add( "Text" )
\r
225 NevraxInsertFileHeader CppFilename, ProdName
\r
226 ActiveDocument.Selection = vbLf + "#include """ + ShortIncDir + HFilename + """" + vbLf + vbLf + vbLf
\r
227 if ( CurrentDirectoryName<>"" ) then
\r
228 ActiveDocument.Selection = "namespace " + Namesp + " {" + vbLf + vbLf + vbLf
\r
230 ActiveDocument.Selection = "/*" + vbLf + _
\r
231 " * Constructor" + vbLf + _
\r
233 ClassName + "::" + ClassName + "()" + vbLf + _
\r
235 "}" + vbLf + vbLf + vbLf
\r
236 if ( CurrentDirectoryName<>"" ) then
\r
237 ActiveDocument.Selection = "} // " + Namesp + vbLf
\r
239 ' Warning: ActiveDocument.Save raises an "Unknown error" if the directory does not exist"
\r
240 ActiveDocument.Save( FinalCPPfilename )
\r
241 if AddToProject=0 then
\r
242 ActiveProject.AddFile( FinalCPPfilename )
\r
244 Projects(AddToProject).AddFile( FinalCPPfilename )
\r
248 Documents.Add( "Text" )
\r
249 NevraxInsertFileHeader HFilename, ProdName
\r
250 ActiveDocument.Selection = vbLf + "#ifndef " + UniqueName + vbLf + _
\r
251 "#define " + UniqueName + vbLf + vbLf
\r
252 ActiveDocument.Selection = "#include ""nel/misc/types_nl.h""" + vbLf
\r
253 if AncClassName <> "" then
\r
254 ActiveDocument.Selection = "#include """ + AncHFilename + """" + vbLf
\r
256 if ( CurrentDirectoryName<>"" ) then
\r
257 ActiveDocument.Selection = vbLf + vbLf + "namespace " + Namesp + " {" + vbLf
\r
259 ActiveDocument.Selection = vbLf + vbLf + _
\r
261 " * <Class description>" + vbLf + _
\r
262 " * \author " + CurrentProgrammerName + vbLf + _
\r
263 " * \author Nevrax France" + vbLf + _
\r
264 " * \date 2004" + vbLf + _
\r
266 "class " + ClassName
\r
267 if AncClassName <> "" then
\r
268 ActiveDocument.Selection = " : public " + AncClassName
\r
270 ActiveDocument.Selection = vbLf + _
\r
272 "public:" + vbLf + vbLf + _
\r
273 " /// Constructor" + vbLf + _
\r
274 " " + ClassName + "();" + vbLf + vbLf + _
\r
276 if ( CurrentDirectoryName<>"" ) then
\r
277 ActiveDocument.Selection = vbLf + "} // " + Namesp + vbLf + vbLf
\r
279 ActiveDocument.Selection = vbLf + "#endif // " + UniqueName + vbLf
\r
280 ActiveDocument.Selection = vbLf + "/* End of " + HFilename + " */" + vbLf
\r
281 ' Warning: ActiveDocument.Save raises an "Unknown error" if the directory does not exist"
\r
282 ActiveDocument.Save( FinalHfilename )
\r
283 if AddToProject=0 then
\r
284 ActiveProject.AddFile( FinalHfilename )
\r
286 Projects(AddToProject).AddFile( FinalHfilename )
\r
291 ' *** End of NevraxNewClass ***
\r
294 ' ** NevraxToggleHCPP
\r
297 ' DESCRIPTION: Opens the .cpp or .h file (toggles) for the current document.
\r
298 ' TIP: Bind this macro to Ctrl+<
\r
299 ' Last modification : 22/05/2001
\r
300 ' Author : Olivier Cado
\r
301 Sub NevraxToggleHCPP()
\r
303 ' ** Get filename extension and ensure it is .h or .cpp
\r
304 ActFilename = ActiveDocument.FullName
\r
305 pos = InstrRev( ActFilename, "." )
\r
306 if ( pos <> 0 ) then
\r
307 Ext = mid(ActFilename,pos)
\r
308 if (Ext<>".h" and Ext<>".cpp") then
\r
309 msgbox( "Error : Active document is not a .cpp or .h file" )
\r
316 ' ** Build the alternative filename
\r
318 ' The module name is the word between the two last backslashes of the path\filename
\r
319 ModuleDir = left( ActFilename, InstrRev(ActFilename,"\")-1 )
\r
320 ModuleDir = mid( ModuleDir, InstrRev(ModuleDir, "\")+1 ) + "\"
\r
323 if ( Ext = ".cpp" ) then
\r
324 SearchDirs(1) = "R:\code\nel\include\nel\" + ModuleDir
\r
325 SearchDirs(2) = "R:\code\nel\include_private\nel\" + ModuleDir
\r
326 SearchDirs(3) = left( ActFilename, InstrRev(ActFilename,"\") ) 'dir of the current file
\r
330 SearchDirs(1) = "R:\code\nel\src\" + ModuleDir
\r
331 SearchDirs(2) = left( ActFilename, InstrRev(ActFilename,"\") ) 'dir of the current file
\r
338 while (DirIndex <= NbDirs) and (FileFound = False)
\r
339 ' NeL directory scheme
\r
340 if InStr(ActFilename,"nel")<>0 then
\r
341 ' Add the search path and the filename
\r
342 NewFilename = SearchDirs(DirIndex)
\r
343 ShortFilenameDot = mid( ActFilename, InstrRev(ActFilename,"\")+1 )
\r
345 ' The complete filename
\r
346 ShortFilenameDot = ActFilename
\r
348 ShortFilenameDot = left( ShortFilenameDot, Instr(ShortFilenameDot,".") )
\r
349 NewFilename = NewFilename + ShortFilenameDot + Ext
\r
351 ' ** Open the alternative file
\r
353 set fso = CreateObject("Scripting.FileSystemObject")
\r
354 if fso.FileExists( NewFilename ) then
\r
355 Documents.Open( NewFilename )
\r
358 Dirs = Dirs + SearchDirs(DirIndex) + vbLf
\r
359 DirIndex = DirIndex + 1
\r
362 if FileFound <> True then
\r
363 MsgBox "There is no file " + ShortFilenameDot + Ext + " in " + vbLf + Dirs
\r
369 ' ** NevraxToggleHCPP
\r
372 ' NevraxFormatMethodHeader
\r
373 ' DESCRIPTION: Edit a Doxygen .h style method header for a .cpp file.
\r
374 ' The caret must be a the beginning of the first line of the header.
\r
375 ' Author : Olivier Cado
\r
376 Sub NevraxFormatMethodHeader()
\r
377 ActiveDocument.Selection.Delete
\r
378 ActiveDocument.Selection.CharRight
\r
379 ActiveDocument.Selection.Delete 2
\r
380 ActiveDocument.Selection = "*" + vbLf + " *"
\r
381 ActiveDocument.Selection.EndOfLine
\r
382 ActiveDocument.Selection = vbLf + " */"
\r
383 ActiveDocument.Selection.LineDown
\r
384 ActiveDocument.Selection.Delete
\r
385 ActiveDocument.Selection.EndOfLine
\r
386 ActiveDocument.Selection.Backspace
\r
387 ActiveDocument.Selection = vbLf + "{" + vbLf + vbLf + "}" + vbLf
\r
388 ActiveDocument.Selection.LineDown dsMove,2
\r