private void SetupToolbox() { if (ProjectMFVersion == toolboxMFversion && ProjectGVersion == toolboxGversion) { return; } var service = GetService(typeof(IToolboxService)) as IToolboxService; var toolbox = GetService(typeof(SVsToolbox)) as IVsToolbox3; if (service == null || toolbox == null) { return; } using (var txStore = new Store(typeof(GadgeteerDSLDomainModel))) using (var tx = txStore.TransactionManager.BeginTransaction()) { foreach (GadgeteerToolboxItem item in service.GetToolboxItems().OfType <GadgeteerToolboxItem>()) { service.RemoveToolboxItem(item); } int position = 2; foreach (MainboardDefinition md in GadgeteerDefinitionsManager.Instance.Mainboards) { AddToolboxItem(GadgeteerToolboxItem.CreateFor(md, txStore, ProjectMFVersion, ProjectGVersion, position++), service, toolbox); } foreach (ModuleDefinition md in GadgeteerDefinitionsManager.Instance.Modules.OrderBy(m => m.Name)) { AddToolboxItem(GadgeteerToolboxItem.CreateFor(md, txStore, ProjectMFVersion, ProjectGVersion, position++), service, toolbox); } tx.Commit(); } this.toolboxMFversion = this.ProjectMFVersion; this.toolboxGversion = this.ProjectGVersion; }
private void AddToolboxItem(GadgeteerToolboxItem item, IToolboxService service, IVsToolbox3 toolbox) { service.AddToolboxItem(item, item.TabName); string testTabId = null; if (toolbox.GetIDOfTab(item.TabName, out testTabId) != 0 || testTabId != item.TabNameId + item.TabName) { toolbox.SetIDOfTab(item.TabName, item.TabNameId + item.TabName); // add a dummy item so that the group is not visible outside of Gadgeteer designer (empty groups are by design) IVsToolbox2 toolbox2 = toolbox as IVsToolbox2; if (toolbox2 != null) { Guid pkgGuid = new Guid(Constants.GadgeteerDSLPackageId); TBXITEMINFO[] info = new[] { new TBXITEMINFO { bstrText = "(hidden placeholder)" } }; toolbox2.AddItem2(new Microsoft.VisualStudio.Shell.OleDataObject(), info, item.TabName, ref pkgGuid); } } }