/src/Votive/votive/Forms/WixBuildEventEditorForm.cs

http://wix.codeplex.com · C# · 163 lines · 86 code · 26 blank · 51 comment · 6 complexity · 9b4686287aad4eb8c08406a133fb56e2 MD5 · raw file

  1. //--------------------------------------------------------------------------------------------------
  2. // <copyright file="WixBuildEventEditorForm.cs" company="Outercurve Foundation">
  3. // Copyright (c) 2004, Outercurve Foundation.
  4. // This software is released under Microsoft Reciprocal License (MS-RL).
  5. // The license and further copyright text can be found in the file
  6. // LICENSE.TXT at the root directory of the distribution.
  7. // </copyright>
  8. //
  9. // <summary>
  10. // Contains the WixBuildEventEditorForm class.
  11. // </summary>
  12. //--------------------------------------------------------------------------------------------------
  13. namespace WixToolset.VisualStudio.Forms
  14. {
  15. using System;
  16. using System.Collections.Generic;
  17. using System.ComponentModel;
  18. using System.Windows.Forms;
  19. /// <summary>
  20. /// Advanced editor form for build events.
  21. /// </summary>
  22. internal partial class WixBuildEventEditorForm : Form
  23. {
  24. // =========================================================================================
  25. // Member Variables
  26. // =========================================================================================
  27. private static readonly List<string> DelayedExpansionProperties = new List<string>(new string[]
  28. {
  29. "TargetPath",
  30. "TargetPdbPath"
  31. });
  32. private IServiceProvider serviceProvider;
  33. // =========================================================================================
  34. // Constructors
  35. // =========================================================================================
  36. /// <summary>
  37. /// Initializes a new instance of the <see cref="WixBuildEventEditorForm"/> class.
  38. /// </summary>
  39. /// <param name="serviceProvider">The service provider object provided by the IDE hosting the project.</param>
  40. public WixBuildEventEditorForm(IServiceProvider serviceProvider)
  41. {
  42. this.serviceProvider = serviceProvider;
  43. this.InitializeComponent();
  44. this.HelpRequested += new HelpEventHandler(this.WixBuildEventEditorForm_HelpRequested);
  45. this.Font = WixHelperMethods.GetDialogFont();
  46. }
  47. // =========================================================================================
  48. // Properties
  49. // =========================================================================================
  50. /// <summary>
  51. /// Gets or sets the editor's text.
  52. /// </summary>
  53. public string EditorText
  54. {
  55. get { return this.contentTextBox.Text; }
  56. set { this.contentTextBox.Text = value; }
  57. }
  58. // =========================================================================================
  59. // Methods
  60. // =========================================================================================
  61. /// <summary>
  62. /// Sets up the macros list view.
  63. /// </summary>
  64. /// <param name="buildMacros">The collection of build macros to add to the list.</param>
  65. public void InitializeMacroList(WixBuildMacroCollection buildMacros)
  66. {
  67. this.macrosListView.Items.Clear();
  68. foreach (WixBuildMacroCollection.MacroNameValuePair pair in buildMacros)
  69. {
  70. ListViewItem item = new ListViewItem(new string[] { pair.MacroName, pair.Value }, 0);
  71. this.macrosListView.Items.Add(item);
  72. }
  73. this.macrosListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
  74. }
  75. /// <summary>
  76. /// This method gets called whenever the dialog box is shown.
  77. /// </summary>
  78. /// <param name="e">Contains information about the event raised.</param>
  79. protected override void OnShown(EventArgs e)
  80. {
  81. // Set focus and cursor to text box.
  82. this.contentTextBox.Focus();
  83. this.contentTextBox.SelectionStart = this.contentTextBox.Text.Length;
  84. // Disable insert button as no macro is selected by default.
  85. this.insertButton.Enabled = false;
  86. base.OnShown(e);
  87. }
  88. /// <summary>
  89. /// Inserts the specified macro name into the text box at the current text selection.
  90. /// </summary>
  91. /// <param name="item">The <see cref="ListViewItem"/> that contains the macro name.</param>
  92. private void InsertMacro(ListViewItem item)
  93. {
  94. string macroName = item.Text;
  95. if (DelayedExpansionProperties.Contains(macroName))
  96. {
  97. this.contentTextBox.SelectedText = "!(" + macroName + ")";
  98. }
  99. else
  100. {
  101. this.contentTextBox.SelectedText = "$(" + macroName + ")";
  102. }
  103. this.contentTextBox.Focus();
  104. }
  105. // =========================================================================================
  106. // Event Handlers
  107. // =========================================================================================
  108. private void OnInsertButtonClick(object sender, EventArgs e)
  109. {
  110. if (this.macrosListView.SelectedItems.Count > 0)
  111. {
  112. this.InsertMacro(this.macrosListView.SelectedItems[0]);
  113. }
  114. }
  115. private void OnMacrosListViewMouseDoubleClick(object sender, MouseEventArgs e)
  116. {
  117. ListViewHitTestInfo hitTestInfo = this.macrosListView.HitTest(e.Location);
  118. if (hitTestInfo.Item != null)
  119. {
  120. this.InsertMacro(hitTestInfo.Item);
  121. }
  122. }
  123. private void OnMacrosListViewSelectedIndexChanged(object sender, EventArgs e)
  124. {
  125. this.insertButton.Enabled = this.macrosListView.SelectedItems.Count > 0;
  126. }
  127. private void WixBuildEventEditorForm_HelpRequested(object sender, HelpEventArgs hlpevent)
  128. {
  129. Microsoft.VisualStudio.VSHelp.Help help = this.serviceProvider.GetService(typeof(Microsoft.VisualStudio.VSHelp.Help)) as Microsoft.VisualStudio.VSHelp.Help;
  130. if (help != null)
  131. {
  132. help.DisplayTopicFromF1Keyword("cs.ProjectPropertiesBuildEventsBuilder");
  133. }
  134. hlpevent.Handled = true;
  135. }
  136. }
  137. }