private void CreateToolboxData(string pToolboxItemName, string pData, string pTabInToolbox, bool pRemoveTabItems = false) { // Create the data object that will store the data for the menu item. OleDataObject toolboxData = new OleDataObject(); toolboxData.SetData(typeof(ToolboxData), new ToolboxData(pData)); // Get the toolbox service IVsToolbox toolbox = (IVsToolbox)GetService(typeof(SVsToolbox)); //IVsToolbox2 vsToolbox2 = (IVsToolbox2)toolbox; //IVsToolbox3 vsToolbox3 = (IVsToolbox3)vsToolbox2; if (pRemoveTabItems) { bool succeed = ErrorHandler.Succeeded(toolbox.RemoveTab(pTabInToolbox)); } // Create the array of TBXITEMINFO structures to describe the items // we are adding to the toolbox. TBXITEMINFO[] itemInfo = new TBXITEMINFO[1]; itemInfo[0].bstrText = pToolboxItemName; itemInfo[0].clrTransparent = ColorToUInt(Color.Black); itemInfo[0].hBmp = Resources.cartForToolboxItem.GetHbitmap(); itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; //itemInfo[0].iImageIndex = 0; //itemInfo[0].iImageWidth = 16; ErrorHandler.ThrowOnFailure(toolbox.AddItem(toolboxData, itemInfo, pTabInToolbox)); }
/// <summary> /// This method is called when the pane is sited with a non null service provider. /// Here is where you can do all the initialization that requare access to /// services provided by the shell. /// </summary> protected override void Initialize() { // If toolboxData have initialized, skip creating a new one. if (toolboxData == null) { // Create the data object that will store the data for the menu item. toolboxData = new OleDataObject(); toolboxData.SetData(typeof(ToolboxItemData), new ToolboxItemData("Test string")); // Get the toolbox service IVsToolbox toolbox = (IVsToolbox)GetService(typeof(SVsToolbox)); // Create the array of TBXITEMINFO structures to describe the items // we are adding to the toolbox. TBXITEMINFO[] itemInfo = new TBXITEMINFO[1]; itemInfo[0].bstrText = "Toolbox Sample Item"; itemInfo[0].hBmp = IntPtr.Zero; itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; ErrorHandler.ThrowOnFailure(toolbox.AddItem((IOleDataObject)toolboxData, itemInfo, "Toolbox Test")); } }
/// <summary> /// This method is called when the pane is sited with a non null service provider. /// Here is where you can do all the initialization that requare access to /// services provided by the shell. /// </summary> protected override void Initialize() { ThreadHelper.ThrowIfNotOnUIThread(); // If toolboxData have initialized, skip creating a new one. if (toolboxData == null) { // Get the toolbox service IVsToolbox toolbox = (IVsToolbox)GetService(typeof(SVsToolbox)); System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap(@"Resources\Bitmap1.bmp"); System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap(@"Resources\Bitmap2.bmp"); // Create the array of TBXITEMINFO structures to describe the items // we are adding to the toolbox. TBXITEMINFO[] itemInfo1 = new TBXITEMINFO[1]; itemInfo1[0].bstrText = "Toolbox Sample Item"; itemInfo1[0].hBmp = bitmap1.GetHbitmap(); itemInfo1[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; TBXITEMINFO[] itemInfo2 = new TBXITEMINFO[1]; itemInfo2[0].bstrText = "Toolbox Sample Item 2"; itemInfo2[0].hBmp = bitmap2.GetHbitmap(); itemInfo2[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; toolboxData = new OleDataObject(); toolboxData.SetData(typeof(Toolbox_TestItem1), new Toolbox_TestItem1("Test string")); ErrorHandler.ThrowOnFailure(toolbox.AddItem(toolboxData, itemInfo1, "GraphML Toolbox")); toolboxData = new OleDataObject(); toolboxData.SetData(typeof(Toolbox_TestItem2), new Toolbox_TestItem2("Test string 2")); ErrorHandler.ThrowOnFailure(toolbox.AddItem(toolboxData, itemInfo2, "GraphML Toolbox")); } }
/// <summary> /// The process record. /// </summary> /// <exception cref="PSInvalidOperationException"> /// An error occured /// </exception> protected override void ProcessRecord() { var project = this.Project as VSProject; if (project == null) { throw new PSInvalidOperationException("Cannot cast the Project object to a VSProject"); } var sp = new ServiceProvider((IOleServiceProvider)project.DTE); // Get the toolbox var svsToolbox = sp.GetService(typeof(SVsToolbox)); if (svsToolbox == null) { throw new PSInvalidOperationException("Cannot get global Toolbox Service (SVsToolbox)"); } var toolbox = svsToolbox as IVsToolbox; if (toolbox == null) { throw new PSInvalidOperationException("Cannot cast Toolbox Service to IVsToolbox"); } // Add the tab toolbox.AddTab(this.Category); // Find the assembly in the project references var reference = project.References.Find(this.ActivityAssembly); if (reference == null) { throw new PSInvalidOperationException( "Cannot find a project reference to assembly " + this.ActivityAssembly); } // Load the assembly // Don't load the assembly - this causes problems when uninstalling - see http://wf.codeplex.com/workitem/8762 // var assembly = Assembly.LoadFrom(reference.Path); // Get the activity type // var activityType = assembly.GetType(this.Activity); var assemblyQualifiedName = GetAssemblyQualifiedName(reference.Path, this.Activity); if (string.IsNullOrEmpty(this.DisplayName)) { this.DisplayName = GetNameFromActivity(this.Activity); } IEnumToolboxItems enumToolboxItems; toolbox.EnumItems(this.Category, out enumToolboxItems); var dataObjects = new IDataObject[1]; uint fetched; while (enumToolboxItems.Next(1, dataObjects, out fetched) == VSConstants.S_OK) { if (dataObjects[0] != null && fetched == 1) { // Create an OleDataObject to work with var itemDataObject = new OleDataObject(dataObjects[0]); // Access the data var name = itemDataObject.GetData("CF_WORKFLOW_4"); if (name != null) { // If this toolbox item already exists, remove it if (name.ToString() == this.DisplayName) { // Note: This prevents an old toolbox item from adding a ref to the wrong runtime assembly toolbox.RemoveItem(dataObjects[0]); } } } } var dataObject = new OleDataObject(); dataObject.SetData("AssemblyName", this.ActivityAssembly); dataObject.SetData("CF_WORKFLOW_4", this.DisplayName); dataObject.SetData("WorkflowItemTypeNameFormat", assemblyQualifiedName); // Load the bitmap var bitmap = (Bitmap)Resources.ResourceManager.GetObject(this.BitmapID); if (bitmap == null) { throw new PSInvalidOperationException("Cannot load bitmap ID " + this.BitmapID); } var toolboxItemInfo = new TBXITEMINFO[1]; toolboxItemInfo[0].bstrText = this.DisplayName; toolboxItemInfo[0].hBmp = bitmap.GetHbitmap(); toolboxItemInfo[0].clrTransparent = (uint)ColorTranslator.ToWin32(Color.White); toolbox.AddItem(dataObject, toolboxItemInfo, this.Category); }