public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { if (_editorUI == null) { _editorUI = new XSharpSLEPropertyForm(); } _editorUI.Text = context.PropertyDescriptor.DisplayName; // we can also use the Attributes property to pass in information via an attribute _editorUI.PropertyText.Text = (string)value; _editorUI.PropertyText.Select(); _editorUI.PropertyText.DeselectAll(); _editorUI.PropertyText.ClearUndo(); XBuildMacroCollection mc = new XBuildMacroCollection((ProjectNode)((SettingsPage)context.Instance).ProjectMgr); _editorUI.SetMacros(mc); DialogResult result = edSvc.ShowDialog(_editorUI); if (result == DialogResult.OK) { value = _editorUI.PropertyText.Text; } } } return(value); }
// ========================================================================================= // Methods // ========================================================================================= /// <summary> /// Sets up the macros list view. /// </summary> /// <param name="buildMacros">The collection of build macros to add to the list.</param> public void InitializeMacroList(XBuildMacroCollection buildMacros) { this.macrosListView.Items.Clear(); foreach (XBuildMacroCollection.MacroNameValuePair pair in buildMacros) { ListViewItem item = new ListViewItem(new string[] { pair.MacroName, pair.Value }, 0); this.macrosListView.Items.Add(item); } this.macrosListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Initializes a new instance of the <see cref="XSharpBuildMacros"/> class. /// </summary> /// <param name="project">The project from which to read the properties.</param> public XBuildMacroCollection(ProjectNode project) { XHelperMethods.VerifyNonNullArgument(project, "project"); // get the global SolutionX properties XBuildMacroCollection.DefineSolutionProperties(project); foreach (string globalMacroName in globalMacroNames) { string property = null; project.BuildProject.GlobalProperties.TryGetValue(globalMacroName, out property); if (null == property) { this.list.Add(globalMacroName, "*Undefined*"); } else { this.list.Add(globalMacroName, property); } } // we need to call GetTargetPath first so that TargetDir and TargetPath are resolved correctly ConfigCanonicalName configCanonicalName; if (!Utilities.TryGetActiveConfigurationAndPlatform(project.Site, project, out configCanonicalName)) { throw new InvalidOperationException(); } BuildResult res = project.Build(configCanonicalName, XProjectFileConstants.GetTargetPath); // get the ProjectX and TargetX variables foreach (string macroName in macroNames) { string value; if (res.ProjectInstance != null) { value = res.ProjectInstance.GetPropertyValue(macroName); } else { value = project.GetProjectProperty(macroName); } this.list.Add(macroName, value); } }
internal void SetMacros(XBuildMacroCollection mc) { MacrosList.BeginUpdate(); MacrosList.Items.Clear(); foreach (var p in mc) { ListViewItem i = new ListViewItem(); i.Text = String.Concat("$(", p.MacroName, ")"); i.SubItems.Add(p.Value); MacrosList.Items.Add(i); } MacrosList.Items[0].Selected = true; MacrosList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); MacrosList.EndUpdate(); }
/// <summary> /// Shows the editor form, which contains advanced editing features. /// </summary> /// <param name="sender">The edit button.</param> /// <param name="e">The <see cref="EventArgs"/> object that contains the event data.</param> private void OnEditButtonClick(object sender, EventArgs e) { // set the form's caption and text box this.EditorForm.Text = this.EditorFormText; this.EditorForm.EditorText = this.contentTextBox.Text; // get the build macros currently defined - we do this every time rather than caching // the results because the configuration could change without us knowing about it. XBuildMacroCollection buildMacros = new XBuildMacroCollection(this.project); this.EditorForm.InitializeMacroList(buildMacros); // show the dialog and get the text back DialogResult result = this.editorForm.ShowDialog(this); if (result == DialogResult.OK) { this.contentTextBox.Text = this.editorForm.EditorText; this.contentTextBox.Modified = true; this.contentTextBox.Select(this.contentTextBox.Text.Length, 0); this.contentTextBox.Focus(); } }
/// <summary> /// Executes an MSBuild target. /// </summary> /// <param name="target">Name of the MSBuild target to execute.</param> /// <returns>Result from executing the target (success/failure).</returns> protected override Microsoft.VisualStudio.Project.BuildResult InvokeMsBuild(string target) { XBuildMacroCollection.DefineSolutionProperties(this); XBuildMacroCollection.DefineProjectReferenceConfigurations(this); return(base.InvokeMsBuild(target)); }