public ComponentIndexFile AddFile(string file)
        {
            ComponentIndexFile cf  = new ComponentIndexFile(file);
            LoaderContext      ctx = new LoaderContext();

            try {
                cf.Update(ctx);
            } finally {
                ctx.Dispose();
            }
            if (cf.Components.Count == 0)
            {
                return(null);
            }
            else
            {
                files.Add(cf);
                return(cf);
            }
        }
		void AddItem (ComponentIndexFile ifile, ItemToolboxNode co)
		{
			Gdk.Pixbuf img = co.Icon != null ? co.Icon.ScaleSimple (16, 16, Gdk.InterpType.Bilinear) : null;
			if (showCategories) {
				TreeIter it;
				bool found = false;
				if (store.GetIterFirst (out it)) {
					do {
						if (co.Category == (string) store.GetValue (it, ColName)) {
							found = true;
							break;
						}
					}
					while (store.IterNext (ref it));
				}
				if (!found)
					it = store.AppendValues (false, co.Category, string.Empty, string.Empty, string.Empty, null, null, false, (int)Pango.Weight.Bold);
				store.AppendValues (it, currentItems.ContainsKey (co), co.Name, string.Empty, ifile.Name, ifile.Location, img, co, true, (int)Pango.Weight.Normal);
			}
			else
				store.AppendValues (currentItems.ContainsKey (co), co.Name, string.Empty, ifile.Name, ifile.Location, img, co, true, (int)Pango.Weight.Normal);
		}
		public ComponentIndexFile AddFile (string file)
		{
			ComponentIndexFile cf = new ComponentIndexFile (file);
			LoaderContext ctx = new LoaderContext ();
			try {
				cf.Update (ctx);
			} finally {
				ctx.Dispose ();
			}
			if (cf.Components.Count == 0)
				return null;
			else {
				files.Add (cf);
				return cf;
			}
		}
		internal ComponentIndex GetComponentIndex (ProgressMonitor 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.CancellationToken.IsCancellationRequested)
					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.CancellationToken.IsCancellationRequested)
						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.CancellationToken.IsCancellationRequested)
							return index;
					}
				} finally {
					ctx.Dispose ();
					monitor.EndTask ();
				}
			}
			
			if (toupdate.Count > 0 || todelete.Count > 0)
				index.Save ();
			
			return index;
		}
        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);
        }