Exemplo n.º 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));
        }
Exemplo n.º 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");
        }
Exemplo n.º 4
0
        void SQLitePackage_ToolboxUpgraded(object sender, EventArgs e)
        {
            IVsToolbox vstbx = GetService(typeof(SVsToolbox)) as IVsToolbox;

            vstbx.RemoveTab("SQLite");

            SQLitePackage_ToolboxInitialized(sender, e);
        }
Exemplo n.º 5
0
        private void OnToolboxUpgraded(object sender, EventArgs e)
        {
            IVsToolbox toolbox = this.GetService(typeof(SVsToolbox)) as IVsToolbox;

            if (toolbox == null)
            {
                throw new InvalidOperationException();
            }

            toolbox.RemoveTab(toolboxTabName);
            OnToolboxInitialized(sender, e);
        }
        //</Snippet10>

        //<Snippet11>
        void OnRefreshToolbox(object sender, EventArgs e)
        {
            // Add new instances of all ToolboxItems contained in ToolboxItemList.
            IToolboxService service =
                GetService(typeof(IToolboxService)) as IToolboxService;
            IVsToolbox toolbox = GetService(typeof(IVsToolbox)) as IVsToolbox;

            //Remove target tab and all controls under it.
            foreach (ToolboxItem oldItem in service.GetToolboxItems(CategoryTab))
            {
                service.RemoveToolboxItem(oldItem);
            }
            toolbox.RemoveTab(CategoryTab);

            foreach (ToolboxItem itemFromList in ToolboxItemList)
            {
                service.AddToolboxItem(itemFromList, CategoryTab);
            }
            service.SelectedCategory = CategoryTab;

            service.Refresh();
        }
        /// <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"));
            }
        }
        //<Snippet10>
        // Add new instances of all ToolboxItems to the toolbox item list.
        void OnRefreshToolbox(object sender, EventArgs e)
        {
            IToolboxService service =
                GetService(typeof(IToolboxService)) as IToolboxService;
            IVsToolbox toolbox =
                GetService(typeof(IVsToolbox)) as IVsToolbox;

            // Remove target tab and all items under it.
            foreach (ToolboxItem item in service.GetToolboxItems(CategoryTab))
            {
                service.RemoveToolboxItem(item);
            }
            toolbox.RemoveTab(CategoryTab);

            // Recreate the target tab with the items from the current list.
            foreach (ToolboxItem item in ToolboxItemList)
            {
                service.AddToolboxItem(item, CategoryTab);
            }
            service.SelectedCategory = CategoryTab;

            service.Refresh();
        }
Exemplo n.º 9
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"));
            }
        }