none
ClassGenerator for C++ Visual Studio 2008 Makro RRS feed

  • Allgemeine Diskussion

  • Ich habe mir hier ein bisschen gebastelt und es kommt auch ein Ergebnis raus und es funktioniert etc.... nur gibt es ein Problem das ich nicht schaffe zu lösen.

    Bevor die Dateien hinzugefügt werden sollen, soll das aktive Projekt ausgewählt werden nur hab ich das bis jetzt leider nicht geschafft.

    Die Dateien werde nicht in den Header und Quellcode Filtern geschrieben, sondern in eine der Dateien die da sind, es sei denn ich klicke vor dem generieren der Class das Projekt an, dann funktioniert es.

    Bitte helft mir, ich verzweifel schon, oder eher ich bin müde....

    Ich stelle hier mein komplettes Makro rein und hoffe das ihr mir helfen könnt.

    Es steht frei zur Verfügung, bedient euch! ;) Und ich hoffe es gefällt!

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports System.Diagnostics
    
    Public Module ClassGenerator
    
     Dim f
     Dim CurrentDirectoryDir, CurrentDirectoryName, ShortIncludeDir
     Dim SourceDirectory
     Dim IncludeDirectory
     Dim TypeFile
     Dim Author
     Dim Email
     Dim Company
     Dim Team
     Dim ProjectNameSpace
     Dim CurrentProject
     Dim Config = "C:\class.cfg"
     Dim Mark As String = "///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////"
    
     Sub GenerateNewClass()
    
     Dim ClassName = InputBox("Name of the new Class:", "New Class :: Step 1")
     If ClassName = "" Then
     Exit Sub
     End If
    
     Dim FileName = InputBox("Name of the new File:", "New Class :: Step 2", ClassName)
     If FileName = "" Then
     Exit Sub
     End If
    
     Dim UniqueName = "SB_" + UCase(FileName) + "_H"
     Dim HeaderName = FileName + ".h"
     Dim SourceName = FileName + ".cpp"
     Dim ScriptObject = CreateObject("Scripting.FileSystemObject")
    
     If ScriptObject.FileExists(Config) Then
     f = ScriptObject.OpenTextFile(Config, 1)
     Author = f.ReadLine
     Email = f.ReadLine
     Company = f.ReadLine
     Team = f.ReadLine
     'ProjectNameSpace = f.ReadLine
     CurrentProject = f.ReadLine
     TypeFile = f.ReadLine
     SourceDirectory = f.ReadLine
     IncludeDirectory = f.ReadLine
     f.Close()
     End If
    
     ' ** Directories
     SourceDirectory = InputBox("Dir for source (.cpp):", "New Class :: Step 3", SourceDirectory)
     If SourceDirectory <> "" Then
     If Right(SourceDirectory, 1) <> "\" Then
     SourceDirectory = SourceDirectory + "\"
     End If
     Else
     IncludeDirectory = ""
     End If
    
     IncludeDirectory = InputBox("Dir for includes (h.):", "New Class :: Step 4", IncludeDirectory)
     If IncludeDirectory = "" Then
     IncludeDirectory = SourceDirectory
     Else
    
     If (Right(IncludeDirectory, 1) <> "\") Then
     IncludeDirectory = IncludeDirectory + "\"
     End If
     End If
    
     CurrentDirectoryName = InputBox("Subfolder for " + IncludeDirectory + ")", "New Class :: Step 5", CurrentDirectoryName)
     If CurrentDirectoryName <> "" Then
     CurrentDirectoryDir = CurrentDirectoryName + "\"
     If ProjectNameSpace = "" Then
     ProjectNameSpace = UCase(CurrentDirectoryName)
     End If
     End If
    
     'Check for file existence
    
     Dim FinalSourceDir = SourceDirectory + CurrentDirectoryDir
     Dim FinalHeaderDir = IncludeDirectory + CurrentDirectoryDir
    
     If Not ScriptObject.FolderExists(FinalHeaderDir) Then
     MsgBox("Error: Path " + FinalHeaderDir + " don't exsist!", vbExclamation)
     Exit Sub
     End If
    
     If Not ScriptObject.FolderExists(FinalSourceDir) Then
     MsgBox("Error: Path " + FinalSourceDir + " don't exsist!", vbExclamation)
     Exit Sub
     End If
    
     Dim FinalSourceName = FinalSourceDir + SourceName
     Dim FinalHeaderName = FinalHeaderDir + HeaderName
    
     If ScriptObject.FileExists(FinalHeaderName) Then
     MsgBox("Error: File " + FinalHeaderName + " exist allready!", vbExclamation)
     Exit Sub
     End If
    
     If ScriptObject.FileExists(FinalSourceName) Then
     MsgBox("Error: File " + FinalSourceName + " exist allready!", vbExclamation)
     Exit Sub
     End If
    
     ' Save configuration
     DTE.StatusBar.Text = "Save Configurationfile..."
     f = ScriptObject.OpenTextFile(Config, 2, True) ' 2 = ForWriting
     f.WriteLine(Author)
     f.WriteLine(Email)
     f.WriteLine(Company)
     f.WriteLine(Team)
     'f.WriteLine(ProjectNameSpace)
     f.WriteLine(CurrentProject)
     f.WriteLine(TypeFile)
     f.WriteLine(SourceDirectory)
     f.WriteLine(IncludeDirectory)
     f.Close()
    
     ' Now write .cpp
     DTE.StatusBar.Text = "Create a new Source File..."
     DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
     DTE.ItemOperations.AddNewItem("Visual C++\C++-Datei (.cpp)", FinalSourceName)
    
     Dim doc As Document = DTE.ActiveDocument
    
     DTE.StatusBar.Text = "Generate the Source File..."
     PrintText(Mark, True)
     PrintText("//        //", True)
     PrintText("//   " & Company & "    //", True)
     PrintText("//   This file is property of the " & Company & "   //", True)
     PrintText("//   The copyright is unlimited since 2004   //", True)
     PrintText("//        //", True)
     PrintText(Mark, True)
     PrintText("// project: " & CurrentProject, True)
     PrintText("// file : " & doc.Name, True)
     PrintText("// TODO : description of " & doc.Name, True)
     PrintText("// date : " & CDate(Now), True)
     PrintText("// author : " & Author, True)
     PrintText("// email : " & Email, True)
     PrintText("// team : " & Team, True)
     PrintText(Mark, True)
     PrintText("", True)
     PrintText("//includes", True)
     PrintText("#include """ + ShortIncludeDir + HeaderName + """", True)
     PrintText("", True)
     PrintText("namespace " & ProjectNameSpace, True)
     PrintText("{", True)
     PrintText("" & ClassName & "::" & ClassName & "()", True)
     PrintText("{", True)
     PrintText("}", True)
     PrintText("", True)
     PrintText("" & ClassName & "::~" & ClassName & "()", True)
     PrintText("{", True)
     PrintText("}", True)
     PrintText("", True)
     PrintText("}//namespace " & ProjectNameSpace, True)
     PrintText("", True)
     PrintText("//end of file", True)
     DTE.StatusBar.Text = "Save the Source File..."
     ActiveDocument.Save(FinalSourceName)
    
     ' Now write .h
     DTE.StatusBar.Text = "Create a new Header File..."
     DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
     DTE.ItemOperations.AddNewItem("Visual C++\Headerdatei (.h)", FinalHeaderName)
     Dim doc2 As Document = DTE.ActiveDocument
     DTE.StatusBar.Text = "Generate the Header File..."
     PrintText(Mark, True)
     PrintText("//        //", True)
     PrintText("//   " & Company & "    //", True)
     PrintText("//   This file is property of the " & Company & "   //", True)
     PrintText("//   The copyright is unlimited since 2004   //", True)
     PrintText("//        //", True)
     PrintText(Mark, True)
     PrintText("// project: " & CurrentProject, True)
     PrintText("// file : " & doc2.Name, True)
     PrintText("// TODO : description of " & doc2.Name, True)
     PrintText("// date : " & CDate(Now), True)
     PrintText("// author : " & Author, True)
     PrintText("// email : " & Email, True)
     PrintText("// team : " & Team, True)
     PrintText(Mark, True)
     PrintText("", True)
     PrintText("#ifndef " & UniqueName, True)
     PrintText("#define " & UniqueName, True)
     PrintText("", True)
     PrintText("//includes", True)
     PrintText("#include """ + ShortIncludeDir + TypeFile + """", True)
     PrintText("", True)
     PrintText("namespace " & ProjectNameSpace, True)
     PrintText("{", True)
     PrintText("class " & ClassName, True)
     PrintText("{", True)
     PrintText("public:", True)
     PrintText("" & ClassName & "();", True)
     PrintText("~" & ClassName & "();", True)
     PrintText("private:", True)
     PrintText("protected:", True)
     PrintText("};//end of class " & ClassName, True)
     PrintText("", True)
     PrintText("}//namespace " & ProjectNameSpace, True)
     PrintText("", True)
     PrintText("#endif //" & UniqueName, True)
     PrintText("", True)
     PrintText("//end of file", True)
     DTE.StatusBar.Text = "Save the Header File..."
     ActiveDocument.Save(FinalHeaderName)
    
     DTE.StatusBar.Text = "All done. Without any Errors."
     End Sub
    
    
    
     Function PrintText(ByVal s As String, ByVal newline As Boolean)
    
     Dim ts As TextSelection = DTE.ActiveWindow.Selection
    
     ts.Text = s
    
     If newline Then
    
     ts.NewLine()
    
     End If
    
    
    
     End Function
    
    
    
    End Module
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    Samstag, 8. Mai 2010 01:41