protected override void OnSited() { base.OnSited(); IAssetReferenceService referenceService = (IAssetReferenceService) this.GetService(typeof(IAssetReferenceService), true); foreach (IAssetReference reference in referenceService.GetAll()) { if (reference is RecipeReference && reference is IBoundAssetReference) { RecipeTaskItem recipeTaskItem = new RecipeTaskItem((RecipeReference)reference); this.Add(recipeTaskItem, reference.Key); } } ((IVsEnumTaskItems)this).Reset(); }
private void LoadReferences() { this.SuspendLayout(); this.imgImages.Images.Clear(); this.lstRecipes.Items.Clear(); GuidancePackage[] Packages = base.RecipeManagerService.GetEnabledPackages(); ArrayList images = new ArrayList(); // Add the two default images. ToolboxBitmapAttribute boundattr = new ToolboxBitmapAttribute(typeof(IBoundAssetReference)); Image boundimg = boundattr.GetImage(boundattr); this.imgImages.Images.Add(boundimg); // Add gray version this.imgImages.Images.Add(ConvertToGrayscale(boundimg)); ToolboxBitmapAttribute unboundattr = new ToolboxBitmapAttribute(typeof(IUnboundAssetReference)); Image unboundimg = unboundattr.GetImage(unboundattr); this.imgImages.Images.Add(unboundimg); // Add gray version this.imgImages.Images.Add(ConvertToGrayscale(unboundimg)); Hashtable groups = new Hashtable(); ArrayList items = new ArrayList(); // WORKAROUND: fixed for VSWhidbey "by design" bug #440390. Now we load items and groups // first, then sort everything manually, and finally add stuff to the control. // Commented lines should be documented when feature is fixed. foreach (GuidancePackage Package in Packages) { IAssetReferenceService refservice = (IAssetReferenceService) Package.GetService(typeof(IAssetReferenceService), true); IConfigurationService configService = (IConfigurationService)Package.GetService(typeof(IConfigurationService), true); foreach (IAssetReference reference in refservice.GetAll()) { ReferenceInfo info = new ReferenceInfo(reference); #region Determine image int imageindex = images.IndexOf(reference.GetType()); // Determine image to show. if (imageindex == -1) { ToolboxBitmapAttribute bmp = (ToolboxBitmapAttribute)Attribute.GetCustomAttribute( reference.GetType(), typeof(ToolboxBitmapAttribute), true); if (bmp == null) { // Use default attributes. if (reference is IBoundAssetReference) { imageindex = 0; } else { imageindex = 2; } if (!info.IsEnabled) { imageindex++; } } else { imageindex = this.imgImages.Images.Count; Image newimg = bmp.GetImage(reference); if (info.IsEnabled) { this.imgImages.Images.Add(newimg); } else { // Add gray version. this.imgImages.Images.Add(ConvertToGrayscale(newimg)); } images.Add(reference.GetType()); } } else { // Account for the 4 built-in images. imageindex = imageindex + 4; } #endregion Determine image #region Determine group // Bug: Should we fix this? // We should get custom attributes instead of a single attr. // The reference could override the category //CategoryAttribute category = (CategoryAttribute)Attribute.GetCustomAttribute( // reference.GetType(), typeof(CategoryAttribute), true); CategoryAttribute category = (CategoryAttribute)Attribute.GetCustomAttributes( reference.GetType(), typeof(CategoryAttribute), true).First(); // ListViewGroup categorygroup = this.lstRecipes.Groups[category.Category]; ListViewGroup categorygroup = (ListViewGroup)groups[category.Category]; if (categorygroup == null) { //categorygroup = this.lstRecipes.Groups.Add(category.Category, category.Category); categorygroup = new ListViewGroup(category.Category, category.Category); groups.Add(category.Category, categorygroup); } #endregion Determine group Config.Recipe recipe = null; if (reference is RecipeReference) { recipe = configService.CurrentPackage[reference.AssetName]; } string[] subitems = new string[3]; string errors = string.Empty; Exception ex = null; try { subitems[0] = reference.Caption; } catch (Exception e) { if (recipe != null) { subitems[0] = recipe.Caption; } ex = e; errors = "Caption"; } try { subitems[1] = reference.AppliesTo; } catch (Exception e) { subitems[1] = Configuration.Resources.Reference_AppliesToThrew; if (ex == null) { ex = e; } if (!string.IsNullOrEmpty(errors)) { errors += ", "; } errors += "AppliesTo"; } subitems[2] = Package.Configuration.Caption; ListViewItem item = new ListViewItem(subitems, imageindex); item.Tag = info; item.Group = categorygroup; items.Add(item); if (ex != null) { ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), new RecipeExecutionException(reference.AssetName, string.Format(CultureInfo.CurrentCulture, Configuration.Resources.Reference_InvalidAttributes, errors), ex)); } } } // Sort everything. ListViewGroup[] lvgroups = new ListViewGroup[groups.Count]; groups.Values.CopyTo(lvgroups, 0); items.Sort(new ListViewItemSortComparer()); Array.Sort(lvgroups, new GroupSortComparer()); this.lstRecipes.Groups.AddRange(lvgroups); this.lstRecipes.Items.AddRange((ListViewItem[])items.ToArray(typeof(ListViewItem))); this.lstRecipes.Invalidate(); this.ResumeLayout(); if (this.lstRecipes.Items.Count > 0) { splitter.Panel1.Focus(); splitter.Panel1.Select(); ((ListViewItem)items[0]).Selected = true; this.lstRecipes.Focus(); this.lstRecipes.Select(); } else { this.txtDescription.Text = String.Empty; } }