Linux multi-monitor fullscreen support
[ryzomcore.git] / tool / visual_studio_macros / nevrax_macros_ryzom.dsm
blob8fe8c4c02385e3a68369e79c7c5d7c1973764e7c
1 ' nevrax_macros.dsm\r
2 '\r
3 ' Copyright (C) 2000-2004 Nevrax. All rights reserved.\r
4 '\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
8 '\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
25                 " */" + vbLf + vbLf\r
26 End Sub\r
29 Function IsUpCase( str )\r
30         IsUpcase = ( str = Ucase(str) )\r
31 End Function\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
39         beginningpos = 1\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
44                                 beginningpos = 2\r
45                         end if\r
46                 end if\r
47         end if\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
55                                 end if\r
56                         else\r
57                                 filename = filename + "_"\r
58                         end if\r
59                 end if\r
60                 filename = filename + lcase(charact)\r
61         next\r
62         NevraxClassNameToFileName = filename\r
63 End Function\r
66 ' NevraxProjectOpen\r
67 ' Utility Function for NevraxNewClass()\r
68 ' Author : Olivier Cado\r
69 Function NevraxProjectOpen( projname )\r
70         found = 0\r
71         dim proj\r
72         for i = 1 to Projects.Count\r
73                 if Projects(i).Name = projname then\r
74                         found = i\r
75                         exit for\r
76                 end if\r
77         next\r
78         NevraxProjectOpen = found\r
79 End Function\r
82 ' Global variable\r
83 Dim CurrentDirectoryName\r
84 Dim CurrentProgrammerName\r
87 ' NevraxNewClass\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
93 ' Weird things :\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
103                 Exit Sub\r
104         end if\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
109                 Exit Sub\r
110         end if\r
111         UniqueName = "NL_" + UCase( Filename ) + "_H"\r
112         HFilename = Filename + ".h"\r
113         CppFilename = Filename + ".cpp"\r
115         ' Load configuration\r
116         dim fso\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
123                 'else\r
124                 '       CurrentProgrammerName = "Richard Stallman"\r
125                 'end if\r
126                 SrcDirectory = f.ReadLine\r
127                 IncDirectory = f.ReadLine\r
128                 f.Close\r
129         end if\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
136                 end if\r
137         else\r
138                 IncDirectory = ""\r
139         end if\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
143         else\r
144                 if (right(IncDirectory,1)<>"\") then\r
145                         IncDirectory = IncDirectory + "\"\r
146                 end if\r
147         end if\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
153         end if\r
154         If InStr( IncDirectory, "nel" ) then\r
155                 ProdName = "NEL"\r
156                 ShortIncDir = "nel/" + CurrentDirectoryName + "/"\r
157         else\r
158                 ProdName = "RYZOM" ' HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE\r
159         end if\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
166                 Exit Sub\r
167         end if\r
168         if not fso.FolderExists( FinalCPPdir ) then\r
169                 MsgBox "Erreur : le répertoire " + FinalCPPdir + " n'existe pas !", vbExclamation\r
170                 Exit Sub\r
171         end if\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
176                 Exit Sub\r
177         end if\r
178         if fso.FileExists( FinalCPPfilename ) then\r
179                 MsgBox "Erreur : le fichier " + FinalCPPfilename + " existe déjà !", vbExclamation\r
180                 Exit Sub\r
181         end if\r
183         ' ** Check for open project\r
184         if CurrentDirectoryName=""      then\r
185                 AddToProject = 0\r
186         else\r
187                 AddToProject = NevraxProjectOpen( CurrentDirectoryName )\r
188         end if\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
193                 Exit Sub\r
194         end if\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
201         f.Close\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
207                 Exit Sub\r
208         else\r
209                 if AncClassName = NoAncestor then\r
210                         AncClassName = ""\r
211                 else\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
214                                 Exit Sub\r
215                         end if\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
219                         'end if\r
220                 end if\r
221         end if\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
229         end if\r
230         ActiveDocument.Selection = "/*" + vbLf + _\r
231                 " * Constructor" + vbLf + _\r
232                 " */" + vbLf + _\r
233                 ClassName + "::" + ClassName + "()" + vbLf + _\r
234                 "{" + vbLf + _\r
235                 "}" + vbLf + vbLf + vbLf\r
236         if ( CurrentDirectoryName<>"" ) then\r
237                 ActiveDocument.Selection = "} // " + Namesp + vbLf\r
238         end if\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
243         else\r
244                 Projects(AddToProject).AddFile( FinalCPPfilename )\r
245         end if\r
247         ' ** Now write .h\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
255         end if\r
256         if ( CurrentDirectoryName<>"" ) then\r
257                 ActiveDocument.Selection = vbLf + vbLf + "namespace " + Namesp + " {" + vbLf\r
258         end if\r
259         ActiveDocument.Selection = vbLf + vbLf + _\r
260                 "/**" + vbLf + _\r
261                 " * <Class description>" + vbLf + _\r
262                 " * \author " + CurrentProgrammerName + vbLf + _\r
263                 " * \author Nevrax France" + vbLf + _\r
264                 " * \date 2004" + vbLf + _\r
265                 " */" + vbLf + _\r
266                 "class " + ClassName\r
267         if AncClassName <> "" then\r
268                 ActiveDocument.Selection = " : public " + AncClassName\r
269         end if\r
270         ActiveDocument.Selection = vbLf + _\r
271                 "{" + vbLf + _\r
272                 "public:" + vbLf + vbLf + _\r
273                 "       /// Constructor" + vbLf + _\r
274                 "       " + ClassName + "();" + vbLf + vbLf + _\r
275                 "};" + vbLf + vbLf\r
276         if ( CurrentDirectoryName<>"" ) then\r
277                 ActiveDocument.Selection = vbLf + "} // " + Namesp + vbLf + vbLf\r
278         end if\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
285         else\r
286                 Projects(AddToProject).AddFile( FinalHfilename )\r
287         end if\r
289 End Sub\r
291 ' *** End of NevraxNewClass ***\r
294 ' ** NevraxToggleHCPP\r
296 ' 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
310                         exit sub\r
311                 end if\r
312         else\r
313                 exit sub\r
314         end if\r
315         \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
322         dim SearchDirs (4)\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
327                 NbDirs = 3\r
328                 Ext = "h"\r
329         else\r
330                 SearchDirs(1) = "R:\code\nel\src\" + ModuleDir\r
331                 SearchDirs(2) = left( ActFilename, InstrRev(ActFilename,"\") ) 'dir of the current file\r
332                 NbDirs = 2\r
333                 Ext = "cpp"\r
334         end if\r
335         DirIndex = 1\r
336         FileFound = False\r
337         Dirs = ""\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
344                 else\r
345                         ' The complete filename\r
346                         ShortFilenameDot = ActFilename\r
347                 end if\r
348                 ShortFilenameDot = left( ShortFilenameDot, Instr(ShortFilenameDot,".") )\r
349                 NewFilename = NewFilename + ShortFilenameDot + Ext\r
350  \r
351                 ' ** Open the alternative file\r
352                 dim fso\r
353                 set fso = CreateObject("Scripting.FileSystemObject")\r
354                 if fso.FileExists( NewFilename ) then\r
355                         Documents.Open( NewFilename )\r
356                         FileFound = True\r
357                 else\r
358                         Dirs = Dirs + SearchDirs(DirIndex) + vbLf\r
359                         DirIndex = DirIndex + 1\r
360                 end if\r
361         wend\r
362         if FileFound <> True then\r
363                 MsgBox "There is no file " + ShortFilenameDot + Ext + " in " + vbLf + Dirs\r
364         end if\r
365 End Sub\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
389 End Sub\r