Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module Utility
'アウトプットペインに文字列を出力する
Sub WriteOutputpane(ByVal paneName As String, ByVal text As String)
Dim output As OutputWindowPane
Try
output = DTE.ToolWindows.OutputWindow.OutputWindowPanes.Item(paneName)
Catch ex As Exception
output = DTE.ToolWindows.OutputWindow.OutputWindowPanes.Add(paneName)
End Try
output.OutputString(text)
End Sub
Sub WriteOutputpane(ByVal text As String)
WriteOutputpane("My Macro Default", text)
End Sub
Sub WriteOutputpane(ByVal paneName As OutputWindowPane, ByVal text As String)
paneName.OutputString(text)
End Sub
'アウトプットペインに改行付きで文字列を出力する
Sub WriteLineOutputpane(ByVal paneName As String, ByVal text As String)
WriteOutputpane(paneName, text + vbCrLf)
End Sub
Sub WriteLineOutputpane(ByVal text As String)
WriteOutputpane("My Macro Default", text + vbCrLf)
End Sub
Sub WriteLineOutputpane(ByVal paneName As OutputWindowPane, ByVal text As String)
paneName.OutputString(text + vbCrLf)
End Sub
Sub WriteLineOutputpane()
WriteOutputpane(vbCrLf)
End Sub
Sub ClearOutputpane(ByVal paneName As String)
Dim output As OutputWindowPane
output = DTE.ToolWindows.OutputWindow.OutputWindowPanes.Item(paneName)
output.Clear()
End Sub
'インクルードガードを書き込む
Sub WriteIncludeGuard()
If IsTextWindow() Then Return
Dim name As String
name = DTE.ActiveDocument.Name
name = name.ToUpper()
name = name.Replace(".", "_")
name = name + "_"
DTE.ActiveDocument.Selection.Text = _
"#ifndef " + name + NewLine() + _
"#define " + name + NewLine() + _
NewLine(3) + _
"#endif // " + name + NewLine()
End Sub
'namespace を書き込む
Sub WriteNamespace()
If IsTextWindow() Then Return
DTE.ActiveDocument.Selection.Text = "namespace {" + NewLine(3) + "} // namespace "
End Sub
'インクルードガードと名前空間を書き込む
Sub WriteIncludeGuardAndNamespace()
If IsTextWindow() Then Return
Dim name As String
name = DTE.ActiveDocument.Name
name = name.ToUpper()
name = name.Replace(".", "_")
name = name + "_"
DTE.ActiveDocument.Selection.Text = _
"#ifndef " + name + NewLine() + _
"#define " + name + NewLine() + _
NewLine() + _
"namespace {" + NewLine() + _
NewLine(3) + _
"} // namespace " + NewLine() + _
NewLine() + _
"#endif // " + name + NewLine()
End Sub
Sub WriteIncludeAndNamespace()
If IsTextWindow() Then Return
DTE.ActiveDocument.Selection.Text = "#include """ + HeaderName(DTE.ActiveDocument.Name) + """" + NewLine(2)
WriteNamespace()
End Sub
'ソリューションをアクティブ化する
Sub ActiveSolution()
DTE.Windows.Item("ソリューション エクスプローラー").Activate()
End Sub
'ウィンドウがテキストウィンドウか調べる
Function IsTextWindow() As Boolean
IsTextWindow(DTE.ActiveWindow)
End Function
Function IsTextWindow(ByVal win As EnvDTE.Window) As Boolean
If TypeOf win.Object Is TextWindow Then
IsTextWindow = True
Else
IsTextWindow = False
End If
End Function
'改行文字列を返す
Function NewLine() As String
Return Environment.NewLine
End Function
Function NewLine(ByVal number As Integer) As String
Dim s As String = ""
For i As Integer = 1 To number
s += Environment.NewLine
Next
Return s
End Function
'ソースファイル名(.cpp)をもとにヘッダファイル名(.h)を返す
Function HeaderName(ByVal SourceName As String) As String
Return SourceName.Replace(".cpp", ".h")
End Function
'
Sub 一時()
MsgBox("")
End Sub
End Module