/// <summary> /// Sends notification that an item in the Toolbox is selected through a click, or by pressing ENTER. /// </summary> /// <param name="pDO">Data object that is selected.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns> int IVsToolboxUser.ItemPicked(IOleDataObject pDO) { // Create a OleDataObject from the input interface. OleDataObject oleData = new OleDataObject(pDO); // Check if the picked item is the one we added to the toolbox. if (oleData.GetDataPresent(typeof(ToolboxItemData))) { Debug.WriteLine("MyToolboxItemData selected from the toolbox"); ToolboxItemData myData = (ToolboxItemData)oleData.GetData(typeof(ToolboxItemData)); editorControl.Text += myData.Content; } return VSConstants.S_OK; }
/// <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); }