internal ComponentIndex GetComponentIndex(IProgressMonitor monitor)
        {
            // Returns an index of all components that can be added to the toolbox.

            ComponentIndex index = ComponentIndex.Load();

            // Get the list of assemblies that need to be updated

            HashSet <string>          files    = new HashSet <string> ();
            List <ComponentIndexFile> toupdate = new List <ComponentIndexFile> ();
            List <ComponentIndexFile> todelete = new List <ComponentIndexFile> ();

            foreach (ComponentIndexFile ia in index.Files)
            {
                files.Add(ia.FileName);
                if (!File.Exists(ia.FileName))
                {
                    todelete.Add(ia);
                }
                if (ia.NeedsUpdate)
                {
                    toupdate.Add(ia);
                }
                if (monitor.IsCancelRequested)
                {
                    return(index);
                }
            }

            // Look for new assemblies

            foreach (TargetRuntime runtime in Runtime.SystemAssemblyService.GetTargetRuntimes())
            {
                foreach (SystemAssembly asm in runtime.AssemblyContext.GetAssemblies())
                {
                    if (files.Add(asm.Location))
                    {
                        ComponentIndexFile c = new ComponentIndexFile(asm.Location);
                        index.Files.Add(c);
                        toupdate.Add(c);
                    }
                    if (monitor.IsCancelRequested)
                    {
                        return(index);
                    }
                }
            }

            foreach (ComponentIndexFile ia in todelete)
            {
                index.Files.Remove(ia);
            }

            if (toupdate.Count > 0)
            {
                monitor.BeginTask(GettextCatalog.GetString("Looking for components..."), toupdate.Count);
                LoaderContext ctx = new LoaderContext();
                try {
                    foreach (ComponentIndexFile ia in toupdate)
                    {
                        ia.Update(ctx);
                        monitor.Step(1);
                        if (monitor.IsCancelRequested)
                        {
                            return(index);
                        }
                    }
                } finally {
                    ctx.Dispose();
                    monitor.EndTask();
                }
            }

            if (toupdate.Count > 0 || todelete.Count > 0)
            {
                index.Save();
            }

            return(index);
        }
		public ComponentSelectorDialog (IToolboxConsumer currentConsumer)
		{
			using (IProgressMonitor monitor = new MessageDialogProgressMonitor (true, true, false, true)) {
				index = DesignerSupport.Service.ToolboxService.GetComponentIndex (monitor);
			}
			
			this.Build();
			
			store = new TreeStore (typeof(bool), typeof(string), typeof(string), typeof(string), typeof(string), typeof(Gdk.Pixbuf), typeof(ItemToolboxNode), typeof(bool), typeof(int));
			
			TreeViewColumn col;
			col = new TreeViewColumn ();
			Gtk.CellRendererToggle crt = new CellRendererToggle ();
			col.PackStart (crt, false);
			col.AddAttribute (crt, "active", ColChecked);
			col.AddAttribute (crt, "visible", ColShowCheck);
			crt.Toggled += OnToggleItem;
			col.SortColumnId = ColChecked;
			listView.AppendColumn (col);
			
			col = new TreeViewColumn ();
			col.Spacing = 3;
			col.Title = GettextCatalog.GetString ("Name");
			var crp = new CellRendererPixbuf ();
			CellRendererText crx = new CellRendererText ();
			crx.Width = 150;
			col.PackStart (crp, false);
			col.PackStart (crx, false);
			col.AddAttribute (crp, "pixbuf", ColIcon);
			col.AddAttribute (crp, "visible", ColShowCheck);
			col.AddAttribute (crx, "text", ColName);
			col.AddAttribute (crx, "weight", ColBold);
			listView.AppendColumn (col);
			col.Resizable = true;
			col.SortColumnId = ColName;
			
			col = listView.AppendColumn (GettextCatalog.GetString ("Library"), new CellRendererText (), "text", ColLibrary);
			col.Resizable = true;
			col.SortColumnId = ColLibrary;
			
			col = listView.AppendColumn (GettextCatalog.GetString ("Location"), new CellRendererText (), "text", ColPath);
			col.Resizable = true;
			col.SortColumnId = ColPath;
			
			store.SetSortColumnId (ColName, SortType.Ascending);
			listView.SearchColumn = ColName;
			listView.Model = store;
			
			foreach (ItemToolboxNode it in DesignerSupport.Service.ToolboxService.UserItems)
				currentItems [it] = it;
			
			List<string> list = new List<string> ();
			foreach (ComponentIndexFile ifile in index.Files) {
				foreach (ItemToolboxNode co in ifile.Components) {
					if (!list.Contains (co.ItemDomain))
						list.Add (co.ItemDomain);
				}
			}
			
			string defaultDomain = null;
			if (currentConsumer != null)
				defaultDomain = currentConsumer.DefaultItemDomain;
			
			comboType.AppendText (GettextCatalog.GetString ("All"));
			comboType.Active = 0;

			for (int n=0; n<list.Count; n++) {
				string s = list [n];
				comboType.AppendText (s);
				if (s == defaultDomain)
					comboType.Active = n+1;
			}
		}
		public async Task<bool> Initialize (IToolboxConsumer currentConsumer)
		{
			using (ProgressMonitor monitor = new MessageDialogProgressMonitor (true, true, false, true)) {
				index = await DesignerSupport.Service.ToolboxService.GetComponentIndex (monitor);
				if (monitor.CancellationToken.IsCancellationRequested)
					return false;
			}

			List<string> list = new List<string> ();
			foreach (ComponentIndexFile ifile in index.Files) {
				foreach (ItemToolboxNode co in ifile.Components) {
					if (!list.Contains (co.ItemDomain))
						list.Add (co.ItemDomain);
				}
			}

			string defaultDomain = null;
			if (currentConsumer != null)
				defaultDomain = currentConsumer.DefaultItemDomain;

			for (int n = 0; n < list.Count; n++) {
				string s = list [n];
				comboType.AppendText (s);
				if (s == defaultDomain)
					comboType.Active = n + 1;
			}
			return true;
		}