Example #1
0
        void InitializeToolbox()
        {
#if false
            ThreadHelper.ThrowIfNotOnUIThread();

            // If toolboxData have initialized, skip creating a new one.
            if (toolboxData == null)
            {
                // Get the toolbox service
                IVsToolbox toolbox = (IVsToolbox)GetService(typeof(SVsToolbox));

                toolboxData = new OleDataObject[3];

                // Create the data objects that will store the data for the toolbox items.
                toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.Event] = new OleDataObject();
                toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.Event].SetData(typeof(Toolbox.ToolboxItemData), new Toolbox.ToolboxItemData(Toolbox.ToolboxItemData.ToolboxItems.Event));
                toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.State] = new OleDataObject();
                toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.State].SetData(typeof(Toolbox.ToolboxItemData), new Toolbox.ToolboxItemData(Toolbox.ToolboxItemData.ToolboxItems.State));
                toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.Transition] = new OleDataObject();
                toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.Transition].SetData(typeof(Toolbox.ToolboxItemData), new Toolbox.ToolboxItemData(Toolbox.ToolboxItemData.ToolboxItems.Transition));

                TBXITEMINFO[] itemInfo = new TBXITEMINFO[1];

                for (Toolbox.ToolboxItemData.ToolboxItems item = Toolbox.ToolboxItemData.ToolboxItems.Event; item <= Toolbox.ToolboxItemData.ToolboxItems.Transition; item++)
                {
                    itemInfo[0].bstrText = item.ToString();
                    itemInfo[0].hBmp     = IntPtr.Zero;
                    itemInfo[0].dwFlags  = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST;
                    ErrorHandler.ThrowOnFailure(toolbox.AddItem(toolboxData[(int)item], itemInfo, "State Machine"));
                }
            }
#endif
        }
        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));
        }
Example #3
0
        /// <summary>
        /// This method adds a Toolbox item by VS Toolbox service.
        /// This way provides more flexibilities than DTE way.
        /// </summary>
        private void AddItemByVsToolboxService()
        {
            // Get shell service provider.
            ServiceProvider sp =
                new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_applicationObject);

            // Get the IVsToolbox interface.
            IVsToolbox tbs = sp.GetService(typeof(SVsToolbox)) as IVsToolbox;

            // Toolbox Item Info data 
            TBXITEMINFO[] itemInfo = new TBXITEMINFO[1];
            Bitmap bitmap =
                new Bitmap(this.GetType().Assembly.GetManifestResourceStream("CSVSAddInToolboxItem.Demo.bmp"));
            itemInfo[0].bstrText = "Service Added HTML Content";
            itemInfo[0].hBmp = bitmap.GetHbitmap();
            itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST;

            // OleDataObject to host toolbox data
            OleDataObject tbItem = new OleDataObject();
            tbItem.SetText(
                ConvertToClipboardFormat("<input id=\"Button1\" type=\"button\" value=\"button\" />", null, null),
                TextDataFormat.Html);

            // Add a new toolbox item to MyCustomTab tab
            tbs.AddItem(tbItem, itemInfo, "CustomTab");
        }
Example #4
0
        private TBXITEMINFO[] GetItemInfo([NotNull] string name)
        {
            Debug.ArgumentNotNull(name, nameof(name));

            var result = new TBXITEMINFO[1];

            result[0].bstrText = name;
            result[0].dwFlags  = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST;

            return(result);
        }
Example #5
0
        private static void AddToToolbox(string label, string actualText)
        {
            var tbs = Instance.ServiceProvider.GetServiceAsync(typeof(IVsToolbox)).Result as IVsToolbox;

            var itemInfo = new TBXITEMINFO[1];
            var tbItem   = new OleDataObject();

            var bitmap = new System.Drawing.Bitmap("./Resources/MarkupTag_16x.png");

            itemInfo[0].hBmp     = bitmap.GetHbitmap();
            itemInfo[0].bstrText = label;
            itemInfo[0].dwFlags  = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST;

            tbItem.SetText(actualText, TextDataFormat.Text);

            tbs?.AddItem(tbItem, itemInfo, "Rapid XAML");
        }
