Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

270 lines
20 KiB

  1. ��Imports EnvDTE
  2. Imports System.Diagnostics
  3. Imports System.IO
  4. Public Module Valve
  5. Sub CloseToolWindows()
  6. DTE.ExecuteCommand("View.CommandWindow")
  7. DTE.Windows.Item(Constants.vsWindowKindCommandWindow).Close()
  8. DTE.Windows.Item("{73F6DD5A-437E-11D3-B88E-00C04F79F802}").Close()
  9. DTE.ExecuteCommand("View.Output")
  10. DTE.Windows.Item(Constants.vsWindowKindOutput).Close()
  11. DTE.ExecuteCommand("View.TaskList")
  12. DTE.Windows.Item(Constants.vsWindowKindTaskList).Close()
  13. DTE.ExecuteCommand("View.FindResults1")
  14. DTE.Windows.Item(Constants.vsWindowKindFindResults1).Close()
  15. DTE.ExecuteCommand("View.FindResults2")
  16. DTE.Windows.Item(Constants.vsWindowKindFindResults2).Close()
  17. End Sub
  18. Sub ModuleHeader()
  19. 'DESCRIPTION: This macro adds the standard copyright information to the top of a module.
  20. ActiveDocument.Selection.StartOfDocument()
  21. ' Create the standard file prologue
  22. Dim Header As String
  23. Header = "//====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======" + vbCrLf
  24. Header = Header + "//" + vbCrLf
  25. Header = Header + "// Purpose: " + vbCrLf
  26. Header = Header + "//" + vbCrLf
  27. Header = Header + "//=============================================================================" + vbCrLf + vbCrLf
  28. ' Add the single inclusion macros for header files
  29. Dim DotHPos As String
  30. DotHPos = InStr(ActiveDocument.Name, ".h")
  31. Dim InclusionKey As String
  32. If DotHPos > 0 Then
  33. InclusionKey = Left(ActiveDocument.Name, DotHPos - 1)
  34. InclusionKey = UCase(InclusionKey) + "_H"
  35. Header = Header + "#ifndef " + InclusionKey + vbCrLf
  36. Header = Header + "#define " + InclusionKey + vbCrLf
  37. Header = Header + "#ifdef _WIN32" + vbCrLf
  38. Header = Header + "#pragma once" + vbCrLf
  39. Header = Header + "#endif" + vbCrLf + vbCrLf
  40. End If
  41. ActiveDocument.Selection.Text = Header
  42. ' Add the "#endif" for header files
  43. If DotHPos > 0 Then
  44. ActiveDocument.Selection.EndOfDocument()
  45. Header = vbCrLf + "#endif // " + InclusionKey + vbCrLf
  46. ActiveDocument.Selection.Text = Header
  47. End If
  48. ActiveDocument.Selection.StartOfDocument()
  49. End Sub
  50. Sub TypeHeader()
  51. 'DESCRIPTION: This macro adds a description block above a type declaration
  52. ' Select the text on the current line and store it for parsing
  53. ActiveDocument.Selection.SelectLine()
  54. Dim TypeDec As String
  55. TypeDec = ActiveDocument.Selection.Text
  56. ActiveDocument.Selection.StartOfLine()
  57. ' Check to make sure that this line is a type delcaration
  58. If InStr(TypeDec, "class") = 0 And InStr(TypeDec, "struct") = 0 And InStr(TypeDec, "interface") = 0 And InStr(TypeDec, "enum") = 0 Then
  59. MsgBox("This line does not contain a class, struct, interface, or enum declaration.")
  60. Else
  61. ' Construct the type header
  62. Dim Header As String
  63. Header = "//-----------------------------------------------------------------------------" + vbCrLf
  64. Header = Header + "// Purpose: " + vbCrLf
  65. Header = Header + "//-----------------------------------------------------------------------------" + vbCrLf
  66. ' Write the header
  67. ActiveDocument.Selection.Text = Header
  68. End If
  69. End Sub
  70. Sub FunctionHeader()
  71. 'DESCRIPTION: This macro creates a function header for C functions or C++ member functions
  72. ' Select the text on the current line and store it for parsing
  73. ActiveDocument.Selection.SelectLine()
  74. Dim FunctionImp = ActiveDocument.Selection.Text
  75. ActiveDocument.Selection.StartOfLine()
  76. Dim LineNum = ActiveDocument.Selection.CurrentLine
  77. Dim FunctionName = Left(FunctionImp, InStr(FunctionImp, "("))
  78. ' Check to make sure that this line is a class delcaration
  79. If Len(FunctionName) = 0 Then
  80. MsgBox("This line does not contain a function implementation.")
  81. Else
  82. Dim FuncArray = Split(FunctionName)
  83. Dim ReturnType = ""
  84. ' Get the return type and function name
  85. Dim Element
  86. For Each Element In FuncArray
  87. If InStr(Element, "(") = 0 Then
  88. ReturnType = ReturnType + Element + " "
  89. Else
  90. FunctionName = Left(Element, Len(Element) - 1)
  91. End If
  92. Next
  93. ReturnType = Trim(ReturnType)
  94. If ReturnType = "BOOL" Then
  95. ReturnType = "Returns TRUE on success, FALSE on failure."
  96. ElseIf ReturnType = "bool" Then
  97. ReturnType = "Returns true on success, false on failure."
  98. End If
  99. ' Place the function parameters in its own string
  100. Dim Params = Right(FunctionImp, Len(FunctionImp) - InStr(FunctionImp, "("))
  101. Do While InStr(Params, ")") = 0
  102. ActiveDocument.Selection.LineDown()
  103. ActiveDocument.Selection.SelectLine()
  104. Params = Left(Params, InStr(Params, vbCrLf) - 1)
  105. Params = Params + Trim(ActiveDocument.Selection.Text)
  106. Loop
  107. ActiveDocument.Selection.GotoLine(LineNum - 1)
  108. Params = Left(Params, InStr(Params, ")") - 1)
  109. Params = Trim(Params)
  110. ' Remove any /* */ comments from Params
  111. Dim Pos = InStr(Params, "/*")
  112. Do While Pos
  113. Dim EndComment = InStr(Params, "*/")
  114. If EndComment Then
  115. Dim StartString = Left(Params, InStr(Params, "/*") - 1)
  116. Dim Pos2 = Len(Params) - InStr(Params, "*/") + 3
  117. Dim EndString = Mid(Params, InStr(Params, "*/") + 2, Pos2)
  118. StartString = Trim(StartString)
  119. EndString = Trim(EndString)
  120. Params = StartString + EndString
  121. Pos = InStr(Params, "/*")
  122. Else
  123. Pos = 0
  124. End If
  125. Loop
  126. ' Create an array of individual parameters
  127. Dim ParamsArray = Split(Params, ",")
  128. ' Construct the parameters section
  129. Dim ParamSection = ""
  130. Dim AddNewLine = 0
  131. For Each Element In ParamsArray
  132. Element = Trim(Element)
  133. Element = Right(Element, Len(Element) - InStrRev(Element, " "))
  134. If AddNewLine = 1 Then
  135. ParamSection = ParamSection + vbCrLf + "// "
  136. End If
  137. ParamSection = ParamSection + Element + " - "
  138. AddNewLine = 1
  139. Next
  140. ' Construct the rest of the header
  141. Dim Header = "//-----------------------------------------------------------------------------" + vbCrLf
  142. Header = Header + "// Purpose: " + vbCrLf
  143. If ParamSection <> "void - " And ParamSection <> "" Then
  144. Header = Header + "// Input : " + ParamSection + vbCrLf
  145. End If
  146. If ReturnType <> "void" And ReturnType <> "" Then
  147. Header = Header + "// Output : " + ReturnType + vbCrLf
  148. End If
  149. Header = Header + "//-----------------------------------------------------------------------------" + vbCrLf
  150. ' Write the header
  151. ActiveDocument.Selection.Text = Header
  152. End If
  153. End Sub
  154. 'DESCRIPTION: Comments in or out a line of code, then moves to the next line.
  155. Sub ToggleComment()
  156. ActiveDocument.Selection.SelectLine()
  157. Dim LineText As String = ActiveDocument.Selection.Text
  158. Dim FirstTwoChars = Left(LineText, 2)
  159. If Len(FirstTwoChars) < 2 Then
  160. ActiveDocument.Selection.Text = ""
  161. ElseIf FirstTwoChars = "//" Then
  162. ActiveDocument.Selection.Text = Right(LineText, Len(LineText) - 2)
  163. Else
  164. ActiveDocument.Selection.Text = "//" + LineText
  165. End If
  166. End Sub
  167. Sub JumpToHeader()
  168. '////////////////////////////////////////////
  169. 'DESCRIPTION: Switch Between Header and cpp
  170. '////////////////////////////////////////////
  171. Dim myDocument
  172. Dim a
  173. Dim b
  174. Dim c
  175. Dim Flag
  176. Dim Flag1
  177. Flag1 = 0
  178. Flag = 1
  179. a = ActiveDocument.FullName
  180. Dim tmp = InStr(a, ".cpp")
  181. If tmp Then
  182. b = Left(a, Len(a) - 3) + "h"
  183. c = Left(a, Len(a) - 3) + "h"
  184. Flag1 = 1
  185. Else
  186. tmp = InStr(a, ".c")
  187. If tmp Then
  188. b = Left(a, Len(a) - 1) + "h"
  189. c = Left(a, Len(a) - 1) + "h"
  190. Flag1 = 1
  191. Else
  192. tmp = InStr(a, ".h")
  193. If tmp Then
  194. b = Left(a, Len(a) - 1) + "c"
  195. c = Left(a, Len(a) - 1) + "cpp"
  196. Flag1 = 1
  197. End If
  198. End If
  199. End If
  200. For Each myDocument In Application.Documents
  201. If myDocument.FullName = b Then
  202. myDocument.Active = True
  203. Flag = 0
  204. Exit For
  205. End If
  206. If myDocument.FullName = c Then
  207. myDocument.Active = True
  208. Flag = 0
  209. b = c
  210. Exit For
  211. End If
  212. Next
  213. If Flag And Flag1 Then
  214. DTE.Documents.Open(b, "Text")
  215. End If
  216. End Sub
  217. End Module