/// <summary> /// Called after the dialog has been created. /// </summary> /// <param name="DTEObject">The DTE object.</param> void IDTToolsOptionsPage.OnAfterCreated(DTE DTEObject) { // Enumerate plug-ins and create a dynamic properties // Must also check for unique features CustomClass featuresHost = new CustomClass(); foreach (BIDSHelperPluginBase plugin in Connect.Plugins.Values) { CustomProperty parent = featuresHost.Find(plugin.FeatureName); if (parent == null) { // New feature featuresHost.Add(new CustomProperty(plugin)); } else { parent.Children.Add(new CustomProperty(plugin)); } } // Assign our dynamic properties collection to the property grid this.propertyGridFeatures.SelectedObject = featuresHost; // Hide property grid when we have nothing to show, and display // "add-in is not currently enabled" message instead propertyGridFeatures.Visible = (featuresHost.Count > 0); lblCurrentlyDisabled.Visible = !propertyGridFeatures.Visible; // Skip the rest if the add-in is disabled if (lblCurrentlyDisabled.Visible) { return; } // Set width of property grid columns, make the description larger than default 50% FieldInfo fieldInfo = typeof(PropertyGrid).GetField("gridView", BindingFlags.NonPublic | BindingFlags.Instance); object gridViewRef = fieldInfo.GetValue(this.propertyGridFeatures); Type gridViewType = gridViewRef.GetType(); MethodInfo methodInfo = gridViewType.GetMethod("MoveSplitterTo", BindingFlags.NonPublic | BindingFlags.Instance); int width = (int)(this.propertyGridFeatures.Width * 0.7); methodInfo.Invoke(gridViewRef, new object[] { width }); // Description area size is tool small for 3 lines of text, but fine for 2. // The DocComment Lines or Height approach is too unreliable, need to get // accurate border sizes, DrawString etc. Only a few descriptions that are // too long. Most are only 1 line, so live with it as is. // Set default focus to General category, the top of the grid // Walk up to the top of the grid tree first GridItem item = this.propertyGridFeatures.SelectedGridItem; if (item == null) { return; } while (item.Parent != null) { item = item.Parent; } foreach (GridItem category in item.GridItems) { if (category.Label == CustomProperty.GetFeatureCategoryLabel(BIDSFeatureCategories.General)) { if (category.GridItems.Count > 0) { category.GridItems[0].Select(); } else { category.Select(); } } } }