Example #6
0
        /// <summary>
        /// 添加工具箱栏目.
        /// </summary>
        void AddToolboxItem()
        {
            LogEntry(__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
                     string.Format("Entering AddToolboxItem for: {0}", toolboxItemString));
            var toolboxData = new Microsoft.VisualStudio.Shell.OleDataObject();

            tooltipStream = FormatTooltipData(toolboxTooltipString, toolboxDescriptionString);
            // 设置提示信息.
            toolboxData.SetData("VSToolboxTipInfo", tooltipStream);
            // 设置拖放文本.
            toolboxData.SetData(DataFormats.Text, toolboxItemTextString);
            TBXITEMINFO[] itemInfo = new TBXITEMINFO[1];
            itemInfo[0].bstrText = toolboxItemString;
            itemInfo[0].hBmp     = IntPtr.Zero;
            itemInfo[0].dwFlags  = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST;
            ErrorHandler.ThrowOnFailure(
                vsToolbox2.AddItem(toolboxData, itemInfo, toolboxTabString));
        }
        private static async Task AddToToolboxAsync(string label, string actualText)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var tbs = await Instance.ServiceProvider.GetServiceAsync(typeof(IVsToolbox)) as IVsToolbox;

            var itemInfo = new TBXITEMINFO[1];
            var tbItem   = new OleDataObject();

            var bitmap = new System.Drawing.Bitmap("./Resources/MarkupTag_16x.png");

            itemInfo[0].hBmp     = bitmap.GetHbitmap();
            itemInfo[0].bstrText = label;
            itemInfo[0].dwFlags  = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST;

            tbItem.SetText(actualText, TextDataFormat.Text);

            tbs?.AddItem(tbItem, itemInfo, StringRes.UI_ToolboxGroupHeader);
        }
        private static async Task AddToToolboxAsync(string label, string actualText)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var tbs = await Instance.AsyncPackage.GetServiceAsync <IVsToolbox, IVsToolbox>();

            var itemInfo = new TBXITEMINFO[1];
            var tbItem   = new OleDataObject();

            var executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var bitmap        = new System.Drawing.Bitmap(Path.Combine(executionPath, "Resources", "MarkupTag_16x.png"));

            itemInfo[0].hBmp     = bitmap.GetHbitmap();
            itemInfo[0].bstrText = label;
            itemInfo[0].dwFlags  = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST;

            tbItem.SetText(actualText, TextDataFormat.Text);

            tbs?.AddItem(tbItem, itemInfo, StringRes.UI_ToolboxGroupHeader);
        }
        /// <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"));
            }
        }
Example #10
0
        /// <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>
 /// 添加工具箱栏目. 
 /// </summary>
 void AddToolboxItem()
 {
     LogEntry(__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
     string.Format("Entering AddToolboxItem for: {0}", toolboxItemString));
     var toolboxData = new Microsoft.VisualStudio.Shell.OleDataObject();
     tooltipStream = FormatTooltipData(toolboxTooltipString, toolboxDescriptionString);
     // 设置提示信息.
     toolboxData.SetData("VSToolboxTipInfo", tooltipStream);
     // 设置拖放文本.
     toolboxData.SetData(DataFormats.Text, toolboxItemTextString);
     TBXITEMINFO[] itemInfo = new TBXITEMINFO[1];
     itemInfo[0].bstrText = toolboxItemString;
     itemInfo[0].hBmp = IntPtr.Zero;
     itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST;
     ErrorHandler.ThrowOnFailure(
         vsToolbox2.AddItem(toolboxData, itemInfo, toolboxTabString));
 }
Example #12
0
        /// <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"));
            }
        }
Example #13
0
        /// <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);
        }
        /// <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);
        }