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 ' $Id: nevrax_macros.dsm,v 1.22 2005/01/03 14:46:02 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
30 Function IsUpCase( str )
\r
31 IsUpcase = ( str = Ucase(str) )
\r
35 ' NevraxClassNameToFileName
\r
36 ' Utility Function for NevraxNewClass()
\r
37 ' 1/08/2000 : now analyses the first character
\r
38 ' Author : Olivier Cado
\r
39 Function NevraxClassNameToFileName( classname )
\r
41 first = left(classname,1)
\r
42 if ((first="C") or (first="E") or (first="I")) then
\r
43 if len(classname)>1 then
\r
44 if IsUpCase( mid(classname,2,1) ) then
\r
49 filename = lcase(mid(classname,beginningpos,1))
\r
50 for i = beginningpos+1 to len( classname )
\r
51 charact = mid(classname,i,1 )
\r
52 if IsUpCase( charact ) then
\r
53 if i+1 <= len( classname ) then
\r
54 if not IsUpCase( mid(classname,i+1,1) ) then
\r
55 filename = filename + "_"
\r
58 filename = filename + "_"
\r
61 filename = filename + lcase(charact)
\r
63 NevraxClassNameToFileName = filename
\r
68 ' Utility Function for NevraxNewClass()
\r
69 ' Author : Olivier Cado
\r
70 Function NevraxProjectOpen( projname )
\r
73 for i = 1 to Projects.Count
\r
74 if Projects(i).Name = projname then
\r
79 NevraxProjectOpen = found
\r
84 Dim CurrentDirectoryName
\r
85 Dim CurrentProgrammerName
\r
89 ' DESCRIPTION: Wizard for new class creation
\r
90 ' 1/08/2000 : added input boxes for directories
\r
91 ' 7/09/2000 : added programmer's name dialog and test for file existence (dirs & files)
\r
92 ' 18/09/2000 : namespace, programmer's name saved in a file, file added to the right project
\r
93 ' 12/10/2000 : modified output
\r
95 ' - CreateObject( Scripting.FileSystemObject ) doesn't work on Win 98, but on 2000
\r
96 ' - Projects.Item( string ) doesn't work. Using number instead
\r
97 ' Author : Olivier Cado
\r
98 Sub NevraxNewClass()
\r
100 ' ** Input class name and file name
\r
101 ClassName = InputBox( "Bienvenue dans l'assistant de création de classe." + vbLf + vbLf + _
\r
102 "Nom de la nouvelle classe :", "Nouvelle classe (1)" )
\r
103 if ClassName = "" then
\r
106 Filename = NevraxClassNameToFileName( ClassName )
\r
107 ' Warning: do not enter an existing filename, or MsDev will crash when attempting to save
\r
108 Filename = InputBox( "Nom de fichier sans l'extension:", "Nouvelle classe (2)", Filename )
\r
109 if Filename = "" then
\r
112 UniqueName = "NL_" + UCase( Filename ) + "_H"
\r
113 HFilename = Filename + ".h"
\r
114 CppFilename = Filename + ".cpp"
\r
116 ' Load configuration
\r
118 set fso = CreateObject("Scripting.FileSystemObject")
\r
119 ConfigFileName = "R:\code\tool\visual_studio_macros\nevrax_new_class.cfg"
\r
120 if fso.FileExists( ConfigFileName ) then
\r
121 set f = fso.OpenTextFile( ConfigFileName, 1 ) ' 1 = ForReading
\r
122 'if CurrentProgrammerName = "" then
\r
123 CurrentProgrammerName = f.ReadLine
\r
125 ' CurrentProgrammerName = "Richard Stallman"
\r
127 SrcDirectory = f.ReadLine
\r
128 IncDirectory = f.ReadLine
\r
132 ' ** Directories (NB: input boxes cannot be canceled in this part)
\r
133 SrcDirectory = InputBox( "Répertoire racine (existant) des sources (.cpp)" + vbLf + "(ex: R:\code\nel\src pour NeL) :","Nouvelle classe (3)", SrcDirectory )
\r
134 if SrcDirectory <> "" then
\r
135 if right(SrcDirectory,1)<>"\" then
\r
136 SrcDirectory = SrcDirectory + "\"
\r
141 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
142 if IncDirectory = "" then
\r
143 IncDirectory = SrcDirectory
\r
145 if (right(IncDirectory,1)<>"\") then
\r
146 IncDirectory = IncDirectory + "\"
\r
149 CurrentDirectoryName = InputBox( "Nom du répertoire de travail (ex: misc)" + vbLf + "(existant dans " + SrcDirectory + _
\r
150 " et dans " + IncDirectory + ")" + vbLf + "Ce nom restera mémorisé" + vbLf + "(chaîne vide pour pour un projet hors-NeL).", "Nouvelle classe (5)", CurrentDirectoryName )
\r
151 if CurrentDirectoryName<>"" then
\r
152 CurrentDirectoryDir = CurrentDirectoryName + "\"
\r
153 Namesp = "NL" + ucase(CurrentDirectoryName)
\r
155 If InStr( IncDirectory, "nel" ) then
\r
157 ShortIncDir = "nel/" + CurrentDirectoryName + "/"
\r
159 ProdName = "NeL Network Services" ' not Distributed Toolkit Components System anymore
\r
162 ' ** Check for file existence
\r
163 FinalCPPdir = SrcDirectory + CurrentDirectoryDir
\r
164 FinalHdir = IncDirectory + CurrentDirectoryDir
\r
165 if not fso.FolderExists( FinalHdir ) then
\r
166 MsgBox "Erreur : le répertoire " + FinalHdir + " n'existe pas !", vbExclamation
\r
169 if not fso.FolderExists( FinalCPPdir ) then
\r
170 MsgBox "Erreur : le répertoire " + FinalCPPdir + " n'existe pas !", vbExclamation
\r
173 FinalCPPfilename = FinalCPPdir + CppFilename
\r
174 FinalHfilename = FinalHdir + HFilename
\r
175 if fso.FileExists( FinalHfilename ) then
\r
176 MsgBox "Erreur : le fichier " + FinalHfilename + " existe déjà !", vbExclamation
\r
179 if fso.FileExists( FinalCPPfilename ) then
\r
180 MsgBox "Erreur : le fichier " + FinalCPPfilename + " existe déjà !", vbExclamation
\r
184 ' ** Check for open project
\r
185 if CurrentDirectoryName="" then
\r
188 AddToProject = NevraxProjectOpen( CurrentDirectoryName )
\r
191 ' ** Programmer's name
\r
192 CurrentProgrammerName = InputBox( "Votre prénom et votre nom (qui restera mémorisé dans un fichier) :", "Nouvelle classe (6)", CurrentProgrammerName )
\r
193 if CurrentProgrammerName = "" then
\r
197 ' Save configuration
\r
198 set f = fso.OpenTextFile( ConfigFileName, 2, true ) ' 2 = ForWriting
\r
199 f.WriteLine CurrentProgrammerName
\r
200 f.WriteLine SrcDirectory
\r
201 f.WriteLine IncDirectory
\r
204 ' ** Input ancestor class name and file name
\r
205 NoAncestor = "NO BASE CLASS"
\r
206 AncClassName = InputBox( "Nom de la classe de base :", "Nouvelle classe (7)", NoAncestor )
\r
207 if AncClassName = "" then
\r
210 if AncClassName = NoAncestor then
\r
213 AncFilename = InputBox( "Nom de fichier (avec chemin) sans l'extension (ex: nel/misc/toto) :", "Nouvelle classe (8)" )
\r
214 if AncFileName = "" then
\r
217 AncHFilename = AncFilename + ".h"
\r
218 'if not fso.FileExists( AncHFilename ) then
\r
219 ' MsgBox "Attention : le fichier " + AncHFilename + " n'existe pas encore.", vbInformation
\r
224 ' ** Now write .cpp
\r
225 Documents.Add( "Text" )
\r
226 NevraxInsertFileHeader CppFilename, ProdName
\r
227 ActiveDocument.Selection = vbLf + "#include """ + ShortIncDir + HFilename + """" + vbLf + vbLf + vbLf
\r
228 if ( CurrentDirectoryName<>"" ) then
\r
229 ActiveDocument.Selection = "namespace " + Namesp + " {" + vbLf + vbLf + vbLf
\r
231 ActiveDocument.Selection = "/*" + vbLf + _
\r
232 " * Constructor" + vbLf + _
\r
234 ClassName + "::" + ClassName + "()" + vbLf + _
\r
236 "}" + vbLf + vbLf + vbLf
\r
237 if ( CurrentDirectoryName<>"" ) then
\r
238 ActiveDocument.Selection = "} // " + Namesp + vbLf
\r
240 ' Warning: ActiveDocument.Save raises an "Unknown error" if the directory does not exist"
\r
241 ActiveDocument.Save( FinalCPPfilename )
\r
242 if AddToProject=0 then
\r
243 ActiveProject.AddFile( FinalCPPfilename )
\r
245 Projects(AddToProject).AddFile( FinalCPPfilename )
\r
249 Documents.Add( "Text" )
\r
250 NevraxInsertFileHeader HFilename, ProdName
\r
251 ActiveDocument.Selection = vbLf + "#ifndef " + UniqueName + vbLf + _
\r
252 "#define " + UniqueName + vbLf + vbLf
\r
253 ActiveDocument.Selection = "#include ""nel/misc/types_nl.h""" + vbLf
\r
254 if AncClassName <> "" then
\r
255 ActiveDocument.Selection = "#include """ + AncHFilename + """" + vbLf
\r
257 if ( CurrentDirectoryName<>"" ) then
\r
258 ActiveDocument.Selection = vbLf + vbLf + "namespace " + Namesp + " {" + vbLf
\r
260 ActiveDocument.Selection = vbLf + vbLf + _
\r
262 " * <Class description>" + vbLf + _
\r
263 " * \author " + CurrentProgrammerName + vbLf + _
\r
264 " * \author Nevrax France" + vbLf + _
\r
265 " * \date 2005" + vbLf + _
\r
267 "class " + ClassName
\r
268 if AncClassName <> "" then
\r
269 ActiveDocument.Selection = " : public " + AncClassName
\r
271 ActiveDocument.Selection = vbLf + _
\r
273 "public:" + vbLf + vbLf + _
\r
274 " /// Constructor" + vbLf + _
\r
275 " " + ClassName + "();" + vbLf + vbLf + _
\r
277 if ( CurrentDirectoryName<>"" ) then
\r
278 ActiveDocument.Selection = vbLf + "} // " + Namesp + vbLf + vbLf
\r
280 ActiveDocument.Selection = vbLf + "#endif // " + UniqueName + vbLf
\r
281 ActiveDocument.Selection = vbLf + "/* End of " + HFilename + " */" + vbLf
\r
282 ' Warning: ActiveDocument.Save raises an "Unknown error" if the directory does not exist"
\r
283 ActiveDocument.Save( FinalHfilename )
\r
284 if AddToProject=0 then
\r
285 ActiveProject.AddFile( FinalHfilename )
\r
287 Projects(AddToProject).AddFile( FinalHfilename )
\r
292 ' *** End of NevraxNewClass ***
\r
295 ' ** NevraxToggleHCPP
\r
298 ' DESCRIPTION: Opens the .cpp or .h file (toggles) for the current document.
\r
299 ' TIP: Bind this macro to Ctrl+<
\r
300 ' Last modification : 22/05/2001
\r
301 ' Author : Olivier Cado
\r
302 Sub NevraxToggleHCPP()
\r
304 ' ** Get filename extension and ensure it is .h or .cpp
\r
305 ActFilename = ActiveDocument.FullName
\r
306 pos = InstrRev( ActFilename, "." )
\r
307 if ( pos <> 0 ) then
\r
308 Ext = mid(ActFilename,pos)
\r
309 if (Ext<>".h" and Ext<>".cpp") then
\r
310 msgbox( "Error : Active document is not a .cpp or .h file" )
\r
317 ' ** Build the alternative filename
\r
319 ' The module name is the word between the two last backslashes of the path\filename
\r
320 ModuleDir = left( ActFilename, InstrRev(ActFilename,"\")-1 )
\r
321 ModuleDir = mid( ModuleDir, InstrRev(ModuleDir, "\")+1 ) + "\"
\r
324 if ( Ext = ".cpp" ) then
\r
325 SearchDirs(1) = "R:\code\nel\include\nel\" + ModuleDir
\r
326 SearchDirs(2) = "R:\code\nel\include_private\nel\" + ModuleDir
\r
327 SearchDirs(3) = left( ActFilename, InstrRev(ActFilename,"\") ) 'dir of the current file
\r
331 SearchDirs(1) = "R:\code\nel\src\" + ModuleDir
\r
332 SearchDirs(2) = left( ActFilename, InstrRev(ActFilename,"\") ) 'dir of the current file
\r
339 while (DirIndex <= NbDirs) and (FileFound = False)
\r
340 ' NeL directory scheme
\r
341 if InStr(ActFilename,"nel")<>0 then
\r
342 ' Add the search path and the filename
\r
343 NewFilename = SearchDirs(DirIndex)
\r
344 ShortFilenameDot = mid( ActFilename, InstrRev(ActFilename,"\")+1 )
\r
346 ' The complete filename
\r
347 ShortFilenameDot = ActFilename
\r
349 ShortFilenameDot = left( ShortFilenameDot, Instr(ShortFilenameDot,".") )
\r
350 NewFilename = NewFilename + ShortFilenameDot + Ext
\r
352 ' ** Open the alternative file
\r
354 set fso = CreateObject("Scripting.FileSystemObject")
\r
355 if fso.FileExists( NewFilename ) then
\r
356 Documents.Open( NewFilename )
\r
359 Dirs = Dirs + SearchDirs(DirIndex) + vbLf
\r
360 DirIndex = DirIndex + 1
\r
363 if FileFound <> True then
\r
364 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