Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.20 KB | None | 0 0
  1. ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  2.  
  3. Imports System.Drawing
  4. Imports System.Windows.Forms
  5. Imports EnvDTE
  6. Imports Microsoft.VisualStudio.Editor
  7. Imports Microsoft.VisualStudio.Shell.Interop
  8. Imports VSLangProj80
  9.  
  10. Namespace Microsoft.VisualStudio.Editors.PropertyPages
  11.  
  12. Friend NotInheritable Class BuildEventsPropPage
  13. Inherits PropPageUserControlBase
  14. Implements IServiceProvider
  15.  
  16. Public Sub New()
  17. MyBase.New()
  18.  
  19. 'PERF: Set font before InitializeComponent so we don't cause unnecessary layouts (needs the site first)
  20. _fontChangeWatcher = New Common.ShellUtil.FontChangeMonitor(Me, Me, True)
  21.  
  22. InitializeComponent()
  23.  
  24. 'Opt out of page scaling since we're using AutoScaleMode
  25. PageRequiresScaling = False
  26.  
  27. 'Add any initialization after the InitializeComponent() call
  28. AddChangeHandlers()
  29.  
  30. ' Get the Text Editor's font setting from Font and Colors category and set it
  31. SetupTextEditorFontSetting()
  32.  
  33. End Sub
  34.  
  35. Public Sub New(serviceProvider As IServiceProvider)
  36.  
  37. End Sub
  38.  
  39. Public Enum Tokens
  40. OutDir = 0
  41. ConfigurationName
  42. ProjectName
  43. TargetName
  44. TargetPath
  45. ProjectPath
  46. ProjectFileName
  47. TargetExt
  48. TargetFileName
  49. DevEnvDir
  50. TargetDir
  51. ProjectDir
  52. SolutionFileName
  53. SolutionPath
  54. SolutionDir
  55. SolutionName
  56. PlatformName
  57. ProjectExt
  58. SolutionExt
  59. Tokens_MAX
  60. End Enum
  61.  
  62. Private Shared ReadOnly s_tokenNames() As String = {
  63. "OutDir",
  64. "ConfigurationName",
  65. "ProjectName",
  66. "TargetName",
  67. "TargetPath",
  68. "ProjectPath",
  69. "ProjectFileName",
  70. "TargetExt",
  71. "TargetFileName",
  72. "DevEnvDir",
  73. "TargetDir",
  74. "ProjectDir",
  75. "SolutionFileName",
  76. "SolutionPath",
  77. "SolutionDir",
  78. "SolutionName",
  79. "PlatformName",
  80. "ProjectExt",
  81. "SolutionExt"
  82. }
  83.  
  84. Private prevFontInfo As FontInfo
  85.  
  86. ' Helper class to handle font change notifications...
  87. Private _fontChangeWatcher As Common.ShellUtil.FontChangeMonitor
  88.  
  89. 'Data shared by all pages hooked up to this project designer (available through GetService)
  90. Private _configurationState As PropPageDesigner.ConfigurationState
  91.  
  92. '*** Project Property related data
  93. Private _projectObject As Object 'Project's browse object
  94. Private _DTEProject As Project 'Project's DTE object
  95. Private _specialFiles As IVsProjectSpecialFiles
  96.  
  97. Private _serviceProvider As IServiceProvider
  98.  
  99. Private Sub SetupTextEditorFontSetting()
  100. Dim Flags As __FCSTORAGEFLAGS = __FCSTORAGEFLAGS.FCSF_READONLY Or __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS
  101. Dim VsConstantResult As Integer
  102. Dim FontAndColorStorageService = Shell.ServiceProvider.GlobalProvider.GetService(GetType(SVsFontAndColorStorage))
  103. Dim FontColorStorage As IVsFontAndColorStorage = TryCast(FontAndColorStorageService, IVsFontAndColorStorage)
  104. If FontColorStorage IsNot Nothing Then
  105. VsConstantResult = FontColorStorage.OpenCategory(DefGuidList.guidTextEditorFontCategory, CType(Flags, System.UInt32))
  106. If VsConstantResult = VSConstants.S_OK Then
  107. Dim logFontw(1) As LOGFONTW
  108. Dim TextEditorFont(1) As FontInfo
  109. VsConstantResult = FontColorStorage.GetFont(logFontw, TextEditorFont)
  110. If VsConstantResult = VSConstants.S_OK Then
  111. ' Try to set the font..
  112. Dim FontDisplayed As Font
  113. FontDisplayed = New Font(TextEditorFont(0).bstrFaceName, CType(TextEditorFont(0).wPointSize, Single))
  114. txtPreBuildEventCommandLine.Font = FontDisplayed
  115. txtPostBuildEventCommandLine.Font = FontDisplayed
  116. End If
  117.  
  118. End If
  119. FontColorStorage.CloseCategory()
  120.  
  121. End If
  122.  
  123. End Sub
  124.  
  125. Protected Overrides ReadOnly Property ControlData() As PropertyControlData()
  126. Get
  127. If m_ControlData Is Nothing Then
  128. m_ControlData = New PropertyControlData() {
  129. New PropertyControlData(VsProjPropId2.VBPROJPROPID_PreBuildEvent, "PreBuildEvent", txtPreBuildEventCommandLine, ControlDataFlags.None, New Control() {btnPreBuildBuilder, lblPreBuildEventCommandLine}),
  130. New PropertyControlData(VsProjPropId2.VBPROJPROPID_PostBuildEvent, "PostBuildEvent", txtPostBuildEventCommandLine, ControlDataFlags.None, New Control() {btnPostBuildBuilder, lblPostBuildEventCommandLine}),
  131. New PropertyControlData(VsProjPropId2.VBPROJPROPID_RunPostBuildEvent, "RunPostBuildEvent", cboRunPostBuildEvent, New Control() {lblRunPostBuildEvent})
  132. }
  133. End If
  134.  
  135. Return m_ControlData
  136. End Get
  137. End Property
  138.  
  139. Protected Overrides Function GetF1HelpKeyword() As String
  140. If IsVBProject() Then
  141. Return HelpKeywords.VBProjPropBuildEvents
  142. Else
  143. Return HelpKeywords.CSProjPropBuildEvents
  144. End If
  145. End Function
  146.  
  147. Private Sub PostBuildBuilderButton_Click(sender As Object, e As EventArgs) Handles btnPostBuildBuilder.Click
  148. Dim CommandLineText As String
  149. CommandLineText = txtPostBuildEventCommandLine.Text
  150.  
  151. LaunchEventBuilder(Me, AddressOf GetTokenValue, My.Resources.Designer.PPG_PostBuildCommandLineTitle, CommandLineText)
  152. Dim oldCommandLine As String = txtPostBuildEventCommandLine.Text
  153. txtPostBuildEventCommandLine.Text = CommandLineText
  154. If oldCommandLine <> CommandLineText Then
  155. SetDirty(txtPostBuildEventCommandLine, True)
  156. End If
  157. End Sub
  158.  
  159. Private Sub PreBuildBuilderButton_Click(sender As Object, e As EventArgs) Handles btnPreBuildBuilder.Click
  160. Dim CommandLineText As String
  161. CommandLineText = txtPreBuildEventCommandLine.Text
  162.  
  163. LaunchEventBuilder(Me, AddressOf GetTokenValue, My.Resources.Designer.PPG_PreBuildCommandLineTitle, CommandLineText)
  164. Dim oldCommandLine As String = txtPreBuildEventCommandLine.Text
  165. txtPreBuildEventCommandLine.Text = CommandLineText
  166. If oldCommandLine <> CommandLineText Then
  167. SetDirty(txtPreBuildEventCommandLine, True)
  168. End If
  169. End Sub
  170.  
  171. Friend Delegate Function GetTokenValueFunc(MacroName As String) As String
  172.  
  173. Private Function LaunchEventBuilder(Parent As BuildEventsPropPage, valueHelper As GetTokenValueFunc, WindowTitleText As String, ByRef CommandLine As String) As Boolean
  174.  
  175. Dim frm As New BuildEventCommandLineDialog
  176. Dim Values() As String = Nothing
  177.  
  178. '// Initialize the title text
  179. frm.SetFormTitleText(WindowTitleText)
  180.  
  181.  
  182. '// Initialize the command line
  183. frm.EventCommandLine = CommandLine
  184.  
  185. '// Set the page property
  186. frm.Page = Parent
  187.  
  188. '// Set the Dte object for cmdline dialog
  189. ' VSWhidbey 163859 - help not able to retrieve DTE handle
  190. frm.DTE = Parent.DTE
  191.  
  192. '// Initialize the token values
  193.  
  194. GetTokenValues(Values, valueHelper)
  195. frm.SetTokensAndValues(s_tokenNames, Values)
  196.  
  197.  
  198. '// Show the form
  199. If (frm.ShowDialog(ServiceProvider) = System.Windows.Forms.DialogResult.OK) Then
  200. CommandLine = frm.EventCommandLine
  201. End If
  202.  
  203. Return True
  204. End Function
  205.  
  206. Friend Shared Function GetTokenValues(ByRef Values() As String, valueHelper As GetTokenValueFunc) As Boolean
  207. Dim i As Integer
  208. Values = CType(Array.CreateInstance(GetType(String), Tokens.Tokens_MAX), String())
  209.  
  210. For i = 0 To Tokens.Tokens_MAX - 1
  211. Values(i) = valueHelper(s_tokenNames(i))
  212. Next
  213.  
  214. Return True
  215. End Function
  216.  
  217. Private Function GetTokenValue(MacroName As String) As String
  218. Dim MacroEval As IVsBuildMacroInfo
  219. Dim MacroValue As String = Nothing
  220. Dim Hier As IVsHierarchy = Nothing
  221. Dim ItemId As UInteger
  222. Dim ThisObj As Object = m_Objects(0)
  223.  
  224. If TypeOf ThisObj Is IVsBrowseObject Then
  225. VSErrorHandler.ThrowOnFailure(CType(ThisObj, IVsBrowseObject).GetProjectItem(Hier, ItemId))
  226. ElseIf TypeOf ThisObj Is IVsCfgBrowseObject Then
  227. VSErrorHandler.ThrowOnFailure(CType(ThisObj, IVsCfgBrowseObject).GetProjectItem(Hier, ItemId))
  228. End If
  229. MacroEval = CType(Hier, IVsBuildMacroInfo)
  230. VSErrorHandler.ThrowOnFailure(MacroEval.GetBuildMacroValue(MacroName, MacroValue))
  231.  
  232. Return MacroValue
  233. End Function
  234.  
  235. Private Sub SetSite(serviceProvider As IServiceProvider)
  236. _serviceProvider = serviceProvider
  237.  
  238. 'Set the provider into the base tab control so it can get access to fonts and colors
  239. MyBase.ServiceProvider = _serviceProvider
  240. End Sub
  241.  
  242. Public Shadows Function GetService(serviceType As Type) As Object Implements IServiceProvider.GetService
  243. 'Dim Service As Object
  244.  
  245. 'Dim FontAndColorStorageService = Shell.ServiceProvider.GlobalProvider.GetService(GetType(SVsFontAndColorStorage))
  246.  
  247. If serviceType Is GetType(BuildEventsPropPage) Then
  248. 'Allows the PropPageDesignerView to access the ApplicationDesignerView
  249. Return ServiceProvider
  250. Else
  251. Return Shell.ServiceProvider.GlobalProvider.GetService(GetType(SVsFontAndColorStorage))
  252. End If
  253.  
  254. 'Service = _serviceProvider.GetService(serviceType)
  255. 'Return Service
  256. End Function
  257. End Class
  258.  
  259. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement