/// <summary> /// Creates a new instance. /// </summary> public NewWizardTreeContentProvider() { IConfigurationElement[] configurationElements = ExtensionService.Instance .GetConfigurationElements(ExtensionPointId); IConfigurationElement[] categories = configurationElements.Where(x => x.Prefix == "category").ToArray(); IConfigurationElement[] wizards = configurationElements.Where(x => x.Prefix == "wizard").ToArray(); IDictionary <string, CategoryContribution> idToCategoryMap = new Dictionary <string, CategoryContribution>(categories.Length); // Processing categories for (int i = -1; ++i < categories.Length;) { IConfigurationElement category = categories[i]; string id = category["id"]; string label = category["label"]; CategoryContribution contribution = new CategoryContribution { Id = id, Label = label }; idToCategoryMap.Add(id, contribution); iContributions.Add(contribution); } // Processing wizards for (int i = -1; ++i < wizards.Length;) { IConfigurationElement wizard = wizards[i]; string id = wizard["id"]; string category = wizard["category"]; string label = wizard["label"]; string className = wizard["class"]; if (string.IsNullOrEmpty(className)) { continue; } IBundle providingBundle = ExtensionService.Instance.GetProvidingBundle(wizard); Type wizardType = TypeLoader.TypeForName(providingBundle, className); IWizard wizardImpl = Activator.CreateInstance(wizardType) as IWizard; WizardContribution contribution = new WizardContribution { Id = id, Label = label, Category = category, Wizard = wizardImpl }; // Is it a categorized item? if (!string.IsNullOrEmpty(category)) { CategoryContribution categoryContr; if (idToCategoryMap.TryGetValue(category, out categoryContr)) { categoryContr.Wizards.Add(contribution); continue; } } iContributions.Add(contribution); } }
private void OnSelectionChanged(object sender, SelectionEventArgs selectionEventArgs) { WizardContribution wizard = selectionEventArgs.Selection as WizardContribution; bool canLeave = wizard != null; CanLeave = canLeave; SelectedWizard = null; if (wizard != null) { SelectedWizard = wizard.Wizard; } }